Skip to content

feat: Add deployment side config-ssh options #6613

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 34 commits into from
Mar 16, 2023
Merged

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Mar 15, 2023

What this does

Allows setting deployment wide config-ssh options.

fixes #6501
fixes #6500

Bugs fixed

  • User provided config options did not override defaults if they shared the same key.
  • Invalid config ssh options were allowed.

Example

Ran coderd with env vars to overwrite a default ConnectTimeout and add a new option. Also changed the hostname prefix.

  • CODER_SSH_HOSTNAME_PREFIX=steven-local.
  • CODER_SSH_CONFIG_OPTIONS=ConnectTimeout=20,ConnectionAttempts=5
# ------------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".
#
Host steven-local.test
        HostName steven-local.test
        ConnectTimeout 20
        StrictHostKeyChecking=no
        UserKnownHostsFile=/dev/null
        LogLevel ERROR
        ProxyCommand /home/steven/go/bin/coder --global-config /home/steven/.config/coderv2 ssh --stdio test
        ConnectionAttempts 5
Host steven-local.test.main
        HostName steven-local.test.main
        ConnectTimeout 20
        StrictHostKeyChecking=no
        UserKnownHostsFile=/dev/null
        LogLevel ERROR
        ProxyCommand /home/steven/go/bin/coder --global-config /home/steven/.config/coderv2 ssh --stdio test.main
        ConnectionAttempts 5
# ------------END-CODER------------

cli/configssh.go Outdated
Comment on lines 322 to 335
// If the error is 404, this deployment does not support
// this endpoint yet. Do not error, just assume defaults.
// TODO: Remove this in 2 months (May 2023). Just return the error
// and remove this 404 check.
var sdkErr *codersdk.Error
if !xerrors.As(err, &sdkErr) {
// not an SDK error, return the original error.
return xerrors.Errorf("fetch coderd config failed: %w", err)
}

if sdkErr.StatusCode() != http.StatusNotFound {
// Not a 404, return the original error.
return xerrors.Errorf("fetch coderd config failed: %w", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just to support new coder cli against an older coderd. Can drop it after some time.

Copy link
Member

Choose a reason for hiding this comment

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

Meh, I don't think we should do this. Our install script supports installing by version, so it's really easy to upgrade/downgrade.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't care, I can drop it. I think it is mostly something developers will hit.

Copy link
Member

Choose a reason for hiding this comment

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

What error will users see when they do this on an old client?

Copy link
Member

@bpmct bpmct Mar 16, 2023

Choose a reason for hiding this comment

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

As long as it's clear to the user that they need to upgrade to resolve it, I don't think we need to have backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

Let's be sure to label this as a breaking change though

Copy link
Member Author

Choose a reason for hiding this comment

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

Can I just keep this then @kylecarbs? It makes things backwards compatible without docs needed. I included a drop date to remove the code.

It's just a convince to handle any edge cases, and it's not expensive or complex.

Comment on lines +375 to +389
// Override with deployment options
for k, v := range coderdConfig.SSHConfigOptions {
opt := fmt.Sprintf("%s %s", k, v)
err := configOptions.addOptions(opt)
if err != nil {
return xerrors.Errorf("add coderd config option %q: %w", opt, err)
}
}
// Override with flag options
for _, opt := range sshConfigOpts.sshOptions {
err := configOptions.addOptions(opt)
if err != nil {
return xerrors.Errorf("add flag config option %q: %w", opt, err)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Default > Deployment > Flags

So the user can always override any values by using -o flag.

@Emyrk Emyrk marked this pull request as ready for review March 15, 2023 17:59
@Emyrk Emyrk requested review from a team and mafredri and removed request for a team March 15, 2023 18:01
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

LGTM. Mostly small naming things. Just ping and I'll approve!

@Emyrk
Copy link
Member Author

Emyrk commented Mar 15, 2023

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Prob worth just doing ctrl+f CLISSH and replacing with SSH since this won't only apply to the CLI

@Emyrk Emyrk requested a review from kylecarbs March 15, 2023 21:15
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.

LGTM!

Override the default host prefix.
<br/>
| | |
| --- | --- |
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is this a bug in gen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh,I guess if the default is "", it doesn't put anything?

@Emyrk Emyrk merged commit fe247c8 into main Mar 16, 2023
@Emyrk Emyrk deleted the stevenmasley/ssh_config branch March 16, 2023 18:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 16, 2023
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.

Custom prefix for coder config-ssh Deployment-wide defaults for coder config-ssh
4 participants