Skip to content

fix: keep secrets redacted when --find-renames compares them - #1109

Open
cansentay wants to merge 1 commit into
databus23:masterfrom
cansentay:fix/find-renames-secret-redaction
Open

cansentay wants to merge 1 commit into
databus23:masterfrom
cansentay:fix/find-renames-secret-redaction

Conversation

@cansentay

Copy link
Copy Markdown

Problem

With --find-renames, a Secret that is renamed, or removed and added in the same diff, is printed as a parse error instead of the redacted manifest. sa and sb are two copies of a one-template chart; sb renames the Secret app-creds to app-creds-v2 and changes one value:

$ helm diff local ./sa ./sb --find-renames 0.9
default, app-creds, Secret (v1) has changed:
- Error parsing old secret: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field .data.password of type []uint8: illegal base64 data at input byte 0
+ Error parsing new secret: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field .data.password of type []uint8: illegal base64 data at input byte 8

When the pair is scored but not taken as a rename (e.g. --find-renames 0.01), the removal and the addition each show the same error line.

contentSearch redacts (or decodes) each candidate pair in place to score it, and doDiff then redacts the reported resources a second time. The redacted values ('-------- # (7 bytes)') are not base64, so the second pass cannot parse the secret. --show-secrets is not affected.

Fix

Score the candidates on copies of the two MappingResults, so that doDiff is the only place that redacts or decodes a reported secret. The same command now prints:

  # Source: s/templates/secret.yaml
  apiVersion: v1
  kind: Secret
  metadata:
-   name: app-creds
+   name: app-creds-v2
  data:
-   password: '-------- # (7 bytes)'
+   password: '++++++++ # (7 bytes)'
    token: 'REDACTED # (6 bytes)'
    username: 'REDACTED # (5 bytes)'
  type: Opaque

Tests

TestRenameDetectionWithRedactedSecrets covers a detected and a rejected rename of a Secret with the default redaction. Both cases fail on master with the error above. go test ./diff/ and make lint pass.

With --find-renames, contentSearch redacted (or decoded) each removed and
added Secret in place to score it as a rename candidate. doDiff then
redacted the reported pair a second time, and a redacted secret does not
parse as a secret any more: its data values are no longer base64. A
renamed Secret, and a removed or added one that was scored as a candidate,
was printed as

  Error parsing old secret: error unmarshaling JSON: ... illegal base64 data at input byte 0

instead of the redacted manifest.

Score the candidates on copies, so that doDiff transforms each secret once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant