Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: passing secret as sensitive config #6006

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pkg/expressions/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ func resolve(v reflect.Value, t tagData, m []Machine, force bool, finalize bool)
vv, _ = expr2.Static().StringValue()
} else {
vv = expr.Template()
if t.value == "template" && !IsTemplateStringWithoutExpressions(str) {
if IsTemplateStringWithInternalFnCall(vv) {
vv = CleanTemplateStringInternalFnCall(vv)
}
}
}
changed = vv != str
if ptr.Kind() == reflect.String {
Expand Down
8 changes: 0 additions & 8 deletions pkg/expressions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,3 @@ func CompileAndResolveTemplate(tpl string, m ...Machine) (Expression, error) {
func IsTemplateStringWithoutExpressions(tpl string) bool {
return !strings.Contains(tpl, "{{")
}

func IsTemplateStringWithInternalFnCall(tpl string) bool {
return strings.Contains(tpl, "{{\"{{\"}}"+InternalFnCall)
}

func CleanTemplateStringInternalFnCall(tpl string) string {
return strings.ReplaceAll(tpl, "{{\"{{\"}}"+InternalFnCall, "{{")
}
3 changes: 1 addition & 2 deletions pkg/expressions/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
)

const (
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
InternalFnCall = "__internal__fn__call__"
RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
)

type StdFunction struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo
secrets := append(layer.Secrets(), options.Secrets...)
for i := range secrets {
AnnotateControlledBy(&secrets[i], options.Config.Resource.RootId, options.Config.Resource.Id)
err = expressions.FinalizeForce(&secrets[i], machines...)
err = expressions.SimplifyForce(&secrets[i], machines...)
if err != nil {
return nil, errors.Wrap(err, "finalizing Secret")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/testworkflows/testworkflowprocessor/secretmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func createSecretMachine(mapEnvs map[string]corev1.EnvVarSource) expressions.Mac
Key: keyName,
},
}

return expressions.NewValue(fmt.Sprintf("{{%senv.%s}}", expressions.InternalFnCall, envName)), true, nil
v, err := expressions.Compile("env." + envName)
return v, true, err
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestSecret(t *testing.T) {
mapEnvs := make(map[string]corev1.EnvVarSource)
machine := createSecretMachine(mapEnvs)
assert.Equal(t, "{{"+expressions.InternalFnCall+"env.name_0_one_1_two_K_key_0_three_1_four}}", expressions.MustCall(machine, "secret", "name-one.two", "key-three.four"))
assert.Equal(t, "{{env.name_0_one_1_two_K_key_0_three_1_four}}", expressions.MustCall(machine, "secret", "name-one.two", "key-three.four"))
assert.EqualValues(t, map[string]corev1.EnvVarSource{
"_02S_name_0_one_1_two_K_key_0_three_1_four": {
SecretKeyRef: &corev1.SecretKeySelector{
Expand All @@ -28,7 +28,7 @@ func TestSecret(t *testing.T) {
func TestSecretComputed(t *testing.T) {
mapEnvs := make(map[string]corev1.EnvVarSource)
machine := createSecretMachine(mapEnvs)
assert.Equal(t, "{{"+expressions.InternalFnCall+"env.name_0_one_1_two_K_key_0_three_1_four}}", expressions.MustCall(machine, "secret", "name-one.two", "key-three.four", true))
assert.Equal(t, "{{env.name_0_one_1_two_K_key_0_three_1_four}}", expressions.MustCall(machine, "secret", "name-one.two", "key-three.four", true))
assert.EqualValues(t, map[string]corev1.EnvVarSource{
"_02CS_name_0_one_1_two_K_key_0_three_1_four": {
SecretKeyRef: &corev1.SecretKeySelector{
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowresolver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func getSecretCallExpression(expr expressions.Expression, k string, externalize
return nil, errors.Wrap(err, "config."+k)
}
if envVar.SecretKeyRef != nil {
expr = expressions.NewValue(fmt.Sprintf("{{%ssecret(\"%s\", \"%s\", true)}}", expressions.InternalFnCall,
return expressions.Compile(fmt.Sprintf("secret(\"%s\", \"%s\", true)",
envVar.SecretKeyRef.Name, envVar.SecretKeyRef.Key))
}

Expand Down
Loading