-
Notifications
You must be signed in to change notification settings - Fork 4.8k
CNTRLPLANE-3789: Add e2e tests for authentication component proxy #31446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tchap
wants to merge
14
commits into
openshift:main
Choose a base branch
from
tchap:auth-proxy-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+980
−2
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f62ee9
Add component-scoped proxy e2e test helpers and keycloak client exten…
tchap 07369cb
Add component-scoped proxy e2e tests with shared setup
tchap d12c3dc
Improve proxy e2e test robustness and cleanup
tchap 8d852b9
Always return cleanup on error, register before Expect
tchap c31e2a4
Use net.JoinHostPort for host:port URL construction
tchap 930322d
Reuse WaitForOperatorsToSettle instead of custom operator status checks
tchap 4b4aa33
Add comment explaining why client secret is regenerated
tchap 9f3ea8e
Add comments explaining admin-cli token timeout and secret regeneration
tchap 5f050ab
Add comment explaining NO_PROXY superset check
tchap 487ed42
Fix vet errors
tchap 2224a7d
Use AfterEach for cleanup and remove redundant network policy cleanup
tchap 94ea07e
Use library-go/pkg/crypto for proxy TLS cert generation
tchap a2b9c93
Revert keycloak_helpers.go changes to reduce PR scope
tchap 4e27a4f
Remove squid log traffic check
tchap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| package authentication | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
|
|
||
| exutil "github.com/openshift/origin/test/extended/util" | ||
| operator "github.com/openshift/origin/test/extended/util/operator" | ||
| ) | ||
|
|
||
| var _ = g.Describe("[sig-auth][Suite:openshift/conformance/serial][OCPFeatureGate:AuthenticationComponentProxy][Serial][Slow]", func() { | ||
| oc := exutil.NewCLIWithoutNamespace("component-proxy") | ||
|
|
||
| var ( | ||
| ctx context.Context | ||
| httpProxyURL string | ||
| httpsProxyURL string | ||
| caCertPEM []byte | ||
| proxyNamespace string | ||
| kcSetup *keycloakProxySetup | ||
| cleanups []removalFunc | ||
| ) | ||
|
|
||
| g.BeforeEach(func() { | ||
| ctx = context.Background() | ||
| cleanups = nil | ||
|
|
||
| g.By("Saving auth state for restore after test") | ||
| authRestore, err := saveAndRestoreAuthState(ctx, oc) | ||
| cleanups = append(cleanups, authRestore) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Deploying Squid forward proxy") | ||
| var proxyCleanup removalFunc | ||
| httpProxyURL, httpsProxyURL, caCertPEM, proxyNamespace, proxyCleanup, err = deploySquidProxy(ctx, oc) | ||
| cleanups = append(cleanups, proxyCleanup) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Deploying Keycloak (without registering IdP yet)") | ||
| var kcCleanups []removalFunc | ||
| kcSetup, kcCleanups, err = deployKeycloakForProxy(ctx, oc) | ||
| cleanups = append(cleanups, kcCleanups...) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Waiting for operators to be stable before test") | ||
| err = operator.WaitForOperatorsToSettle(ctx, oc.AdminConfigClient(), 10) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.GinkgoWriter.Printf("Squid proxy URL: http=%s https=%s\n", httpProxyURL, httpsProxyURL) | ||
| g.GinkgoWriter.Printf("Keycloak issuer URL: %s\n", kcSetup.issuerURL) | ||
| g.GinkgoWriter.Printf("Keycloak namespace: %s\n", kcSetup.namespace) | ||
| }) | ||
|
|
||
| g.AfterEach(func() { | ||
| _ = removeResources(ctx, cleanups...) | ||
|
|
||
| g.By("Waiting for operators to be stable after test") | ||
| err := operator.WaitForOperatorsToSettle(ctx, oc.AdminConfigClient(), 10) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| }) | ||
|
|
||
| g.It("should validate OIDC IdP through component proxy", func() { | ||
| testOIDCIdPThroughComponentProxy(ctx, oc, kcSetup, httpProxyURL, nil, proxyNamespace) | ||
| }) | ||
| g.It("should validate OIDC IdP through component proxy with trustedCA", func() { | ||
| testOIDCIdPThroughComponentProxy(ctx, oc, kcSetup, httpsProxyURL, caCertPEM, proxyNamespace) | ||
| }) | ||
| g.It("should fall back on spec.proxy removal", func() { | ||
| testFallbackOnProxyRemoval(ctx, oc, kcSetup, httpProxyURL, proxyNamespace) | ||
| }) | ||
| }) | ||
|
|
||
| func testOIDCIdPThroughComponentProxy(ctx context.Context, oc *exutil.CLI, kcSetup *keycloakProxySetup, proxyURL string, trustedCACertPEM []byte, proxyNamespace string) { | ||
| withTrustedCA := len(trustedCACertPEM) > 0 | ||
|
|
||
| const trustedCAConfigMapName = "e2e-proxy-ca" | ||
| if withTrustedCA { | ||
| g.By("Creating trustedCA ConfigMap in openshift-config") | ||
| _, err := oc.AdminKubeClient().CoreV1().ConfigMaps("openshift-config").Create(ctx, &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: trustedCAConfigMapName, | ||
| Labels: componentProxyTestLabels(), | ||
| }, | ||
| Data: map[string]string{ | ||
| "ca-bundle.crt": string(trustedCACertPEM), | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| g.DeferCleanup(func(ctx context.Context) error { | ||
| return oc.AdminKubeClient().CoreV1().ConfigMaps("openshift-config").Delete(ctx, trustedCAConfigMapName, metav1.DeleteOptions{}) | ||
| }) | ||
| } | ||
|
|
||
| g.By("Deploying NetworkPolicy to restrict Keycloak ingress to proxy namespace only") | ||
| // We don't need to call the cleanup function since the whole namespace is removed in AfterEach. | ||
| _, err := deployProxyNetworkPolicies(ctx, oc, proxyNamespace, kcSetup.namespace) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Setting component-scoped proxy") | ||
| proxyConfig := operatorv1.AuthenticationProxyConfig{ | ||
| HTTPSProxy: proxyURL, | ||
| } | ||
| if withTrustedCA { | ||
| proxyConfig.TrustedCA = operatorv1.AuthenticationConfigMapReference{Name: trustedCAConfigMapName} | ||
| } | ||
| err = updateAuthenticationProxy(ctx, oc, proxyConfig) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Registering Keycloak as OIDC IdP (operator discovers it through the proxy)") | ||
| idpCleanups, err := addKeycloakOIDCIdPForProxy(ctx, oc, kcSetup) | ||
| g.DeferCleanup(func() { | ||
| _ = removeResources(ctx, idpCleanups...) | ||
| }) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Waiting for operator to pick up IdP changes and stabilize") | ||
| err = waitForOperatorToPickUpChanges(ctx, oc, "authentication") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Verifying OAuth server deployment has proxy env vars and trustedCA volume/mount") | ||
| err = verifyOAuthServerDeploymentProxyConfig(ctx, oc, "", proxyURL, ".cluster.local,.svc,127.0.0.1,localhost", withTrustedCA) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| if withTrustedCA { | ||
| g.By("Verifying trustedCA ConfigMap was synced to openshift-authentication") | ||
| err = verifyTrustedCAConfigMapSynced(ctx, oc) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| func testFallbackOnProxyRemoval(ctx context.Context, oc *exutil.CLI, kcSetup *keycloakProxySetup, httpProxyURL string, proxyNamespace string) { | ||
| g.By("Setting component-scoped proxy") | ||
| err := updateAuthenticationProxy(ctx, oc, operatorv1.AuthenticationProxyConfig{ | ||
| HTTPSProxy: httpProxyURL, | ||
| }) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Registering Keycloak as OIDC IdP") | ||
| idpCleanups, err := addKeycloakOIDCIdPForProxy(ctx, oc, kcSetup) | ||
| g.DeferCleanup(func() { | ||
| _ = removeResources(ctx, idpCleanups...) | ||
| }) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Waiting for operator to pick up IdP changes and stabilize") | ||
| err = waitForOperatorToPickUpChanges(ctx, oc, "authentication") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Removing spec.proxy from Authentication CR") | ||
| err = updateAuthenticationProxy(ctx, oc, operatorv1.AuthenticationProxyConfig{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Deleting Squid to prove the operator no longer routes through it") | ||
| err = oc.AdminKubeClient().CoreV1().Namespaces().Delete(ctx, proxyNamespace, metav1.DeleteOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Waiting for operator to pick up proxy removal and stabilize") | ||
| err = waitForOperatorToPickUpChanges(ctx, oc, "authentication") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| g.By("Verifying proxy env vars are no longer set on OAuth server deployment") | ||
| err = verifyOAuthServerDeploymentProxyConfig(ctx, oc, "", "", "", false) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.