Repository navigation
Redact token exchange secrets on workload export - #7449
Tyagiquamar wants to merge 1 commit into
Conversation
The export endpoint cleared OIDC client secrets but returned the token exchange client secret in token_exchange_config and in the token exchange middleware parameters. Clear it in both places, matching the OIDC behavior, without mutating the persisted configuration. Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7449 +/- ##
==========================================
+ Coverage 82.80% 82.85% +0.05%
==========================================
Files 949 952 +3
Lines 98157 98445 +288
==========================================
+ Hits 81280 81569 +289
+ Misses 16872 16871 -1
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
Thanks for this. Clearing both the typed field and the copy inside the middleware params is the right fix, and the test that checks the secret string never shows up in the response body is a good guard. One thing I'd like changed in the test (inline), plus a few smaller notes.
For the PR description: this changes what a client sees, so it'd help to spell it out under the user-facing section. Export now returns an empty token exchange client_secret, so anyone re-importing an export has to supply it again, same as the OIDC secret today. Also thv export --format json still writes the loaded config unredacted (cmd/thv/app/export.go), which is probably fine for a local 0600 file, but worth saying it's deliberate.
The @description on exportWorkload (workloads.go:695) doesn't mention that credentials are blanked. A short note there would help API consumers. If you change it, task docs needs a re-run so the swagger files match.
| require.NoError(t, json.Unmarshal(w.Body.Bytes(), &exported)) | ||
| require.NotNil(t, exported.TokenExchangeConfig) | ||
| assert.Empty(t, exported.TokenExchangeConfig.ClientSecret) | ||
| for _, middlewareConfig := range exported.MiddlewareConfigs { |
There was a problem hiding this comment.
This loop can run zero times, so the test would still pass if export dropped the token exchange middleware entry entirely (the NotContains check above would be satisfied too). The input side has require.True(foundTokenExchangeMiddleware), the response side needs the same.
While you're here, could the fixture put a token exchange entry in AdditionalMiddlewareConfigs as well, with a different secret? That list goes through its own redaction call and isn't covered right now. Then require both entries in the response, check their client IDs/token URLs survived, and assert neither secret appears in the body.
| return nil, fmt.Errorf("failed to encode auth middleware configuration: %w", err) | ||
| } | ||
| redacted[i].Parameters = parameters | ||
| case tokenexchange.MiddlewareType: |
There was a problem hiding this comment.
Small thing, not a blocker: this decodes into tokenexchange.MiddlewareParams and re-marshals, so any member of the stored params that this binary doesn't declare gets dropped from the export (it used to pass through untouched). In practice LoadState already drops unknown fields elsewhere in the RunConfig and the auth case above behaves the same way, so I wouldn't hold the PR on it. If you'd rather not drop anything, redacting on a map[string]json.RawMessage (and the nested token_exchange_config) would do it, ideally for both cases. Otherwise a line in the PR description noting the behavior is enough.
Summary
GET /api/v1beta/workloads/{name}/exportredacted OIDC client secrets but returned the token exchange client secret in plain text, both in the canonicaltoken_exchange_configfield and inside the serialized parameters of the token exchange middleware entry.redactRunConfigOIDCClientSecretsis renamed toredactRunConfigClientSecretsand now also clearsRunConfig.TokenExchangeConfig.ClientSecreton the exported copy.redactAuthMiddlewareConfigsis renamed toredactMiddlewareClientSecretsand now handlestokenexchangemiddleware entries in addition toauthentries, clearingtoken_exchange_config.client_secretinside their parameters. Other middleware types pass through unchanged, and the loaded on-disk configuration is never mutated.Fixes #7439
Type of change
Root cause
redactRunConfigOIDCClientSecrets(pkg/api/v1/workloads.go) only clearedOIDCConfig.ClientSecretand the OIDC client secret insideauthmiddleware parameters.PopulateMiddlewareConfigsembeds the fulltokenexchange.Config(includingClientSecret) into thetokenexchangemiddleware parameters, andRunConfig.TokenExchangeConfigis persisted alongside it, so a workload configured with token exchange exported its client secret to any caller of the export endpoint.Test plan
task test)task test-e2e)task lint-fix)Local environment has no
task/Go toolchain, so checks ran insidegolang:1.27Docker with named Go cache volumes:go build ./pkg/api/v1/- passedgo test ./pkg/api/v1/ -run "TestExportWorkload" -v- passed (2 tests)go test ./pkg/api/v1/- passedgo vet ./pkg/api/v1/- cleangofmton the LF-normalized files - clean (working tree is CRLF viacore.autocrlf; committed content is LF)New regression test
TestExportWorkload_RedactsTokenExchangeClientSecretsaves a workload withTokenExchangeConfigset, verifies the secret is present in both the canonical field and the middleware parameters before export, then asserts the export response contains no secret while the persisted state still has it.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Does this introduce a user-facing change?
Yes: the workload export endpoint no longer returns the token exchange client secret. Exported configurations that previously carried
client_secretvalues for token exchange now export it as an empty string, matching the existing OIDC redaction behavior.Special notes for reviewers
The existing OIDC redaction test was updated only for the function rename; its assertions are unchanged.