fix(validate): accept CloudNativePG s3Credentials Secret references

PR #10 added the platform-postgres backup patch and its restore-drill
Cluster. Both hold barmanObjectStore.s3Credentials, where accessKeyId
and secretAccessKey are SecretKeySelectors (name and key). The
structured scan treats any non-string value under a key ending in
"access key" as a credential literal, so the source scan reported
CREDENTIAL_LITERAL for both files on main.

An entry directly under s3Credentials, named accessKeyId or
secretAccessKey, whose value is a mapping of exactly name and key
with non-empty strings, is now a reference. This mirrors the existing
exact rule for the Grafana client-secret secretKeyRef.

Rejected: a general "name and key is always a reference" rule. It
would also pass a literal hidden under some other credential key that
happens to have those two fields.

Risk: none beyond the two key names under that one parent. A literal
string, an extra child, or the same mapping under another parent is
still rejected (new test cases).

Verification: on desktop, the source scan of main 205927f reported the
two files before this change and passes after it. The unit test
passes in a non-canonical clone.
This commit is contained in:
DongHyeonka
2026-11-12 08:36:38 +09:00
parent 27eb8c1799
commit ae4e256c95
2 changed files with 53 additions and 0 deletions
@@ -378,6 +378,44 @@ envValueFrom:
YAML
expect_reject 'a secretKeyRef container with a literal child fails closed' \
'platform/bootstrap/reference-container.yaml'
rm -f -- "$WORK/platform/bootstrap/reference-container.yaml"
cat >"$WORK/platform/bootstrap/s3-credentials.yaml" <<'YAML'
spec:
backup:
barmanObjectStore:
s3Credentials:
accessKeyId:
name: platform-postgres-backup-s3
key: ACCESS_KEY_ID
secretAccessKey:
name: platform-postgres-backup-s3
key: ACCESS_SECRET_KEY
YAML
expect_clean 'a CloudNativePG s3Credentials Secret reference remains a reference'
cat >"$WORK/platform/bootstrap/s3-credentials.yaml" <<'YAML'
spec:
s3Credentials:
secretAccessKey:
name: platform-postgres-backup-s3
key: ACCESS_SECRET_KEY
value: should-never-be-printed-s3-reference
YAML
expect_reject 'an s3Credentials reference with an extra literal child fails closed' \
'platform/bootstrap/s3-credentials.yaml'
cat >"$WORK/platform/bootstrap/s3-credentials.yaml" <<'YAML'
spec:
storage:
secretAccessKey:
name: platform-postgres-backup-s3
key: ACCESS_SECRET_KEY
YAML
expect_reject 'a name and key container outside s3Credentials still fails closed' \
'platform/bootstrap/s3-credentials.yaml'
printf 'spec:\n s3Credentials:\n secretAccess%sKey: Actual%s\n' '' 'ProductionSecretValue9283' \
>"$WORK/platform/bootstrap/s3-credentials.yaml"
expect_reject 'a literal s3Credentials secret access key is rejected' \
'platform/bootstrap/s3-credentials.yaml'
new_fixture
cat >"$WORK/platform/bootstrap/webhook-feature.yaml" <<'YAML'