Skip to content

Add --no-container to fly ssh console - #5075

Open
dangra wants to merge 1 commit into
masterfrom
pilot-machine-namespace-ssh
Open

Add --no-container to fly ssh console#5075
dangra wants to merge 1 commit into
masterfrom
pilot-machine-namespace-ssh

Conversation

@dangra

@dangra dangra commented Aug 12, 2026

Copy link
Copy Markdown
Member

On a machine that has containers, fly ssh console always lands you inside one: the only container, the first of several, or one you choose under --select. There was no way to ask for the machine itself, which is what you get on a machine without containers.

--no-container asks for the machine's own namespace:

fly ssh console --no-container

Passing it together with --container is an error.

Behaviour

  • Without the flag nothing changes.
  • The flag sends an explicit opt-in to the machine rather than just omitting the container, so a hand-rolled SSH client using a cert from fly ssh issue is unaffected — it sets no environment and keeps landing where it does today.
  • Against a machine running an older platform version the session is refused with an error rather than silently dropping you in a container.

Notes for the reviewer

  • ssh.Console and ssh.Client.Shell take a SessionTarget in place of the trailing container name, since the container and the machine-namespace choice are mutually exclusive and belong together. Both are exported; this changes their signatures.
  • SessionTarget now rejects a target that sets both rather than quietly preferring one, and Shell defers Close() immediately after opening the session — previously an error from Setenv could return without closing it.
  • fly sftp on a machine with containers already reads the machine's own filesystem rather than a container's. This PR does not change that, but it is worth knowing when comparing the two surfaces.

fly machine exec gets the same flag separately in #5077.

Copilot AI lite review requested due to automatic review settings August 12, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a consistent “session target” concept across SSH console and machine exec so users can explicitly choose between a container and the machine’s own namespace (via --no-container, and --container for fly machine exec).

Changes:

  • Introduces ssh.SessionTarget and updates ssh.Client.Shell / ssh.Console to accept it instead of a raw container string.
  • Adds --no-container to fly ssh console and enforces mutual exclusivity with --container during container selection.
  • Adds --container and --no-container to fly machine exec and wires them into the MachineExecRequest.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ssh/client.go Adds SessionTarget and updates Client.Shell to set target-selection env vars.
internal/command/ssh/ssh_terminal.go Updates Shell call site to pass an empty SessionTarget.
internal/command/ssh/console.go Adds --no-container, passes SessionTarget through to ssh.Console, and enforces exclusivity with --container.
internal/command/ssh/console_test.go Adds unit tests covering selectContainer behavior with --no-container.
internal/command/ssh/connect.go Extends ConnectParams with Machine (for passing selection through command flow).
internal/command/postgres/barman.go Updates ssh.Console call site for new SessionTarget signature.
internal/command/machine/run.go Updates ssh.Console call site for new SessionTarget signature.
internal/command/machine/exec.go Adds --container / --no-container flags and sets MachineExecRequest.Container / .Machine.
internal/command/console/console.go Updates ssh.Console call site to pass SessionTarget.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ssh/client.go
Comment on lines +134 to +138
switch {
case target.Machine:
if err := sess.Setenv("FLY_SSH_MACHINE", "1"); err != nil {
return err
}
@dangra
dangra force-pushed the pilot-machine-namespace-ssh branch from 6c493ed to d84e821 Compare August 13, 2026 04:48
@dangra dangra changed the title Add --no-container to ssh console and machine exec Add --no-container to fly ssh console Aug 13, 2026
On a machine with containers, `fly ssh console` always lands you inside
one: the only container, the first of several, or one picked under
--select. There was no way to reach the machine itself, which is what you
get on a machine without containers.

--no-container asks for the machine's own namespace instead. It sends an
explicit opt-in rather than just omitting the container, so a hand-rolled
SSH client using a cert from `fly ssh issue` is unaffected.

Console and Client.Shell now take a SessionTarget rather than a container
name, so the two mutually exclusive choices travel together.
@dangra
dangra force-pushed the pilot-machine-namespace-ssh branch from d84e821 to 553175f Compare August 13, 2026 04:56
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.

2 participants