Skip to content

feat(cli): support header and header-command in config-ssh #10413

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 10 commits into from
Feb 7, 2024

Conversation

JoshVee
Copy link
Contributor

@JoshVee JoshVee commented Oct 30, 2023

This PR modifies the config-ssh command so that it includes any provided --header-command \ CODER_HEADER_COMMAND in the generated SSH ProxyCommand.

This ensures that any custom headers are also available when running ssh coder.workspace.

The avoids the need to always rely on having the CODER_HEADER_COMMAND environment variable set globally.

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Oct 30, 2023
@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 7, 2023
@matifali matifali removed the stale This issue is like stale bread. label Nov 7, 2023
@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 15, 2023
@github-actions github-actions bot closed this Nov 18, 2023
@spikecurtis spikecurtis reopened this Nov 21, 2023
@spikecurtis spikecurtis removed the stale This issue is like stale bread. label Nov 21, 2023
@mafredri
Copy link
Member

mafredri commented Nov 21, 2023

Hey @JoshVee, thanks for the PR and sorry for the long wait-time.

I think this PR looks good, but there's a change I'd like to see before we merge it, and that's support for serializing the header command into the options.

For instance, compare these two:

./coder config-ssh --header-command 'echo foo=bar'
> The following changes will be made to your SSH configuration:

    * Update the coder section in /home/coder/.ssh/coder

  Continue? (yes/no)yes

Versus:

./coder config-ssh --header-command 'echo foo=bar' -o ForwardAgent=yes
> New options differ from previous options:

  New options:
    * ssh-option: ForwardAgent=yes

  Previous options: none              (<- should list header command)

  Use new options? (yes/no)yes

> The following changes will be made to your SSH configuration:

    * Use new options
    * Update the coder section in /home/coder/.ssh/coder

  Continue? (yes/no)yes

Now let's say we forget about the header command next run, there's only going to be a cryptic change to the SSH config, and users may be left wondering why SSH isn't working afterwards (the update removes the header command, but doesn't say that the options/settings have changed):

./coder config-ssh -o ForwardAgent=yes
> The following changes will be made to your SSH configuration:

    * Update the coder section in /home/coder/.ssh/coder

  Continue? (yes/no)

The options are serialized under # Last config-ssh options::

# ------------START-CODER-----------
# This section is managed by coder. DO NOT EDIT.
#
# You should not hand-edit this section unless you are removing it, all
# changes will be lost when running "coder config-ssh".
#
# Last config-ssh options:
# :ssh-option=ForwardAgent=yes
#

I would suggest something like # :header-command=printf h1=v1.

@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 29, 2023
@github-actions github-actions bot closed this Dec 3, 2023
@mafredri mafredri reopened this Dec 3, 2023
@github-actions github-actions bot removed the stale This issue is like stale bread. label Dec 4, 2023
@mafredri mafredri removed their request for review December 7, 2023 14:30
@mafredri
Copy link
Member

mafredri commented Dec 7, 2023

@JoshVee are you still interested in working on this PR? If not, we can see if someone on the team has the bandwidth to tackle it.

@github-actions github-actions bot added the stale This issue is like stale bread. label Dec 15, 2023
@github-actions github-actions bot closed this Dec 18, 2023
@spikecurtis spikecurtis reopened this Dec 20, 2023
@github-actions github-actions bot removed the stale This issue is like stale bread. label Dec 21, 2023
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 2, 2024
@matifali matifali removed the stale This issue is like stale bread. label Jan 2, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 10, 2024
@github-actions github-actions bot closed this Jan 13, 2024
@mafredri mafredri reopened this Jan 16, 2024
@mafredri mafredri removed the stale This issue is like stale bread. label Jan 16, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 24, 2024
@github-actions github-actions bot closed this Jan 28, 2024
@mafredri mafredri reopened this Jan 28, 2024
@github-actions github-actions bot removed the stale This issue is like stale bread. label Jan 29, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 5, 2024
@mafredri mafredri removed the stale This issue is like stale bread. label Feb 5, 2024
@mafredri mafredri changed the title feat(cli): add provided header command to the SSH config feat(cli): add support for header and header-command to config-ssh Feb 5, 2024
rootFlags += fmt.Sprintf(" --header %q", h)
}
if sshConfigOpts.headerCommand != "" {
rootFlags += fmt.Sprintf(" --header-command %q", sshConfigOpts.headerCommand)
Copy link
Member

Choose a reason for hiding this comment

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

Review: We shouldn't need to do special escaping here like we do for the coder binary, that's because we're simply passing a string argument to coder.

@mafredri
Copy link
Member

mafredri commented Feb 5, 2024

Updated the PR with changes to support serialization, while I was at it, I included support for --header, too.

./coder config-ssh --header-command 'echo "foo=bar"' -o ForwardAgent=yes

> New options differ from previous options:

  New options:
    * ssh-option: ForwardAgent=yes
    * header-command: echo "foo=bar"

  Previous options:
    * ssh-option: ForwardAgent=yes
    * header: foo=bar

Ready for review @Emyrk.

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

👍

Comment on lines +120 to +123
a = slices.Clone(a)
slices.Sort(a)
b = slices.Clone(b)
slices.Sort(b)
Copy link
Member

Choose a reason for hiding this comment

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

nit: curious, can we replace slices.Clone with a simple copy to omit cloning and just operate on same objects?

Copy link
Member

Choose a reason for hiding this comment

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

// Clone returns a copy of the slice.
// The elements are copied using assignment, so this is a shallow clone.

It's actually just a simple copy, so I think it's fine.

@mafredri mafredri changed the title feat(cli): add support for header and header-command to config-ssh feat(cli): support header and header-command in config-ssh Feb 7, 2024
@mafredri mafredri merged commit d3ccb07 into coder:main Feb 7, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2024
@mafredri
Copy link
Member

mafredri commented Feb 7, 2024

Thanks for your contribution @JoshVee, this finally went in!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants