- Notifications
You must be signed in to change notification settings - Fork917
feat(cli): allow SSH command to connect to running container#16726
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
3692436
toe599cef
Compare9780c67
toeec7378
Compareeec7378
to3dc994a
CompareUh oh!
There was an error while loading.Please reload this page.
@@ -495,30 +526,35 @@ func (s *Server) fileTransferBlocked(session ssh.Session) bool { | |||
return false | |||
} | |||
func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []string, magicType MagicSessionType) (retErr error) { | |||
func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []string, magicType MagicSessionType, container, containerUser string) (retErr 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.
review: think it might be time to consider an opts struct?
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 could be done, but no need to do that yet IMO. If this grows more then probably.
I'd actually want us to refactor the whole session handling and manage our own*session
insession.go
or some such. But that's a story for another time.
Uh oh!
There was an error while loading.Please reload this page.
agent/agentssh/agentssh.go Outdated
for _, kv := range env { | ||
if strings.HasPrefix(kv, "CODER_CONTAINER=") { | ||
container = strings.TrimPrefix(kv, "CODER_CONTAINER=") | ||
} | ||
if strings.HasPrefix(kv, "CODER_CONTAINER_USER=") { | ||
containerUser = strings.TrimPrefix(kv, "CODER_CONTAINER_USER=") | ||
} | ||
} | ||
return container, containerUser, slices.DeleteFunc(env, func(kv string) bool { | ||
return strings.HasPrefix(kv, "CODER_CONTAINER=") || strings.HasPrefix(kv, "CODER_CONTAINER_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.
review: inspired by the magic session stuff, this seems to be the only real way to smuggle info betweeen the client and the server.
Uh oh!
There was an error while loading.Please reload this page.
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.
Looking forward to X11 testing!
Uh oh!
There was an error while loading.Please reload this page.
// ContainerEnvironmentVariable is used to specify the target container for an SSH connection. | ||
// This is stripped from any commands being executed. | ||
// Only available if CODER_AGENT_DEVCONTAINERS_ENABLE=true. | ||
ContainerEnvironmentVariable = "CODER_CONTAINER" |
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.
Should we be more specific about the container here? Is it only Devcontainer?
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 not forcing it to be :) It can be any container but the UI andcoder show
should only show devcontainers.
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.
ok, so in theory a smart Coder user can run any container this way?
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, in theory. This is still 'early access' so I'm choosing to not restrict things like this until it makes sense to do so.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
Wish we could keep the container specific stuff out ofagentssh
package, but I don't see a way around it. Glad the invasion is relatively constrained. Nice work!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
@@ -495,30 +526,35 @@ func (s *Server) fileTransferBlocked(session ssh.Session) bool { | |||
return false | |||
} | |||
func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []string, magicType MagicSessionType) (retErr error) { | |||
func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []string, magicType MagicSessionType, container, containerUser string) (retErr 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.
It could be done, but no need to do that yet IMO. If this grows more then probably.
I'd actually want us to refactor the whole session handling and manage our own*session
insession.go
or some such. But that's a story for another time.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
// ContainerUserEnvironmentVariable is used to specify the container user for | ||
// an SSH connection. | ||
// Only available if CODER_AGENT_DEVCONTAINERS_ENABLE=true. | ||
ContainerUserEnvironmentVariable = "CODER_CONTAINER_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.
No need to changeCODER_CONTAINER
orCODER_CONTAINER_USER
values, but should we prefix the varsityMagicSession
like the other?
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 personally dislike theMAGIC_
prefix as it doesn't really impart any information to the reader (except perhaps that it's mysterious and whimsical).
ec44f06
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fixes#16709 and#16420
Notes: