Skip to content

Commit 47ee8ff

Browse files
Always set service-account-jwks-uri to LB URL even with custom issuer
Signed-off-by: Shaza Aldawamneh <[email protected]>
1 parent 0bec046 commit 47ee8ff

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

pkg/operator/configobservation/auth/auth_serviceaccountissuer.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,14 @@ func observedConfig(existingConfig map[string]interface{},
128128
// If the issuer is not set in KAS, we rely on the config-overrides.yaml to set both
129129
// the issuer and the api-audiences but configure the jwks-uri to point to
130130
// the LB so that it does not default to KAS IP which is not included in the serving certs
131-
if observedActiveIssuer == defaultServiceAccountIssuerValue {
132-
infrastructureConfig, err := getInfrastructureConfig("cluster")
133-
if err != nil {
134-
return existingConfig, append(errs, err)
135-
}
136-
if apiServerExternalURL := infrastructureConfig.Status.APIServerURL; len(apiServerExternalURL) == 0 {
137-
return existingConfig, append(errs, fmt.Errorf("APIServerURL missing from infrastructure/cluster"))
138-
} else {
139-
apiServerArguments["service-account-jwks-uri"] = []interface{}{apiServerExternalURL + "/openid/v1/jwks"}
140-
}
131+
infrastructureConfig, err := getInfrastructureConfig("cluster")
132+
if err != nil {
133+
return existingConfig, append(errs, err)
134+
}
135+
if apiServerExternalURL := infrastructureConfig.Status.APIServerURL; len(apiServerExternalURL) == 0 {
136+
return existingConfig, append(errs, fmt.Errorf("APIServerURL missing from infrastructure/cluster"))
137+
} else {
138+
apiServerArguments["service-account-jwks-uri"] = []interface{}{apiServerExternalURL + "/openid/v1/jwks"}
141139
}
142140

143141
return map[string]interface{}{"apiServerArguments": apiServerArguments}, errs

pkg/operator/configobservation/auth/auth_serviceaccountissuer_test.go

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ func TestObservedConfig(t *testing.T) {
5454
expectedChange: true,
5555
},
5656
{
57-
name: "issuer set, no previous issuer",
58-
existingIssuer: "",
59-
issuer: "https://example.com",
60-
expectedIssuer: "https://example.com",
61-
expectedChange: true,
57+
name: "issuer set, no previous issuer",
58+
existingIssuer: "",
59+
issuer: "https://example.com",
60+
expectedIssuer: "https://example.com",
61+
expectInternalJWKI: true,
62+
expectedChange: true,
6263
},
6364
{
6465
name: "previous issuer was default, new is custom value",
@@ -67,14 +68,15 @@ func TestObservedConfig(t *testing.T) {
6768
expectedIssuer: "https://example.com",
6869
trustedIssuers: []string{defaultServiceAccountIssuerValue},
6970
expectedTrustedIssuers: []string{defaultServiceAccountIssuerValue},
70-
expectInternalJWKI: false, // this proves we remove the internal api LB when custom value is set
71+
expectInternalJWKI: true, // now jwks-uri should always point to LB URL
7172
expectedChange: true,
7273
},
7374
{
74-
name: "issuer set, previous issuer same",
75-
existingIssuer: "https://example.com",
76-
issuer: "https://example.com",
77-
expectedIssuer: "https://example.com",
75+
name: "issuer set, previous issuer same",
76+
existingIssuer: "https://example.com",
77+
issuer: "https://example.com",
78+
expectedIssuer: "https://example.com",
79+
expectInternalJWKI: true,
7880
},
7981
{
8082
name: "issuer set, previous issuer and trusted issuers same",
@@ -83,20 +85,23 @@ func TestObservedConfig(t *testing.T) {
8385
trustedIssuers: []string{"https://trusted.example.com"},
8486
expectedIssuer: "https://example.com",
8587
expectedTrustedIssuers: []string{"https://trusted.example.com"},
88+
expectInternalJWKI: true,
8689
},
8790
{
88-
name: "issuer set, previous issuer different",
89-
existingIssuer: "https://example.com",
90-
issuer: "https://example2.com",
91-
expectedIssuer: "https://example2.com",
92-
expectedChange: true,
91+
name: "issuer set, previous issuer different",
92+
existingIssuer: "https://example.com",
93+
issuer: "https://example2.com",
94+
expectedIssuer: "https://example2.com",
95+
expectInternalJWKI: true,
96+
expectedChange: true,
9397
},
9498
{
95-
name: "auth getter error",
96-
existingIssuer: "https://example2.com",
97-
issuer: "https://example.com",
98-
authError: expectedErrAuth,
99-
expectedIssuer: "https://example2.com",
99+
name: "auth getter error",
100+
existingIssuer: "https://example2.com",
101+
issuer: "https://example.com",
102+
authError: expectedErrAuth,
103+
expectedIssuer: "https://example2.com",
104+
expectInternalJWKI: true,
100105
},
101106
{
102107
name: "infra getter error",
@@ -106,6 +111,14 @@ func TestObservedConfig(t *testing.T) {
106111
expectedIssuer: defaultServiceAccountIssuerValue,
107112
expectInternalJWKI: true,
108113
},
114+
{
115+
name: "custom issuer, no previous issuer",
116+
existingIssuer: "",
117+
issuer: "https://custom.com",
118+
expectedIssuer: "https://custom.com",
119+
expectInternalJWKI: true, // should always set jwks-uri
120+
expectedChange: true,
121+
},
109122
} {
110123
t.Run(tc.name, func(t *testing.T) {
111124
testRecorder := events.NewInMemoryRecorder("SAIssuerTest", clock.RealClock{})
@@ -199,11 +212,9 @@ func apiConfigForIssuer(issuer string, trustedIssuers []string) *kubecontrolplan
199212
"service-account-issuer": append([]string{issuer}, trustedIssuers...),
200213
"api-audiences": append([]string{issuer}, trustedIssuers...),
201214
}
202-
if issuer == defaultServiceAccountIssuerValue {
203-
//delete(args, "service-account-issuer")
204-
//delete(args, "api-audiences")
205-
args["service-account-jwks-uri"] = kubecontrolplanev1.Arguments{testLBURI}
206-
}
215+
//delete(args, "service-account-issuer")
216+
//delete(args, "api-audiences")
217+
args["service-account-jwks-uri"] = kubecontrolplanev1.Arguments{testLBURI}
207218

208219
return &kubecontrolplanev1.KubeAPIServerConfig{
209220
TypeMeta: metav1.TypeMeta{

0 commit comments

Comments
 (0)