-
Notifications
You must be signed in to change notification settings - Fork 875
feat(agent): wire up agentssh server to allow exec into container #16638
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
Conversation
d096ac4
to
56cb9e9
Compare
56cb9e9
to
db9df4b
Compare
db9df4b
to
36707f9
Compare
// EnvInfoer encapsulates external information required by CreateCommand. | ||
type EnvInfoer interface { | ||
// CurrentUser returns the current user. | ||
CurrentUser() (*user.User, error) | ||
// Environ returns the environment variables of the current process. | ||
Environ() []string | ||
// UserHomeDir returns the home directory of the current user. | ||
UserHomeDir() (string, error) | ||
// UserShell returns the shell of the given user. | ||
UserShell(username string) (string, error) | ||
} | ||
|
||
type systemEnvInfoer struct{} | ||
|
||
var defaultEnvInfoer EnvInfoer = &systemEnvInfoer{} | ||
|
||
// DefaultEnvInfoer returns a default implementation of | ||
// EnvInfoer. This reads information using the default Go | ||
// implementations. | ||
func DefaultEnvInfoer() EnvInfoer { | ||
return defaultEnvInfoer | ||
} | ||
|
||
func (systemEnvInfoer) CurrentUser() (*user.User, error) { | ||
return user.Current() | ||
} | ||
|
||
func (systemEnvInfoer) Environ() []string { | ||
return os.Environ() | ||
} | ||
|
||
func (systemEnvInfoer) UserHomeDir() (string, error) { | ||
return userHomeDir() | ||
} | ||
|
||
func (systemEnvInfoer) UserShell(username string) (string, error) { | ||
return usershell.Get(username) | ||
} | ||
|
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.
review: moved to usershell
package
func (*DockerEnvInfoer) Environ() []string { | ||
// Return a clone of the environment so that the caller can't modify it | ||
return os.Environ() | ||
} | ||
|
||
func (*DockerEnvInfoer) UserHomeDir() (string, error) { | ||
// We default the working directory of the command to the user's home | ||
// directory. Since this came from inside the container, we cannot guarantee | ||
// that this exists on the host. Return the "real" home directory of the user | ||
// instead. | ||
return os.UserHomeDir() | ||
} | ||
|
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.
review: we now use the embedded usershell.SystemEnvInfo
instead
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.
LGTM
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.
Looks great 👍🏻, minor nits/suggestions inline.
slog.F("before", append([]string{name}, args...)), | ||
slog.F("after", append([]string{modifiedName}, modifiedArgs...)), | ||
) | ||
cmd := s.Execer.PTYCommandContext(ctx, modifiedName, modifiedArgs...) |
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.
Didn't we also have a docker execer? Did we end up not implementing that change, and are only relying on env infoer now? Or are we modifying commands from multiple angles? If former, all good, if latter, I'm wondering if we could unify the concepts (perhaps infoer can be applied on the execer level or vice-versa).
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.
That's all in the envinfoer now.
|
||
// HomeDir returns the home directory of the current user, giving | ||
// priority to the $HOME environment variable. | ||
func HomeDir() (string, error) { |
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.
Is this still useful as a separate function or should we just require usage of envinfoer?
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'd like to unexport it and require going through envinfoer, but trying to keep the scope of refactorings small here.
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'm going to mark it as deprecated for now, we can remove it later.
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com> Co-authored-by: Danny Kopping <danny@coder.com>
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.
Just one minor suggestion, but otherwise this is great 👍🏻
Relates to #16419
Builds on top of #16623 and wires up the ReconnectingPTY server. This does nothing to wire up the web terminal yet but the added test demonstrates the functionality working.
Other changes:
SystemEnvInfo
interface to theagent/usershell
package to address follow-up from feat(agent/agentcontainers): add ContainerEnvInfoer #16623 (comment)usershellinfo.Get
as deprecated. Consumers should use theEnvInfoer
interface instead.