Skip to content

Commit 8d7a767

Browse files
Copilotillume
andcommitted
Add values.schema.json and redact secrets from error messages
- Add config.apiServerEndpoint to charts/headlamp/values.schema.json - Redact user-supplied endpoints from error messages to prevent secret logging - For credentials/query/fragment errors: omit endpoint completely - For scheme errors: include only scheme+host (safe parts) - For path errors: include scheme+host+path (safe parts) - All 14 validation tests still pass - JSON schema valid Addresses security concern about logging secrets in error messages. Co-authored-by: illume <9541+illume@users.noreply.github.com>
1 parent 738c6e0 commit 8d7a767

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

backend/pkg/kubeconfig/kubeconfig.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,45 +1011,45 @@ func validateAPIServerEndpoint(endpoint string) (string, error) {
10111011

10121012
parsedURL, err := url.Parse(trimmed)
10131013
if err != nil || !parsedURL.IsAbs() || parsedURL.Host == "" || parsedURL.Hostname() == "" {
1014+
// Don't include the endpoint in error as it may contain sensitive data
10141015
return "", fmt.Errorf(
1015-
"invalid custom API server endpoint %q: must be an absolute URL with scheme and host",
1016-
trimmed,
1016+
"invalid custom API server endpoint: must be an absolute URL with scheme and host",
10171017
)
10181018
}
10191019

10201020
if parsedURL.Scheme != "https" {
1021+
// Safe to include scheme+host as it doesn't contain secrets
10211022
return "", fmt.Errorf(
1022-
"invalid custom API server endpoint %q: must be a full https:// URL",
1023-
trimmed,
1023+
"invalid custom API server endpoint %s://%s: must be a full https:// URL",
1024+
parsedURL.Scheme, parsedURL.Host,
10241025
)
10251026
}
10261027

10271028
// Disallow embedded credentials, query strings, fragments, and non-root paths
1029+
// Don't include the full URL in these errors to avoid logging secrets
10281030
if parsedURL.User != nil {
10291031
return "", fmt.Errorf(
1030-
"invalid custom API server endpoint %q: must not include user info (credentials)",
1031-
trimmed,
1032+
"invalid custom API server endpoint: must not include user info (credentials)",
10321033
)
10331034
}
10341035

10351036
if parsedURL.RawQuery != "" {
10361037
return "", fmt.Errorf(
1037-
"invalid custom API server endpoint %q: must not include a query string",
1038-
trimmed,
1038+
"invalid custom API server endpoint: must not include a query string",
10391039
)
10401040
}
10411041

10421042
if parsedURL.Fragment != "" {
10431043
return "", fmt.Errorf(
1044-
"invalid custom API server endpoint %q: must not include a fragment",
1045-
trimmed,
1044+
"invalid custom API server endpoint: must not include a fragment",
10461045
)
10471046
}
10481047

10491048
if parsedURL.Path != "" && parsedURL.Path != "/" {
1049+
// Safe to include scheme+host+path as path shouldn't contain secrets
10501050
return "", fmt.Errorf(
1051-
"invalid custom API server endpoint %q: path must be empty or '/' (scheme+host[:port] only)",
1052-
trimmed,
1051+
"invalid custom API server endpoint https://%s%s: path must be empty or '/' (scheme+host[:port] only)",
1052+
parsedURL.Host, parsedURL.Path,
10531053
)
10541054
}
10551055

charts/headlamp/values.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
"items": {
246246
"type": "string"
247247
}
248+
},
249+
"apiServerEndpoint": {
250+
"type": "string",
251+
"description": "Custom Kubernetes API server endpoint (overrides default in-cluster endpoint). Must be a full https:// URL. Useful when requests need to pass through a proxy like kube-oidc-proxy."
248252
}
249253
}
250254
},

0 commit comments

Comments
 (0)