Skip to content

[refactor] Add K6_SECRET_SOURCE#5724

Open
vortegatorres wants to merge 3 commits intomasterfrom
add-k6-secret-source-env-var
Open

[refactor] Add K6_SECRET_SOURCE#5724
vortegatorres wants to merge 3 commits intomasterfrom
add-k6-secret-source-env-var

Conversation

@vortegatorres
Copy link
Contributor

What?

Add support for configuring secret sources via the K6_SECRET_SOURCE environment variable, as an alternative to the --secret-source CLI flag. K6_SECRET_SOURCE is treated as a single complete source spec — equivalent to one --secret-source flag — so its value follows the exact same syntax.

Why?

The --secret-source flag works well for interactive use, but there are cases where having this alternative might be useful.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

@vortegatorres vortegatorres requested a review from a team as a code owner March 11, 2026 14:35
@vortegatorres vortegatorres requested review from a team, ankur22, codebien, facundobatista, inancgumus and mstoykov and removed request for a team March 11, 2026 14:35
@vortegatorres
Copy link
Contributor Author

I tested this example:

K6_SECRET_SOURCE='file=file.secret'  ./k6 run  secrets.test.js

@vortegatorres vortegatorres temporarily deployed to azure-trusted-signing March 11, 2026 14:41 — with GitHub Actions Inactive
@vortegatorres vortegatorres temporarily deployed to azure-trusted-signing March 11, 2026 14:43 — with GitHub Actions Inactive
@vortegatorres vortegatorres changed the title [refactor] Add K6_SECRET_SOURCE [refactor] Add K6_SECRET_SOURCE Mar 11, 2026
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

stderr := ts.Stderr.String()
t.Log(stderr)
assert.NotContains(t, stderr, "level=error")
assert.Contains(t, stderr, `level=info msg="***SECRET_REDACTED***" source=console`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth asserting that you don't see the secret values?

})

t.Run("commas inside spec are not treated as source separators", func(t *testing.T) {
// mock=name=mysource,cool=val has a comma, but it belongs to the source
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what's going on here, to me this look wrong and should return an error, no?

t.Parallel()
ts := NewGlobalTestState(t)
require.NoError(t, fsext.WriteFile(ts.FS, filepath.Join(ts.Cwd, "script.js"), []byte(script), 0o644))
secretFile := filepath.Join(ts.Cwd, "secrets.env")
Copy link
Contributor

Choose a reason for hiding this comment

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

What other sources are there? Should there be tests for those too? e.g. url?


// TestK6SecretSourceEnvVar covers the K6_SECRET_SOURCE environment variable, which is
// treated as a single complete source spec equivalent to one --secret-source flag value.
func TestK6SecretSourceEnvVar(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would prefer a table test where possible.

@vortegatorres vortegatorres temporarily deployed to azure-trusted-signing March 11, 2026 20:23 — with GitHub Actions Inactive
@vortegatorres vortegatorres deployed to azure-trusted-signing March 11, 2026 20:24 — with GitHub Actions Active
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