Skip to content

Commit 24bdf1b

Browse files
committed
safely return secrets
1 parent 552e438 commit 24bdf1b

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

cli/deployment/config.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ func newConfig() *codersdk.DeploymentConfig {
152152
Default: 3,
153153
},
154154
PostgresURL: &codersdk.DeploymentConfigField[string]{
155-
Name: "Postgres Connection URL",
156-
Usage: "URL of a PostgreSQL database. If empty, PostgreSQL binaries will be downloaded from Maven (https://repo1.maven.org/maven2) and store all data in the config root. Access the built-in database with \"coder server postgres-builtin-url\".",
157-
Flag: "postgres-url",
155+
Name: "Postgres Connection URL",
156+
Usage: "URL of a PostgreSQL database. If empty, PostgreSQL binaries will be downloaded from Maven (https://repo1.maven.org/maven2) and store all data in the config root. Access the built-in database with \"coder server postgres-builtin-url\".",
157+
Flag: "postgres-url",
158+
Secret: true,
158159
},
159160
OAuth2: &codersdk.OAuth2Config{
160161
Github: &codersdk.OAuth2GithubConfig{
@@ -164,9 +165,10 @@ func newConfig() *codersdk.DeploymentConfig {
164165
Flag: "oauth2-github-client-id",
165166
},
166167
ClientSecret: &codersdk.DeploymentConfigField[string]{
167-
Name: "OAuth2 GitHub Client Secret",
168-
Usage: "Client secret for Login with GitHub.",
169-
Flag: "oauth2-github-client-secret",
168+
Name: "OAuth2 GitHub Client Secret",
169+
Usage: "Client secret for Login with GitHub.",
170+
Flag: "oauth2-github-client-secret",
171+
Secret: true,
170172
},
171173
AllowedOrgs: &codersdk.DeploymentConfigField[[]string]{
172174
Name: "OAuth2 GitHub Allowed Orgs",
@@ -203,9 +205,10 @@ func newConfig() *codersdk.DeploymentConfig {
203205
Flag: "oidc-client-id",
204206
},
205207
ClientSecret: &codersdk.DeploymentConfigField[string]{
206-
Name: "OIDC Client Secret",
207-
Usage: "Client secret to use for Login with OIDC.",
208-
Flag: "oidc-client-secret",
208+
Name: "OIDC Client Secret",
209+
Usage: "Client secret to use for Login with OIDC.",
210+
Flag: "oidc-client-secret",
211+
Secret: true,
209212
},
210213
EmailDomain: &codersdk.DeploymentConfigField[string]{
211214
Name: "OIDC Email Domain",
@@ -334,6 +337,7 @@ func newConfig() *codersdk.DeploymentConfig {
334337
Usage: "Enables SCIM and sets the authentication header for the built-in SCIM server. New users are automatically created with OIDC authentication.",
335338
Flag: "scim-auth-header",
336339
Enterprise: true,
340+
Secret: true,
337341
},
338342
UserWorkspaceQuota: &codersdk.DeploymentConfigField[int]{
339343
Name: "User Workspace Quota",
@@ -440,7 +444,7 @@ func NewViper() *viper.Viper {
440444
vip.AutomaticEnv()
441445
vip.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
442446

443-
setViperDefaults("", vip, &dc)
447+
setViperDefaults("", vip, dc)
444448

445449
return vip
446450
}

codersdk/deploymentconfig.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,30 @@ type DeploymentConfigField[T Flaggable] struct {
118118
Shorthand string `json:"shorthand"`
119119
Enterprise bool `json:"enterprise"`
120120
Hidden bool `json:"hidden"`
121+
Secret bool `json:"secret"`
121122
Default T `json:"default"`
122123
Value T `json:"value"`
123124
}
124125

126+
// MarshalJSON removes the Value field from the JSON output of any fields marked Secret.
127+
// nolint: revive
128+
func (f *DeploymentConfigField[T]) MarshalJSON() ([]byte, error) {
129+
if !f.Secret {
130+
return json.Marshal(f)
131+
}
132+
133+
return json.Marshal(DeploymentConfigField[T]{
134+
Name: f.Name,
135+
Usage: f.Usage,
136+
Flag: f.Flag,
137+
Shorthand: f.Shorthand,
138+
Enterprise: f.Enterprise,
139+
Hidden: f.Hidden,
140+
Secret: f.Secret,
141+
Default: f.Default,
142+
})
143+
}
144+
125145
// DeploymentConfig returns the deployment config for the coder server.
126146
func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error) {
127147
res, err := c.Request(ctx, http.MethodGet, "/api/v2/config/deployment", nil)

0 commit comments

Comments
 (0)