Skip to content

feat(kubeseal): accept --from-file with --merge-into - #2087

Open
basitalisandhu wants to merge 1 commit into
bitnami:mainfrom
basitalisandhu:kubeseal-merge-from-file
Open

basitalisandhu wants to merge 1 commit into
bitnami:mainfrom
basitalisandhu:kubeseal-merge-from-file

Conversation

@basitalisandhu

Copy link
Copy Markdown

Description of the change

--from-file now works together with --merge-into, so an item can be added to or replaced in an existing sealed secret without building a temporary Secret first:

echo -n baz | kubeseal --merge-into mysealedsecret.json --from-file=bar=/dev/stdin

The name and namespace already came from the target file. The scope did not: new items were sealed with the scope of the input Secret (strict unless annotated), so merging into a cluster-wide or namespace-wide file wrote items the controller can't decrypt. SealMergingInto now uses the target's scope unless --scope is given. This covers the old TODO in TestMergeInto about scope mismatch.

Benefits

This is the "update one key" flow asked for in #1689. I went with a flag instead of a set KEY VALUE subcommand because kubeseal has no subcommands, and reading the value from a file or stdin keeps it out of shell history and ps.

Possible drawbacks

None that I can see. Without --from-file, the only behaviour change is the scope fix for non-strict targets.

Applicable issues

Additional information

Tests: TestMergeInto/cluster-wide (fails on main with no key could decrypt secret (foo)), TestSecretFromFiles, and TestMergeIntoFromFile, which seals a cluster-wide secret, merges a file item through runCLI and unseals it with the private key. go test ./cmd/... ./pkg/..., go vet and golangci-lint 2.15.0 pass. I also checked it by hand with a self-signed cert and --recovery-unseal.

Items can be added to an existing sealed secret straight from files,
without building a Secret first. The new items are sealed with the
scope of the target file, which also fixes merging a plain Secret
into a cluster-wide or namespace-wide sealed secret.

Signed-off-by: Muhammad Basit Ali <62793038+basitalisandhu@users.noreply.github.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.

A subcommand to update an existing sealed secret file

1 participant