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

Preserve environment variables through sudo session #1027

Merged
merged 1 commit into from
Apr 27, 2024

Conversation

shanman190
Copy link
Contributor

@shanman190 shanman190 commented Apr 25, 2024

When performing ssh clones on a machine where the Docker socket requires administrative access to utilize passing over the environment variables into the sudo session is required.

It should also be noted, that Windows ships with OpenSSH 8.1 by default, so if Windows users are having issues with SSH Agent support they may need to upgrade their OpenSSH distribution to be inline or newer than the target machine's environment.

@@ -288,7 +288,7 @@ func rerunAsRoot(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger) (b
}

// call ourself
args := []string{binary}
args := []string{"--preserve-env", binary}
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 preserves all environment variables from the initial session into the sudo session. Technically, this could be reduced down to --preserve-env=SSH_AUTH_SOCK to limit only the SSH Agent socket being passed into the sudo session.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to note, the preservation of the environment variables is necessary regardless of source OS. This is all about the target OS and how the Docker socket has been configured from an access standpoint. So any user using a target where Docker requires admin rights would have been impacted by this.

Copy link
Member

@pascalbreuninger pascalbreuninger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@pascalbreuninger pascalbreuninger merged commit ad6ac70 into loft-sh:main Apr 27, 2024
24 checks passed
@shanman190 shanman190 deleted the feature/ssh-clone branch April 27, 2024 13:55
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.

None yet

2 participants