Skip to content

fix(kubeseal): fail on malformed documents instead of skipping them - #2097

Open
lbarrosby wants to merge 1 commit into
bitnami:mainfrom
lbarrosby:fix/kubeseal-malformed-document
Open

lbarrosby wants to merge 1 commit into
bitnami:mainfrom
lbarrosby:fix/kubeseal-malformed-document

Conversation

@lbarrosby

Copy link
Copy Markdown

Description of the change

readSecrets and readSealedSecrets skip every document that decodes to an empty object, and that includes documents that failed to parse. So with a multi-document input where one document is broken, kubeseal seals the others, silently drops the broken one and exits 0:

cat <<'YAML' | kubeseal --cert cert.pem -o yaml
apiVersion: v1
kind: Secret
metadata:
  name: s1
data:
  foo: YmFy
---
apiVersion: v1
kind: Secret
metadata:
  name: s2
data: [
YAML

Only s1 comes out and nothing is reported for s2. The same happens for --validate and --re-encrypt, which go through readSealedSecrets.

The change returns the decode error when the document is empty and the error is not io.EOF. Empty documents (a stray ---, comment-only documents) still decode without an error and are skipped as before.

Benefits

A typo in one document of a multi-document file is reported instead of producing a SealedSecret file that is missing a secret.

Possible drawbacks

Inputs that only worked because the broken part was ignored now fail. When the first document is malformed, the error is now the parse error instead of "no secrets found".

Applicable issues

None found.

Additional information

Added TestSealWithMalformedDocument and TestReadSealedSecretsWithMalformedDocument; both fail on main and pass with the change. go test ./pkg/kubeseal/ ./cmd/kubeseal/ passes.

readSecrets and readSealedSecrets skipped any document that decoded
to an empty object, including documents that failed to parse. With a
multi-document input where one document has a YAML syntax error,
kubeseal sealed the valid ones, dropped the broken one and exited 0.

Return the decode error for empty documents too. Empty documents
(e.g. a stray "---") still decode without error and are skipped.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

This branch has not been deployed

No deployments
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