Skip to content

Commit d5b493c

Browse files
authored
Merge pull request kubernetes-sigs#1216 from kishorj/newline_dev
Strip trailing newlines from OIDC clientId
2 parents 99b7f5c + 43ed691 commit d5b493c

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

internal/ingress/auth/auth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package auth
33
import (
44
"context"
55
"fmt"
6+
"strings"
7+
"unicode"
68

79
"github.com/aws/aws-sdk-go/service/elbv2"
810
"github.com/kubernetes-sigs/aws-alb-ingress-controller/internal/ingress/annotations"
@@ -118,7 +120,6 @@ func (m *defaultModule) NewConfig(ctx context.Context, ingress *extensions.Ingre
118120
if _, err := annotations.LoadInt64Annotation(AnnotationAuthSessionTimeout, &cfg.SessionTimeout, serviceAnnos, ingressAnnos); err != nil {
119121
return Config{}, err
120122
}
121-
122123
switch cfg.Type {
123124
case TypeCognito:
124125
{
@@ -163,7 +164,7 @@ func (m *defaultModule) loadIDPOIDC(ctx context.Context, idpOIDC *IDPOIDC, names
163164
if err := m.cache.Get(ctx, secretKey, &k8sSecret); err != nil {
164165
return true, errors.Wrapf(err, "failed to load k8s secret: %v", secretKey)
165166
}
166-
clientId := string(k8sSecret.Data["clientId"])
167+
clientId := strings.TrimRightFunc(string(k8sSecret.Data["clientId"]), unicode.IsSpace)
167168
clientSecret := string(k8sSecret.Data["clientSecret"])
168169
*idpOIDC = IDPOIDC{
169170
AuthenticationRequestExtraParams: annoIDPOIDC.AuthenticationRequestExtraParams,

internal/ingress/auth/auth_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,59 @@ func TestDefaultModule_NewConfig(t *testing.T) {
211211
OnUnauthenticatedRequest: DefaultAuthOnUnauthenticatedRequest,
212212
},
213213
},
214+
{
215+
name: "service use oidc auth clientId with trailing whitespaces",
216+
ingress: &extensions.Ingress{
217+
ObjectMeta: metav1.ObjectMeta{
218+
Namespace: "namespace",
219+
Name: "ingress",
220+
},
221+
},
222+
backend: extensions.IngressBackend{
223+
ServiceName: "service",
224+
ServicePort: intstr.FromInt(80),
225+
},
226+
service: &corev1.Service{
227+
ObjectMeta: metav1.ObjectMeta{
228+
Namespace: "namespace",
229+
Name: "service",
230+
Annotations: map[string]string{
231+
parser.GetAnnotationWithPrefix(AnnotationAuthType): "oidc",
232+
parser.GetAnnotationWithPrefix(AnnotationAuthIDPOIDC): "{\"Issuer\": \"Issuer\",\"AuthorizationEndpoint\": \"AuthorizationEndpoint\",\"TokenEndpoint\": \"TokenEndpoint\",\"UserInfoEndpoint\": \"UserInfoEndpoint\",\"SecretName\": \"oidc-secret\",\"AuthenticationRequestExtraParams\": { \"param1\": \"value1\",\"param2\": \"value2\"}}",
233+
},
234+
},
235+
},
236+
secret: &corev1.Secret{
237+
ObjectMeta: metav1.ObjectMeta{
238+
Namespace: "namespace",
239+
Name: "oidc-secret",
240+
},
241+
Data: map[string][]byte{
242+
"clientId": []byte("clientId\t \n"),
243+
"clientSecret": []byte("clientSecret"),
244+
},
245+
},
246+
protocol: "HTTPS",
247+
expectedAuthCfg: Config{
248+
Type: TypeOIDC,
249+
IDPOIDC: IDPOIDC{
250+
Issuer: "Issuer",
251+
AuthorizationEndpoint: "AuthorizationEndpoint",
252+
AuthenticationRequestExtraParams: AuthenticationRequestExtraParams{
253+
"param1": "value1",
254+
"param2": "value2",
255+
},
256+
TokenEndpoint: "TokenEndpoint",
257+
UserInfoEndpoint: "UserInfoEndpoint",
258+
ClientId: "clientId",
259+
ClientSecret: "clientSecret",
260+
},
261+
Scope: DefaultAuthScope,
262+
SessionCookie: DefaultAuthSessionCookie,
263+
SessionTimeout: DefaultAuthSessionTimeout,
264+
OnUnauthenticatedRequest: DefaultAuthOnUnauthenticatedRequest,
265+
},
266+
},
214267
{
215268
name: "service use oidc auth",
216269
ingress: &extensions.Ingress{

0 commit comments

Comments
 (0)