Skip to content

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

Merged
merged 14 commits into from
Feb 26, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Feb 19, 2025

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:

@johnstcn johnstcn self-assigned this Feb 19, 2025
@johnstcn johnstcn changed the title Cj/agent pty container feat(agent): write up reconnectingpty server to container exec Feb 19, 2025
@johnstcn johnstcn force-pushed the cj/agent-pty-container branch 2 times, most recently from d096ac4 to 56cb9e9 Compare February 19, 2025 23:20
@johnstcn johnstcn changed the title feat(agent): write up reconnectingpty server to container exec feat(agent): wire up agentssh server to allow exec into container Feb 19, 2025
@johnstcn johnstcn marked this pull request as draft February 20, 2025 09:59
Base automatically changed from cj/agent-docker-envinfo to main February 24, 2025 15:05
@johnstcn johnstcn force-pushed the cj/agent-pty-container branch from 56cb9e9 to db9df4b Compare February 24, 2025 16:54
@johnstcn johnstcn force-pushed the cj/agent-pty-container branch from db9df4b to 36707f9 Compare February 25, 2025 10:47
Comment on lines -701 to -739
// 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)
}

Copy link
Member Author

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

Comment on lines -131 to -143
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()
}

Copy link
Member Author

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

@johnstcn johnstcn marked this pull request as ready for review February 25, 2025 12:29
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mafredri mafredri left a 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...)
Copy link
Member

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).

Copy link
Member Author

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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

@mafredri mafredri left a 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 👍🏻

@johnstcn johnstcn merged commit 172e523 into main Feb 26, 2025
30 checks passed
@johnstcn johnstcn deleted the cj/agent-pty-container branch February 26, 2025 09:03
@github-actions github-actions bot locked and limited conversation to collaborators Feb 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants