-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: add env var for ssh private key #396
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also have an integration test to confirm that this works as expected. Perhaps also validating the behavior when both file and base64 is given.
@@ -273,6 +290,17 @@ func SetupRepoAuth(logf func(string, ...any), options *options.Options) transpor | |||
} | |||
} | |||
|
|||
// If no path was provided, fall back to the environment variable | |||
if options.GitSSHPrivateKeyBase64 != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth thinking about what the behavior should be if both key path and key base64 is given. Do we exit immediately (invalid input)? Do we prefer one over the other? How do we inform the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I think we should error if both are provided. Removes any ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with erroring, have made that change 👍
options/options.go
Outdated
Flag: "git-ssh-private-key-base64", | ||
Env: WithEnvPrefix("GIT_SSH_PRIVATE_KEY_BASE64"), | ||
Value: serpent.StringOf(&o.GitSSHPrivateKeyBase64), | ||
Description: "SSH private key to be used for Git authentication.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description: "SSH private key to be used for Git authentication.", | |
Description: "Base64 encoded SSH private key to be used for Git authentication. This option takes precedence over the private key path option.", |
The "This option takes ..." is just there for completeness, may be rewritten depending on how the final implementation turns out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we error on having both provided, do we document this in both of the descriptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we should be explicit that both options are mutually exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have documented this now 👍
There's a test SSH server implementation you can probably re-use here: https://github.com/coder/terraform-provider-envbuilder/blob/main/internal/provider/git_test.go#L85 |
Yep, that should work. I believe only the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we have an integration test, this will be good to go! 👍
I've added an integration test. It works similar to the existing tests in Lines 266 to 268 in 58ac15f
|
(cherry picked from commit 08bdb8d)
I've found that this works, but I couldn't find an example anywhere, so it took a very long time to figure out. Sharing in case this helps someone like me in the future: locals {
# ...
envbuilder_env = {
# ...
"ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64" : base64encode(data.coder_workspace_owner.me.ssh_private_key),
}
# Convert the above map to the format expected by the docker provider.
} |
Thanks, that looks helpful. In particular, I was using this coder template. I'd suggest that this template should be updated to include this config, so that private repos can be used. |
Closes #333
Allow passing a base64 encoded ssh private key to
ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64
and using this for git authentication.