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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
79535d0
feat: Allow setting deployment wide ssh config settings
Emyrk Mar 14, 2023
f0eb123
feat: config-ssh respects deployment ssh config
Emyrk Mar 15, 2023
4beeb62
Catch early parse error
Emyrk Mar 15, 2023
08f5d3d
Add to unit test
Emyrk Mar 15, 2023
c8c5189
fix typo
Emyrk Mar 15, 2023
96ad4bc
Add unit test
Emyrk Mar 15, 2023
f9f4a8f
Fix output
Emyrk Mar 15, 2023
ebf9eb9
Make gen
Emyrk Mar 15, 2023
119695b
Simplify if/else
Emyrk Mar 15, 2023
b8f3242
Fix AutorizeAllEndpoints
Emyrk Mar 15, 2023
b082a5a
Fic swager docs
Emyrk Mar 15, 2023
4a1e3c2
Make gen
Emyrk Mar 15, 2023
01ea08f
The '.' is now configurable
Emyrk Mar 15, 2023
7074f50
CODER env prefix is automatic
Emyrk Mar 15, 2023
952c591
Renames
Emyrk Mar 15, 2023
dae091a
Make gen
Emyrk Mar 15, 2023
a1dd7d4
Fix AutorizeAllEndpoints
Emyrk Mar 15, 2023
4f42634
Rename to drop 'CLI'
Emyrk Mar 15, 2023
c218edd
Prefix requires .
Emyrk Mar 15, 2023
a752fc8
Use constant in test
Emyrk Mar 15, 2023
d328d97
Linting
Emyrk Mar 15, 2023
a4b9620
Formatting
Emyrk Mar 15, 2023
78fbda8
Allow the user to override the host prefix
Emyrk Mar 16, 2023
d28b850
Fix doc messages
Emyrk Mar 16, 2023
617d987
Make gen
Emyrk Mar 16, 2023
eb4bb7b
Fix comment
Emyrk Mar 16, 2023
123ce02
Remove "CLI" part of naming
Emyrk Mar 16, 2023
ca41cce
Update golden files
Emyrk Mar 16, 2023
efcbc29
Fix 404 logic
Emyrk Mar 16, 2023
3c1c87f
remove 1 error check
Emyrk Mar 16, 2023
4586b11
Move buildinfo into deployment.go
Emyrk Mar 16, 2023
0f2ef97
fixup! Move buildinfo into deployment.go
Emyrk Mar 16, 2023
a5aac50
make gen
Emyrk Mar 16, 2023
a3254cd
Golden files
Emyrk Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Renames
  • Loading branch information
