Skip to content

Commit dbdacbb

Browse files
committed
oidc: configure an oidc client secret for the console to consume
1 parent 0dc595f commit dbdacbb

File tree

1 file changed

+45
-12
lines changed
  • test/extended/authentication

1 file changed

+45
-12
lines changed

test/extended/authentication/oidc.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
4949
var group string
5050
var originalAuth *configv1.Authentication
5151
var oauthUserConfig *rest.Config
52+
var oidcClientSecret string
5253

5354
var keycloakNamespace string
5455

5556
g.BeforeAll(func() {
5657
var err error
5758

58-
keycloakNamespace = fmt.Sprintf("oidc-keycloak-%s", rand.String(8))
59+
testID := rand.String(8)
60+
keycloakNamespace = fmt.Sprintf("oidc-keycloak-%s", testID)
5961

6062
cleanups, err = deployKeycloak(ctx, oc, keycloakNamespace)
6163
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error deploying keycloak")
@@ -72,9 +74,9 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
7274

7375
o.Expect(keycloakCli.ConfigureClient("admin-cli")).NotTo(o.HaveOccurred(), "should not encounter an error configuring the admin-cli client")
7476

75-
username = rand.String(8)
76-
password = rand.String(8)
77-
group = fmt.Sprintf("ocp-test-%s-group", rand.String(8))
77+
username = fmt.Sprintf("user-%s", testID)
78+
password = fmt.Sprintf("password-%s", testID)
79+
group = fmt.Sprintf("ocp-test-%s-group", testID)
7880

7981
o.Expect(keycloakCli.CreateGroup(group)).To(o.Succeed(), "should be able to create a new keycloak group")
8082
o.Expect(keycloakCli.CreateUser(username, password, group)).To(o.Succeed(), "should be able to create a new keycloak user")
@@ -83,11 +85,28 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
8385
o.Expect(err).NotTo(o.HaveOccurred(), "should not error getting authentications")
8486

8587
oauthUserConfig = oc.GetClientConfigForUser("oidc-e2e-oauth-user")
88+
89+
// create a dummy oidc client secret for the console to consume
90+
oidcClientSecret = fmt.Sprintf("openshift-console-oidc-client-secret-%s", testID)
91+
secret := &corev1.Secret{
92+
ObjectMeta: metav1.ObjectMeta{
93+
Name: oidcClientSecret,
94+
Namespace: "openshift-config",
95+
},
96+
Data: map[string][]byte{
97+
"clientSecret": []byte(`a-secret-value`),
98+
},
99+
}
100+
_, err = oc.AdminKubeClient().CoreV1().Secrets("openshift-config").Create(ctx, secret, metav1.CreateOptions{})
101+
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error creating oidc client secret")
102+
cleanups = append(cleanups, func(ctx context.Context) error {
103+
return oc.AdminKubeClient().CoreV1().Secrets("openshift-config").Delete(ctx, secret.Name, metav1.DeleteOptions{})
104+
})
86105
})
87106

