Skip to content

Commit 4f1a9a2

Browse files
authored
Merge pull request #1228 from M00nF1sh/i_1227
redact oidc
2 parents b2a4dbf + 450c300 commit 4f1a9a2

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-1
lines changed

internal/alb/ls/listener.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ func (controller *defaultController) LSInstanceNeedsModification(ctx context.Con
160160
needModification = true
161161
}
162162
if !actionsMatches(instance.DefaultActions, config.DefaultActions) {
163-
albctx.GetLogger(ctx).DebugLevelf(1, "listener defaultActions needs modification: %v => %v", awsutil.Prettify(instance.DefaultActions), awsutil.Prettify(config.DefaultActions))
163+
albctx.GetLogger(ctx).DebugLevelf(1, "listener defaultActions needs modification",
164+
awsutil.Prettify(redactActions(instance.DefaultActions)),
165+
awsutil.Prettify(redactActions(config.DefaultActions)))
164166
needModification = true
165167
}
166168
return needModification

internal/alb/ls/rules.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"strconv"
77

8+
"github.com/kubernetes-sigs/aws-alb-ingress-controller/pkg/util"
9+
810
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/annotations/conditions"
911
"github.com/pkg/errors"
1012
"k8s.io/apimachinery/pkg/util/intstr"
@@ -576,3 +578,18 @@ func isUnconditionalRedirect(listener *elbv2.Listener, r elbv2.Rule) bool {
576578
}
577579
return false
578580
}
581+
582+
// redactActions will redact sensitive information from actions, so it's safe for logging.
583+
func redactActions(actions []*elbv2.Action) []*elbv2.Action {
584+
actionsClone := make([]*elbv2.Action, len(actions))
585+
for index, action := range actions {
586+
actionClone := &elbv2.Action{}
587+
util.DeepCopyInto(actionClone, action)
588+
if actionClone.AuthenticateOidcConfig != nil {
589+
actionClone.AuthenticateOidcConfig.ClientId = aws.String("<redacted>")
590+
actionClone.AuthenticateOidcConfig.ClientSecret = aws.String("<redacted>")
591+
}
592+
actionsClone[index] = actionClone
593+
}
594+
return actionsClone
595+
}

internal/alb/ls/rules_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,3 +3101,72 @@ func redirectActionConfig(override *elbv2.RedirectActionConfig) *elbv2.RedirectA
31013101
}
31023102
return r
31033103
}
3104+
3105+
func Test_redactActions(t *testing.T) {
3106+
type args struct {
3107+
actions []*elbv2.Action
3108+
}
3109+
tests := []struct {
3110+
name string
3111+
args args
3112+
want []*elbv2.Action
3113+
}{
3114+
{
3115+
name: "actions needs redact",
3116+
args: args{
3117+
actions: []*elbv2.Action{
3118+
{
3119+
AuthenticateOidcConfig: &elbv2.AuthenticateOidcActionConfig{
3120+
ClientId: aws.String("my-client-id"),
3121+
ClientSecret: aws.String("my-secret"),
3122+
TokenEndpoint: aws.String("endpoint-1"),
3123+
},
3124+
},
3125+
{
3126+
AuthenticateOidcConfig: &elbv2.AuthenticateOidcActionConfig{
3127+
ClientId: aws.String("my-client-id"),
3128+
ClientSecret: aws.String("my-secret"),
3129+
TokenEndpoint: aws.String("endpoint-2"),
3130+
},
3131+
},
3132+
},
3133+
},
3134+
want: []*elbv2.Action{
3135+
{
3136+
AuthenticateOidcConfig: &elbv2.AuthenticateOidcActionConfig{
3137+
ClientId: aws.String("<redacted>"),
3138+
ClientSecret: aws.String("<redacted>"),
3139+
TokenEndpoint: aws.String("endpoint-1"),
3140+
},
3141+
},
3142+
{
3143+
AuthenticateOidcConfig: &elbv2.AuthenticateOidcActionConfig{
3144+
ClientId: aws.String("<redacted>"),
3145+
ClientSecret: aws.String("<redacted>"),
3146+
TokenEndpoint: aws.String("endpoint-2"),
3147+
},
3148+
},
3149+
},
3150+
},
3151+
{
3152+
name: "empty actions",
3153+
args: args{
3154+
actions: []*elbv2.Action{},
3155+
},
3156+
want: []*elbv2.Action{},
3157+
},
3158+
{
3159+
name: "nil actions",
3160+
args: args{
3161+
actions: nil,
3162+
},
3163+
want: []*elbv2.Action{},
3164+
},
3165+
}
3166+
for _, tt := range tests {
3167+
t.Run(tt.name, func(t *testing.T) {
3168+
got := redactActions(tt.args.actions)
3169+
assert.Equal(t, tt.want, got)
3170+
})
3171+
}
3172+
}

pkg/util/deepcopy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package util
2+
3+
import (
4+
"bytes"
5+
"encoding/gob"
6+
)
7+
8+
func DeepCopyInto(to interface{}, from interface{}) {
9+
buff := new(bytes.Buffer)
10+
enc := gob.NewEncoder(buff)
11+
dec := gob.NewDecoder(buff)
12+
_ = enc.Encode(from)
13+
_ = dec.Decode(to)
14+
}

pkg/util/deepcopy_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package util
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type structA struct {
10+
Name string
11+
}
12+
13+
type structB struct {
14+
Name string
15+
A *structA
16+
}
17+
18+
func TestDeepCopyInto(t *testing.T) {
19+
obj := structB{
20+
Name: "parent",
21+
A: &structA{
22+
Name: "child-1",
23+
},
24+
}
25+
objClone := structB{}
26+
DeepCopyInto(&objClone, obj)
27+
obj.A.Name = "child-2"
28+
29+
assert.Equal(t, structB{
30+
Name: "parent",
31+
A: &structA{
32+
Name: "child-2",
33+
},
34+
}, obj)
35+
assert.Equal(t, structB{
36+
Name: "parent",
37+
A: &structA{
38+
Name: "child-1",
39+
},
40+
}, objClone)
41+
}

0 commit comments

Comments
 (0)