Emyrk committed Mar 15, 2023
commit 952c591d9a51a4a8e36989553c9cc792476e24fa
2 changes: 1 addition & 1 deletion cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestConfigSSH(t *testing.T) {
const expectedKey = "ConnectionAttempts"
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
ConfigSSH: codersdk.CLISSHConfigResponse{
ConfigSSH: codersdk.SSHConfigResponse{
HostnamePrefix: "test-coder",
SSHConfigOptions: map[string]string{
// Something we can test for
Expand Down
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ flags, and YAML configuration. The precedence is as follows:
LoginRateLimit: loginRateLimit,
FilesRateLimit: filesRateLimit,
HTTPClient: httpClient,
ConfigSSH: codersdk.CLISSHConfigResponse{
SSHConfig: codersdk.SSHConfigResponse{
HostnamePrefix: cfg.CLISSH.DeploymentName.String(),
SSHConfigOptions: configSSHOptions,
},
Expand Down
4 changes: 2 additions & 2 deletions coderd/clissh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// @Produce json
// @Tags General
// @Success 200 {object} codersdk.CLISSHConfigResponse
// @Router /config-ssh [get]
// @Router /deployment/ssh [get]
func (a *API) cliSSHConfig(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), rw, http.StatusOK, a.ConfigSSH)
httpapi.Write(r.Context(), rw, http.StatusOK, a.SSHConfig)
}
16 changes: 5 additions & 11 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ type Options struct {
DeploymentValues *codersdk.DeploymentValues
UpdateCheckOptions *updatecheck.Options // Set non-nil to enable update checking.

// ConfigSSH is the response clients use to configure config-ssh locally.
ConfigSSH codersdk.CLISSHConfigResponse
// SSHConfig is the response clients use to configure config-ssh locally.
SSHConfig codersdk.SSHConfigResponse

HTTPClient *http.Client
}
Expand Down Expand Up @@ -213,8 +213,8 @@ func New(options *Options) *API {
if options.Auditor == nil {
options.Auditor = audit.NewNop()
}
if options.ConfigSSH.HostnamePrefix == "" {
options.ConfigSSH.HostnamePrefix = "coder."
if options.SSHConfig.HostnamePrefix == "" {
options.SSHConfig.HostnamePrefix = "coder."
}
// TODO: remove this once we promote authz_querier out of experiments.
if experiments.Enabled(codersdk.ExperimentAuthzQuerier) {
Expand Down Expand Up @@ -405,17 +405,11 @@ func New(options *Options) *API {
r.Post("/csp/reports", api.logReportCSPViolations)

r.Get("/buildinfo", buildInfo)
r.Route("/config-ssh", func(r chi.Router) {
// Require auth for this route to prevent leaking the SSH config.
// to non-authenticated users. Also some config settings might
// be dependent on the user.
r.Use(apiKeyMiddleware)
r.Get("/", api.cliSSHConfig)
})
r.Route("/deployment", func(r chi.Router) {
r.Use(apiKeyMiddleware)
r.Get("/config", api.deploymentValues)
r.Get("/stats", api.deploymentStats)
r.Get("/ssh", api.cliSSHConfig)
})
r.Route("/experiments", func(r chi.Router) {
r.Use(apiKeyMiddleware)
Expand Down
4 changes: 2 additions & 2 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type Options struct {
Database database.Store
Pubsub database.Pubsub

ConfigSSH codersdk.CLISSHConfigResponse
ConfigSSH codersdk.SSHConfigResponse

SwaggerEndpoint bool
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
UpdateCheckOptions: options.UpdateCheckOptions,
SwaggerEndpoint: options.SwaggerEndpoint,
AppSigningKey: AppSigningKey,
ConfigSSH: options.ConfigSSH,
SSHConfig: options.ConfigSSH,
}
}

Expand Down
22 changes: 11 additions & 11 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1318,13 +1318,13 @@ when required by your organization's security policy.`,
Default: "coder.",
},
{
Name: "CLI SSH Config Options",
Description: "These cli config options will override the default ssh config options. " +
Name: "SSH Config Options",
Description: "These ssh config options will override the default ssh config options. " +
"Provide options in key=value format separated by commas." +
"Using this incorrectly can break ssh to your deployment. Use cautiously.",
Flag: "cli-ssh-options",
Env: "CLI_SSH_OPTIONS",
YAML: "cliSSHOptions",
Flag: "ssh-config-options",
Env: "SSH_CONFIG_OPTIONS",
YAML: "sshConfigOptions",
Group: &deploymentGroupClient,
Value: &c.CLISSH.SSHConfigOptions,
Hidden: false,
Expand Down Expand Up @@ -1645,24 +1645,24 @@ type DeploymentStats struct {
SessionCount SessionCountDeploymentStats `json:"session_count"`
}

type CLISSHConfigResponse struct {
type SSHConfigResponse struct {
HostnamePrefix string `json:"hostname_prefix"`
SSHConfigOptions map[string]string `json:"ssh_config_options"`
}

// SSHConfiguration returns information about the SSH configuration for the
// Coder instance.
func (c *Client) SSHConfiguration(ctx context.Context) (CLISSHConfigResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/config-ssh", nil)
func (c *Client) SSHConfiguration(ctx context.Context) (SSHConfigResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/deployment/ssh", nil)
if err != nil {
return CLISSHConfigResponse{}, err
return SSHConfigResponse{}, err
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return CLISSHConfigResponse{}, ReadBodyAsError(res)
return SSHConfigResponse{}, ReadBodyAsError(res)
}

var cliConfig CLISSHConfigResponse
var cliConfig SSHConfigResponse
return cliConfig, json.NewDecoder(res.Body).Decode(&cliConfig)
}