88107
g.Describe("[OCPFeatureGate:ExternalOIDC]", g.Ordered, func() {
89108
g.BeforeAll(func() {
90-
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, nil)
109+
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, oidcClientSecret, nil)
91110
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error configuring OIDC authentication")
92111

93112
waitForRollout(ctx, oc)
@@ -254,7 +273,7 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
254273
g.Describe("external IdP is configured", func() {
255274
g.Describe("without specified UID or Extra claim mappings", func() {
256275
g.BeforeAll(func() {
257-
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, nil)
276+
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, oidcClientSecret, nil)
258277
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error configuring OIDC authentication")
259278

260279
waitForRollout(ctx, oc)
@@ -282,7 +301,7 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
282301

283302
g.Describe("with valid specified UID or Extra claim mappings", func() {
284303
g.BeforeAll(func() {
285-
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, func(o *configv1.OIDCProvider) {
304+
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, oidcClientSecret, func(o *configv1.OIDCProvider) {
286305
o.ClaimMappings.UID = &configv1.TokenClaimOrExpressionMapping{
287306
Expression: "claims.preferred_username.upperAscii()",
288307
}
@@ -331,7 +350,7 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
331350

332351
g.Describe("with invalid specified UID or Extra claim mappings", func() {
333352
g.It("should reject admission when UID claim expression is not compilable CEL", func() {
334-
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, func(o *configv1.OIDCProvider) {
353+
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, oidcClientSecret, func(o *configv1.OIDCProvider) {
335354
o.ClaimMappings.UID = &configv1.TokenClaimOrExpressionMapping{
336355
Expression: "!@&*#^",
337356
}
@@ -340,7 +359,7 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
340359
})
341360

342361
g.It("should reject admission when Extra claim expression is not compilable CEL", func() {
343-
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, func(o *configv1.OIDCProvider) {
362+
_, _, err := configureOIDCAuthentication(ctx, oc, keycloakNamespace, oidcClientSecret, func(o *configv1.OIDCProvider) {
344363
o.ClaimMappings.Extra = []configv1.ExtraMapping{
345364
{
346365
Key: "payload/test",
@@ -384,7 +403,7 @@ func removeResources(ctx context.Context, removalFuncs ...removalFunc) error {
384403
return errors.FilterOut(errors.NewAggregate(errs), apierrors.IsNotFound)
385404
}
386405

387-
func configureOIDCAuthentication(ctx context.Context, client *exutil.CLI, keycloakNS string, modifier func(*configv1.OIDCProvider)) (*configv1.Authentication, *configv1.Authentication, error) {
406+
func configureOIDCAuthentication(ctx context.Context, client *exutil.CLI, keycloakNS, oidcClientSecret string, modifier func(*configv1.OIDCProvider)) (*configv1.Authentication, *configv1.Authentication, error) {
388407
authConfig, err := client.AdminConfigClient().ConfigV1().Authentications().Get(ctx, "cluster", metav1.GetOptions{})
389408
if err != nil {
390409
return nil, nil, fmt.Errorf("getting authentications.config.openshift.io/cluster: %w", err)
@@ -393,7 +412,7 @@ func configureOIDCAuthentication(ctx context.Context, client *exutil.CLI, keyclo
393412
original := authConfig.DeepCopy()
394413
modified := authConfig.DeepCopy()
395414

396-
oidcProvider, err := generateOIDCProvider(ctx, client, keycloakNS)
415+
oidcProvider, err := generateOIDCProvider(ctx, client, keycloakNS, oidcClientSecret)
397416
if err != nil {
398417
return nil, nil, fmt.Errorf("generating OIDC provider: %w", err)
399418
}
@@ -414,7 +433,7 @@ func configureOIDCAuthentication(ctx context.Context, client *exutil.CLI, keyclo
414433
return original, modified, nil
415434
}
416435

417-
func generateOIDCProvider(ctx context.Context, client *exutil.CLI, namespace string) (*configv1.OIDCProvider, error) {
436+
func generateOIDCProvider(ctx context.Context, client *exutil.CLI, namespace, oidcClientSecret string) (*configv1.OIDCProvider, error) {
418437
idpName := "keycloak"
419438
caBundle := "keycloak-ca"
420439
audiences := []configv1.TokenAudience{
@@ -447,6 +466,20 @@ func generateOIDCProvider(ctx context.Context, client *exutil.CLI, namespace str
447466
},
448467
},
449468
},
469+
// while this config is not required for the tests in this suite, if omitted
470+
// the console-operator will go Degraded; since we're currently running these
471+
// tests in clusters where the Console is installed, we provide this config
472+
// to avoid breaking cluster operator monitor tests
473+
OIDCClients: []configv1.OIDCClientConfig{
474+
{
475+
ComponentName: "console",
476+
ComponentNamespace: "openshift-console",
477+
ClientID: "openshift-console-oidc-client",
478+
ClientSecret: configv1.SecretNameReference{
479+
Name: oidcClientSecret,
480+
},
481+
},
482+
},
450483
}, nil
451484
}
452485

0 commit comments

Comments
 (0)