diff --git a/scripts/validate/scan-platform-sensitive-source.sh b/scripts/validate/scan-platform-sensitive-source.sh index 1f84765..18fe2c8 100644 --- a/scripts/validate/scan-platform-sensitive-source.sh +++ b/scripts/validate/scan-platform-sensitive-source.sh @@ -732,6 +732,19 @@ def permitted_reference_container(key, value): ) +def permitted_s3_credentials_reference(path, key, value): + # CloudNativePG barmanObjectStore.s3Credentials: each entry is a + # SecretKeySelector (name and key only), never the value itself. + return ( + len(path) >= 1 + and path[-1] == "s3Credentials" + and key in ("accessKeyId", "secretAccessKey") + and isinstance(value, dict) + and set(value) == {"name", "key"} + and all(isinstance(value[field], str) and value[field] for field in value) + ) + + def permitted_webhook_feature(path, key, value): return ( tuple(str(part) for part in path) == ("operators", "object-store") @@ -767,6 +780,8 @@ def walk(value, path=()): pass elif permitted_reference_container(key, child): pass + elif permitted_s3_credentials_reference(path, key, child): + pass elif not isinstance(child, str) or unsafe_scalar(child): return True if walk(child, path + (key,)): diff --git a/scripts/validate/test-scan-platform-sensitive-source.sh b/scripts/validate/test-scan-platform-sensitive-source.sh index 3b382ef..d9bf67c 100644 --- a/scripts/validate/test-scan-platform-sensitive-source.sh +++ b/scripts/validate/test-scan-platform-sensitive-source.sh @@ -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'