-
Notifications
You must be signed in to change notification settings - Fork 875
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3dc994a
56538a9
7437e49
a1d0d00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ing container
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,14 @@ const ( | |
// MagicSessionTypeEnvironmentVariable is used to track the purpose behind an SSH connection. | ||
// This is stripped from any commands being executed, and is counted towards connection stats. | ||
MagicSessionTypeEnvironmentVariable = "CODER_SSH_SESSION_TYPE" | ||
// 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" | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. No need to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally dislike the |
||
) | ||
|
||
// MagicSessionType enums. | ||
|
@@ -330,17 +338,17 @@ func (s *sessionCloseTracker) Close() error { | |
|
||
func extractContainerInfo(env []string) (container, containerUser string, filteredEnv []string) { | ||
for _, kv := range env { | ||
if strings.HasPrefix(kv, "CODER_CONTAINER=") { | ||
container = strings.TrimPrefix(kv, "CODER_CONTAINER=") | ||
if strings.HasPrefix(kv, ContainerEnvironmentVariable+"=") { | ||
container = strings.TrimPrefix(kv, ContainerEnvironmentVariable+"=") | ||
} | ||
|
||
if strings.HasPrefix(kv, "CODER_CONTAINER_USER=") { | ||
containerUser = strings.TrimPrefix(kv, "CODER_CONTAINER_USER=") | ||
if strings.HasPrefix(kv, ContainerUserEnvironmentVariable+"=") { | ||
containerUser = strings.TrimPrefix(kv, ContainerUserEnvironmentVariable+"=") | ||
} | ||
} | ||
|
||
return container, containerUser, slices.DeleteFunc(env, func(kv string) bool { | ||
return strings.HasPrefix(kv, "CODER_CONTAINER=") || strings.HasPrefix(kv, "CODER_CONTAINER_USER=") | ||
return strings.HasPrefix(kv, ContainerEnvironmentVariable+"=") || strings.HasPrefix(kv, ContainerUserEnvironmentVariable+"=") | ||
}) | ||
} | ||
|
||
|
@@ -536,7 +544,6 @@ func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []str | |
ptyLabel = "yes" | ||
} | ||
|
||
// plumb in envinfoer here to modify command for container exec? | ||
var ei usershell.EnvInfoer | ||
var err error | ||
if s.config.ExperimentalContainersEnabled && 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 and
coder 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.