Skip to content

Commit

Permalink
Merge pull request #1086 from Permify/feature/hide-preshared-keys
Browse files Browse the repository at this point in the history
feat(config): mask pre-shared keys in output
  • Loading branch information
tolgaOzen committed Feb 27, 2024
2 parents 55deb7d + 1256c47 commit 5498524
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func conf() func(cmd *cobra.Command, args []string) error {
// AUTHN
[]string{"authn.enabled", fmt.Sprintf("%v", cfg.Authn.Enabled), getKeyOrigin(cmd, "authn-enabled", "PERMIFY_AUTHN_ENABLED")},
[]string{"authn.method", cfg.Authn.Method, getKeyOrigin(cmd, "authn-method", "PERMIFY_AUTHN_METHOD")},
[]string{"authn.preshared.keys", fmt.Sprintf("%v", cfg.Authn.Preshared.Keys), getKeyOrigin(cmd, "authn-preshared-keys", "PERMIFY_AUTHN_PRESHARED_KEYS")},
[]string{"authn.preshared.keys", fmt.Sprintf("%v", HideSecrets(cfg.Authn.Preshared.Keys...)), getKeyOrigin(cmd, "authn-preshared-keys", "PERMIFY_AUTHN_PRESHARED_KEYS")},
[]string{"authn.oidc.issuer", HideSecret(cfg.Authn.Oidc.Issuer), getKeyOrigin(cmd, "authn-oidc-issuer", "PERMIFY_AUTHN_OIDC_ISSUER")},
[]string{"authn.oidc.audience", HideSecret(cfg.Authn.Oidc.Audience), getKeyOrigin(cmd, "authn-oidc-audience", "PERMIFY_AUTHN_OIDC_AUDIENCE")},
// TRACER
Expand Down Expand Up @@ -177,3 +177,12 @@ func HideSecret(secret string) string {
// Keep first and last character visible; replace the rest with asterisks
return string(secret[0]) + strings.Repeat("*", len(secret)-2) + string(secret[len(secret)-1])
}

// HideSecrets obscures each string in a given list.
func HideSecrets(secrets ...string) (rv []string) {
// Convert each secret to its hidden version and collect them.
for _, secret := range secrets {
rv = append(rv, HideSecret(secret)) // Hide each secret.
}
return
}

0 comments on commit 5498524

Please sign in to comment.