Skip to content

Commit

Permalink
Support sensitive for object parameters
Browse files Browse the repository at this point in the history
This adds support for tracking object parameters as sensitive. However,
if interpolating sub-properties of an object in templating, those will
not get tracked as sensitive.

Signed-off-by: Leo Bergnéhr <[email protected]>
  • Loading branch information
lbergnehr committed Sep 30, 2024
1 parent 3cb1f10 commit 7630bc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/runtime/runtime_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (m *RuntimeManifest) buildSourceData() (map[string]interface{}, error) {
return nil, err
}
if param.Sensitive {
m.setSensitiveValue(val.(string))
m.setSensitiveValue(fmt.Sprint(val))
}
params[pe] = val
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/runtime/runtime_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,23 @@ func TestResolveSensitiveParameter(t *testing.T) {
ctx := context.Background()
testConfig := config.NewTestConfig(t)
testConfig.Setenv("SENSITIVE_PARAM", "deliciou$dubonnet")
testConfig.Setenv("SENSITIVE_OBJECT", "{ \"secret\": \"this_is_secret\" }")
testConfig.Setenv("REGULAR_PARAM", "regular param value")

mContent := `schemaVersion: 1.0.0
parameters:
- name: sensitive_param
sensitive: true
- name: sensitive_object
sensitive: true
type: object
- name: regular_param
install:
- mymixin:
Arguments:
- ${ bundle.parameters.sensitive_param }
- '${ bundle.parameters.sensitive_object }'
- ${ bundle.parameters.regular_param }
`
rm := runtimeManifestFromStepYaml(t, testConfig, mContent)
Expand All @@ -322,12 +327,13 @@ install:
require.IsType(t, mixin["Arguments"], []interface{}{}, "Data.mymixin.Arguments has incorrect type")
args := mixin["Arguments"].([]interface{})

require.Len(t, args, 2)
require.Len(t, args, 3)
assert.Equal(t, "deliciou$dubonnet", args[0])
assert.Equal(t, "regular param value", args[1])
assert.Equal(t, "{\"secret\":\"this_is_secret\"}", args[1])
assert.Equal(t, "regular param value", args[2])

// There should now be one sensitive value tracked under the manifest
assert.Equal(t, []string{"deliciou$dubonnet"}, rm.GetSensitiveValues())
assert.Equal(t, []string{"deliciou$dubonnet", "{\"secret\":\"this_is_secret\"}"}, rm.GetSensitiveValues())
}

func TestResolveCredential(t *testing.T) {
Expand Down

0 comments on commit 7630bc3

Please sign in to comment.