Skip to content

Read a secret's stringData as well as its data - #464

Open
arpitjain099 wants to merge 1 commit into
carvel-dev:developfrom
arpitjain099:fix/read-secret-string-data
Open

arpitjain099 wants to merge 1 commit into
carvel-dev:developfrom
arpitjain099:fix/read-secret-string-data

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #460.

config.Secret only declares Data map[string][]byte, so stringData has nothing to unmarshal into and is dropped on the floor. Every reader then does secret.Data[ctlconf.SecretK8sCorev1BasicAuthUsernameKey], gets the zero value and carries on without credentials, which is why this shows up as a 401 from the registry instead of as a problem with the config.

stringData is the form you get when a secret is written by hand rather than generated, since the values are not base64, so it is likely the common shape for people hitting this.

This adds StringData to the struct and folds it into Data right after the unmarshal in NewConfigFromFiles, so nothing downstream has to know about it. On a key present in both, stringData wins, matching Kubernetes.

Three subtests through NewConfigFromFiles using the helmChart.repository.secretRef config from the issue: stringData alone, data alone, and both with an overlapping key. Against develop:

--- FAIL: TestSecretStringData/stringData_is_read
--- PASS: TestSecretStringData/data_is_still_read
--- FAIL: TestSecretStringData/stringData_wins_over_data_for_the_same_key

The middle one passing either way is the point of including it, since the change touches the path that already worked.

go build ./..., go vet ./pkg/vendir/config/ and go test ./pkg/... are clean. I did not run ./test/e2e, it wants a helm3 binary and a local registry that I do not have here.

The Secret struct only has Data, so a secret written with stringData
unmarshals with an empty Data and the credentials are dropped. Nothing
reports it: every reader looks the key up in Data, finds nothing, and
carries on without auth, which surfaces later as a 401 from the registry
rather than as a problem with the config.

stringData is how a secret gets written by hand, since the values are not
base64, so this is the shape most people hitting it will have used.

Fold StringData into Data after unmarshalling, with StringData winning on a
duplicate key, which is what Kubernetes does.

Fixes carvel-dev#460

Signed-off-by: Arpit Jain <arpitjain099@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 with stringData fail silently

2 participants