Skip to content

Base64 decode input Secret data when evaluating SecretTemplate stringData - #757

Open
yuminn-k wants to merge 1 commit into
carvel-dev:developfrom
yuminn-k:fix-445-stringdata-decode
Open

yuminn-k wants to merge 1 commit into
carvel-dev:developfrom
yuminn-k:fix-445-stringdata-decode

Conversation

@yuminn-k

Copy link
Copy Markdown

Closes #445

What

When a SecretTemplate uses an input resource of kind Secret inside stringData, the value read from .data is the base64 text stored in the Secret. It was copied into stringData as is, and Kubernetes then base64 encoded it a second time when storing the generated Secret. data already decodes input values (evaluateBytes), so only stringData was affected.

This adds evaluateStringData, which evaluates stringData against input values in which the .data of every input Secret (apiVersion: v1, kind: Secret) is base64 decoded. It builds on the evaluateStringData suggestion in the review of the earlier attempt (#446). Other input kinds (for example a ConfigMap) and other Secret fields such as .metadata.name are unchanged. Annotations, labels and type are not changed.

A test case is added to Test_SecretTemplate: before the change it fails with prefix-dmFsdWUx-suffix (the base64 text of value1), after the change it passes with prefix-value1-suffix. docs/secret-template.md gets one line saying that input Secret .data is decoded in stringData.

Compatibility

This is a behavior change. docs/secret-template.md described stringData as "data that is not base64 encoded", and until now $(.secret.data.key) in stringData produced the raw base64 text. Anyone who relied on that (for example, deliberately wanting the base64 text of a Secret value inside stringData) will now get the decoded value instead, and their generated Secret will change on the next reconcile. I kept the change as narrow as I could: only .data of input resources that are Secrets is decoded, and nothing else. I did not add an opt-out or a new syntax; if you would prefer one, I am happy to rework this.

If an input Secret has a .data value that is not valid base64, stringData evaluation now fails with failed decoding base64 from a Secret, the same error data already returns. A Secret read through the Kubernetes API always has valid base64 there, so I do not expect this in practice.

Testing

  • go test ./pkg/... passes.
  • I could not run golangci-lint locally (the pinned version is not installed here); gofmt reports nothing.

…Data

Signed-off-by: YuMin Kim <yuminkim.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Secrets used as input resources are double base64 encoded when used in stringData

1 participant