Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init operations for workspaces with Git Init as initial implemetation #69 #182

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jfaltermeier
Copy link
Contributor

@jfaltermeier jfaltermeier commented May 22, 2023

CRD, RBAC changes: https://github.com/eclipsesource/theia-cloud-helm/pull/26/files

  • add a new docker image (theiacloud/theia-cloud-git-init) that can be used to clone a git repository and checkout a specific pointer
    • support HTTPS and SSH auth
    • can be tested outside of Theia Cloud with the instructions in python/git-init/README.md (you may have to create/find approriate Git repositories to test though. Note: https://gitlab.eclipse.org allows to create private forks of existing projects in your user namespace!)
  • arguments to create a init container using the new image are passed via the new initOperations array of a session. The container is created in GitInitOperationHandler
    • for private repositories the handler currently expects that the secret is available as a kubernetes secret already
    • besides that the secret has to be annotated to be used by the operator. Otherwise it will not be exposed. See the sample secrets in python/git-init/README.md
    • since the secrets are only available in the init container, they cannot be read from the main IDE
  • Via the InitOperationHandler new init operation handlers may be added to the Operator
  • extends the REST Service API and Typescript Common API to allow creating sessions with init operations

Open issues / Known limitations are:

  • the actual IDE has no git config with the user email yet
  • If we did a clone using SSH the private key is not made available to the main IDE yet
  • Does not work with ephemeral sessions, because we have no volume we could mount in the init container
  • We have no API to create the required Kubernetes Secrets. Currently it is expected that an admin user adds the credentials to kubernetes with the required annotations

For the credential handling I am not sure if this should be a first level Theia Cloud Feature. We could offer some library/util that helps with creating the secrets/adding the annotations, but I think this should be used from client code, e.g. from a dashboard implementation.

@jfaltermeier jfaltermeier force-pushed the jf/git-init branch 2 times, most recently from c0fe595 to daaeb3f Compare May 22, 2023 14:11
@jfaltermeier jfaltermeier marked this pull request as ready for review May 22, 2023 14:36
Copy link
Contributor

@lucas-koehler lucas-koehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial code review. I will test this later.
Code structure and code looks mostly good to me already :) . I added some inline comments.

doc/docs/Building-Internal.md Outdated Show resolved Hide resolved
dockerfiles/git-init/Dockerfile Outdated Show resolved Hide resolved
+ ", error=" + error + ", workspace=" + workspace + ", lastActivity=" + lastActivity + "]";
+ ", error=" + error + ", workspace=" + workspace + ", lastActivity=" + lastActivity
+ ", sessionSecret=" + sessionSecret + ", envVars=" + envVars + ", envVarsFromConfigMaps="
+ envVarsFromConfigMaps + ", envVarsFromSecrets=" + envVarsFromSecrets + ", initOperations="
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we omit envVarsFromSecrets here to avoid leaking secrets in logs, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are just the names of the secrets under which they are stored in k8s and not their actual values

}

public static boolean isEphemeral(String workspace) {
return workspace == null || workspace.isBlank();
}

public static class InitOperation {

@JsonProperty("id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 144 to 152
if (isHTTP(repository)) {
if (!injectHTTPRepoCredentials(correlationId, secret, secretName, repository, gitInitContainer)) {
return;
}
} else {
if (!injectSSHRepoCredentials(correlationId, secret, secretName, repository, gitInitContainer, volumes)) {
return;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the returns? There is nothing after this. If this is some kind of error, should something be logged?

Copy link
Contributor Author

@jfaltermeier jfaltermeier Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the logging is done in the inject methods itself.
The returns are executed when there was a problem.
Reason is that if we add more init code at the end at some point (e.g. injecting the SSH Key in the IDE) or if an adopter overrides the handler and calls super, we only run this new code if there were no issues.
I've added more comments, because it looks weird indeed.

String repositoryWithoutProtocol = split[1];
if (repositoryWithoutProtocol.contains("@")) {
if (repositoryWithoutProtocol.split(Pattern.quote("@"))[0].contains(":")) {
/* username and password part of URL */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this if empty on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, injectUsername and injectPassword are false by default and we won't inject either if both username and password are part of the repo url.
I've adopted the comment

Comment on lines +189 to +190
LOGGER.info(LogMessageUtil.formatLogMessage(correlationId,
MessageFormat.format("Inject username: {0}; Inject password: {1}", injectUsername, injectPassword)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log credentials? This might expose secrets in the log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just a boolean whether they will be injected or not

* create init container that can be used to checkout git repositories
with https and ssh
* add ability to checkout branches/commits/tags
* add list of InitOperations to Session
* introduce binding of multiple InitOperationHandler
* implement GitInitOperationHandler
  * add init container with required environment variables for HTTP(S)
Git checkout
  * checks that the secret is allowed to be used by this user and by
this InitOperationHandler
* implement injecting ssh key and password to init container
* adjust git init script to work with any user id
* make auth info optional (for public repos)
* regenerate open api schema
* regenerate typescript API
* Extend public API
* add verification job for new docker image
* do not update all references to @eclipse-theiacloud/common:
0.8.1-alpha.2 yet, since this is not released yet
@jfaltermeier jfaltermeier force-pushed the jf/git-init branch 4 times, most recently from cc41923 to 01db0af Compare November 27, 2023 11:59
* remove osweek branches from workflow files
* fix typos
* explicitly use python3
Copy link

This PR is stale because it has been open 180 days with no activity.

@github-actions github-actions bot added the stale label May 26, 2024
@lucas-koehler
Copy link
Contributor

keep open

@jfaltermeier jfaltermeier removed the stale label Jul 3, 2024
@parzival418
Copy link

Any word on this? This would be amazing for some work we are looking to use Theia Cloud for.

@jfaltermeier
Copy link
Contributor Author

Any word on this? This would be amazing for some work we are looking to use Theia Cloud for.

Thank you for your interest in this feature! Currently, our main priority is transferring the codebase to the Eclipse Foundation. Once this process is complete, we plan to revisit and continue development on earlier work, including this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants