Skip to content

Commit

Permalink
trim control characters from secret to prevent newlines in client sec…
Browse files Browse the repository at this point in the history
…ret (#3936)
  • Loading branch information
zac-nixon authored Nov 19, 2024
1 parent a2e0247 commit 6aab160
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/ingress/model_build_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (t *defaultModelBuildTask) buildAuthenticateOIDCAction(ctx context.Context,

t.secretKeys = append(t.secretKeys, secretKey)
clientID := strings.TrimRightFunc(string(rawClientID), unicode.IsSpace)
clientSecret := string(rawClientSecret)
clientSecret := strings.TrimRightFunc(string(rawClientSecret), unicode.IsControl)
return elbv2model.Action{
Type: elbv2model.ActionTypeAuthenticateOIDC,
AuthenticateOIDCConfig: &elbv2model.AuthenticateOIDCActionConfig{
Expand Down
55 changes: 55 additions & 0 deletions pkg/ingress/model_build_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,61 @@ func Test_defaultModelBuildTask_buildAuthenticateOIDCAction(t *testing.T) {
},
},
},
{
name: "clientSecret has control characters at end",
env: env{
secrets: []*corev1.Secret{
{
ObjectMeta: metav1.ObjectMeta{
Namespace: "my-ns",
Name: "my-k8s-secret",
},
Data: map[string][]byte{
"clientID": []byte("my-client-id"),
"clientSecret": []byte("my-client-secret\n"),
},
},
},
},
args: args{
authCfg: AuthConfig{
Type: AuthTypeCognito,
IDPConfigOIDC: &AuthIDPConfigOIDC{
Issuer: "https://example.com",
AuthorizationEndpoint: "https://authorization.example.com",
TokenEndpoint: "https://token.example.com",
UserInfoEndpoint: "https://userinfo.example.co",
SecretName: "my-k8s-secret",
AuthenticationRequestExtraParams: map[string]string{
"key1": "value1",
},
},
OnUnauthenticatedRequest: "authenticate",
Scope: "email",
SessionCookieName: "my-session-cookie",
SessionTimeout: 65536,
},
namespace: "my-ns",
},
want: elbv2model.Action{
Type: elbv2model.ActionTypeAuthenticateOIDC,
AuthenticateOIDCConfig: &elbv2model.AuthenticateOIDCActionConfig{
Issuer: "https://example.com",
AuthorizationEndpoint: "https://authorization.example.com",
TokenEndpoint: "https://token.example.com",
UserInfoEndpoint: "https://userinfo.example.co",
ClientID: "my-client-id",
ClientSecret: "my-client-secret",
AuthenticationRequestExtraParams: map[string]string{
"key1": "value1",
},
OnUnauthenticatedRequest: authBehaviorAuthenticate,
Scope: awssdk.String("email"),
SessionCookieName: awssdk.String("my-session-cookie"),
SessionTimeout: awssdk.Int64(65536),
},
},
},
{
name: "clientID & clientSecret configured - legacy clientId",
env: env{
Expand Down

0 comments on commit 6aab160

Please sign in to comment.