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
@@ -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,)):