Skip to content

[sops] Allow encode=base64 config for sops provider#1064

Open
seuf wants to merge 1 commit intohelmfile:mainfrom
seuf:sops-provider-base64-encode
Open

[sops] Allow encode=base64 config for sops provider#1064
seuf wants to merge 1 commit intohelmfile:mainfrom
seuf:sops-provider-base64-encode

Conversation

@seuf
Copy link
Copy Markdown

@seuf seuf commented Mar 16, 2026

When referencing a sops secret, allow vals tu return it as a base64 encoded string

data:
  config.env: ref+sops://config/config.enc.env?encode=base64

the results is a base64 encoded string of the decrypted config/config.enc.env file.

It's like issue #163 but for sops provider.

Signed-off-by: Thierry Sallé <seuf76@gmail.com>
@seuf seuf force-pushed the sops-provider-base64-encode branch from 0ab83d2 to 34d9133 Compare March 17, 2026 09:29
@yxxhero yxxhero requested a review from Copilot March 23, 2026 00:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support to the sops provider for returning decrypted secret contents as a base64-encoded string via ?encode=base64, matching behavior already present in the file provider and addressing the use case described in issue #163.

Changes:

  • Introduce an encode configuration option for the sops provider (default: raw).
  • Update GetString to optionally base64-encode decrypted bytes when encode=base64.
  • Add unit tests verifying New reads the encode config and defaults it appropriately.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/providers/sops/sops.go Adds Encode config and applies it in GetString to return raw or base64 output.
pkg/providers/sops/sops_test.go Adds tests for default and configured Encode value in provider construction.

Comment on lines +68 to +72
switch p.Encode {
case "raw":
return string(cleartext), nil
case "base64":
return base64.StdEncoding.EncodeToString(cleartext), nil
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New encode behavior in GetString isn’t covered by unit tests (no tests call GetString in this package). Please add a test that exercises encode=base64 (verifies output matches base64.StdEncoding.EncodeToString of decrypted bytes) and the unsupported encode error path; this may require making decrypt stub-able (e.g., via an injectable function field) or adding a small helper that can be tested directly.

Copilot uses AI. Check for mistakes.
Comment on lines +251 to +262
func TestNewProviderReadsEncodeBase64(t *testing.T) {
cfg := config.MapConfig{
M: map[string]interface{}{
"encode": "base64",
},
}

p := New(log.New(log.Config{}), cfg, "")

if p.Encode != "base64" {
t.Errorf("Encode = %q, want %q", p.Encode, "base64")
}
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests validate that New reads encode, but they don’t validate the externally observable behavior (that GetString returns base64 when encode=base64). Consider extending coverage to assert the actual returned value/error for each encode mode, so regressions in GetString aren’t missed.

Copilot uses AI. Check for mistakes.
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.

2 participants