Skip to content

Commit 3748430

Browse files
committed
Strip secret values
1 parent ac997a9 commit 3748430

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

cli/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
617617
MetricsCacheRefreshInterval: vals.MetricsCacheRefreshInterval.Value(),
618618
AgentStatsRefreshInterval: vals.AgentStatRefreshInterval.Value(),
619619
DeploymentValues: vals,
620-
DeploymentOptions: opts,
620+
// Do not pass secret values to DeploymentOptions. All values should be read from
621+
// the DeploymentValues instead, this just serves to indicate the source of each
622+
// option. This is just defensive to prevent accidentally leaking.
623+
DeploymentOptions: codersdk.DeploymentOptionsWithoutSecrets(opts),
621624
PrometheusRegistry: prometheus.NewRegistry(),
622625
APIRateLimit: int(vals.RateLimit.API.Value()),
623626
LoginRateLimit: loginRateLimit,

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ type Options struct {
156156
// DeploymentOptions do contain the copy of DeploymentValues, but contain
157157
// contextual information about how the values were set.
158158
// Do not use DeploymentOptions to retrieve values, use DeploymentValues instead.
159+
// All secrets values are stripped.
159160
DeploymentOptions clibase.OptionSet
160161
UpdateCheckOptions *updatecheck.Options // Set non-nil to enable update checking.
161162

codersdk/deployment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,20 @@ type LinkConfig struct {
17621762
Icon string `json:"icon" yaml:"icon"`
17631763
}
17641764

1765+
// DeploymentOptionsWithoutSecrets returns a copy of the OptionSet with secret values omitted.
1766+
func DeploymentOptionsWithoutSecrets(set clibase.OptionSet) clibase.OptionSet {
1767+
cpy := make(clibase.OptionSet, 0, len(set))
1768+
for _, opt := range set {
1769+
cpyOpt := opt
1770+
if IsSecretDeploymentOption(cpyOpt) {
1771+
var empty clibase.String
1772+
cpyOpt.Value = &empty
1773+
}
1774+
cpy = append(cpy, cpyOpt)
1775+
}
1776+
return cpy
1777+
}
1778+
17651779
// WithoutSecrets returns a copy of the config without secret values.
17661780
func (c *DeploymentValues) WithoutSecrets() (*DeploymentValues, error) {
17671781
var ff DeploymentValues

0 commit comments

Comments
 (0)