-
Notifications
You must be signed in to change notification settings - Fork 121
[WIP] CNTRLPLANE-3851: Oauth server proxy config e2e #950
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
ehearne-redhat
wants to merge
30
commits into
openshift:master
Choose a base branch
from
ehearne-redhat:oauth-server-proxy-config-e2e
base: master
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.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
bfc1b89
transport: Add TransportForCARefWithProxy
tchap cd22c77
Add proxy resolution helpers
tchap 7ee06c7
Add component-scoped proxy to all controllers
tchap 6e856a3
Align integration tests
tchap ccddfe3
Add shared test helpers and improve test coverage
tchap 053f60f
Make mergeNoProxy output deterministic and remove duplicate test
tchap b52e4de
Load proxy trustedCA into endpoint accessible controller TLS config
tchap 9a6dc13
Add KUBERNETES_SERVICE_HOST to component proxy NO_PROXY entries
tchap 5d82d59
Add e2e test for proxy validation degraded condition
tchap 929b0a8
Add e2e test for IdPEndpointUnreachable warning event
tchap 5a6b3ad
Refactor e2e proxy tests: extract SaveAndRestoreProxyConfig helper, a…
tchap 6436859
Add A1/A2 e2e tests, split DeployKeycloak from AddKeycloakIDP
tchap b4381db
DeploySquidProxy returns host:port, callers choose http/https scheme
tchap b785c1f
A2 test: use TLS proxy with trustedCA, verify mount is removed after …
tchap 0bf8910
C2 test: verify IdP reachability check went through Squid proxy
tchap 9107129
Make the test suite disruptive
tchap 09983d1
VerifyOAuthServerDeploymentProxyConfig: accept explicit expected values
tchap a9160d8
Implement proxy e2e test helpers and clean up test code
tchap 2c1c88d
DeploySquidProxy: return both HTTP and HTTPS URLs, fix Squid 7 TLS co…
tchap 58ffa5d
Make A1 passing
tchap ee6d9be
Align test name
tchap 4fcc3d8
VerifyOAuthServerDeploymentProxyConfig: check NO_PROXY as superset
tchap e8ab356
Simplify A2 test: use plain HTTP proxy, no trustedCA
tchap 562571e
C1 test: start with working proxy before switching to bad URL
tchap 5f30dcb
Fix cleanup and conflict issues in proxy tests
tchap 82504a7
migrate tests over from origin to cao + test no proxy, full/partial p…
ehearne-redhat d25f343
add extractNamespaceFromIDPName()
ehearne-redhat 19184fd
use split api convention for keycloak deployment
ehearne-redhat d753a8f
amend tchap suggestions
ehearne-redhat 4fea0cf
fix testPartialFullProxyEnvVars()
ehearne-redhat 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
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
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,114 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "golang.org/x/net/http/httpproxy" | ||
|
|
||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
|
|
||
| "github.com/openshift/api/features" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| operatorv1listers "github.com/openshift/client-go/operator/listers/operator/v1" | ||
| "github.com/openshift/library-go/pkg/operator/configobserver/featuregates" | ||
|
|
||
| "github.com/openshift/cluster-authentication-operator/pkg/transport" | ||
| ) | ||
|
|
||
| // ResolvedProxy holds the effective proxy configuration for authentication components. | ||
| type ResolvedProxy struct { | ||
| *httpproxy.Config | ||
| TrustedCAName string | ||
| } | ||
|
|
||
| func (p *ResolvedProxy) IsProxyConfigured() bool { | ||
| return len(p.HTTPProxy) != 0 || len(p.HTTPSProxy) != 0 | ||
| } | ||
|
|
||
| // ProxyFunc returns a function that resolves the proxy URL for a given request URL. | ||
| func (p *ResolvedProxy) ProxyFunc() transport.ProxyFunc { | ||
| return transport.ProxyFunc(p.Config.ProxyFunc()) | ||
| } | ||
|
|
||
| // ResolveProxy reads the component-scoped proxy from the Authentication | ||
| // operator CR (when the feature gate is enabled) and returns the effective proxy | ||
| // settings. When no component proxy is configured, it falls back to the process | ||
| // environment (which reflects the cluster-wide proxy). | ||
| func ResolveProxy( | ||
| featureGateAccessor featuregates.FeatureGateAccess, | ||
| operatorAuthLister operatorv1listers.AuthenticationLister, | ||
| ) (*ResolvedProxy, error) { | ||
| authProxy, err := getComponentProxyConfig(featureGateAccessor, operatorAuthLister) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if authProxy != nil { | ||
| return &ResolvedProxy{ | ||
| TrustedCAName: authProxy.TrustedCA.Name, | ||
| Config: &httpproxy.Config{ | ||
| HTTPProxy: authProxy.HTTPProxy, | ||
| HTTPSProxy: authProxy.HTTPSProxy, | ||
| NoProxy: mergeNoProxy(authProxy.NoProxy), | ||
| }, | ||
| }, nil | ||
| } | ||
|
|
||
| return &ResolvedProxy{ | ||
| Config: httpproxy.FromEnvironment(), | ||
| }, nil | ||
| } | ||
|
|
||
| // getComponentProxyConfig returns the component-scoped proxy configuration | ||
| // from operator.openshift.io/v1 Authentication if the feature gate is enabled. | ||
| // Returns (nil, nil) when the gate is disabled or the resource is not found. | ||
| func getComponentProxyConfig( | ||
| featureGateAccessor featuregates.FeatureGateAccess, | ||
| operatorAuthLister operatorv1listers.AuthenticationLister, | ||
| ) (*operatorv1.AuthenticationProxyConfig, error) { | ||
| featureGates, err := featureGateAccessor.CurrentFeatureGates() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get current feature gates: %w", err) | ||
| } | ||
| if !featureGates.Enabled(features.FeatureGateAuthenticationComponentProxy) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| authOp, err := operatorAuthLister.Get("cluster") | ||
| if err != nil { | ||
| if errors.IsNotFound(err) { | ||
| return nil, nil | ||
| } | ||
| return nil, fmt.Errorf("failed to get operator.openshift.io/v1 authentication/cluster: %w", err) | ||
| } | ||
|
|
||
| proxy := authOp.Spec.Proxy | ||
| if proxy.HTTPProxy == "" && proxy.HTTPSProxy == "" { | ||
| return nil, nil | ||
| } | ||
| return &proxy, nil | ||
| } | ||
|
|
||
| // staticNoProxyEntries contains cluster-internal addresses that must bypass the | ||
| // proxy. Auth components connect to internal services via DNS names covered by | ||
| // .svc and .cluster.local. The kubernetes API service IP (KUBERNETES_SERVICE_HOST) | ||
| // is included explicitly because Go's in-cluster client connects to it by raw IP, | ||
| // which does not match the hostname-based entries above. | ||
| var staticNoProxyEntries = func() []string { | ||
| entries := []string{".cluster.local", ".svc", "127.0.0.1", "localhost"} | ||
| if host := os.Getenv("KUBERNETES_SERVICE_HOST"); host != "" { | ||
| entries = append(entries, host) | ||
| } | ||
| return entries | ||
| }() | ||
|
|
||
| // mergeNoProxy combines user-provided noProxy entries with static cluster-internal | ||
| // defaults. The result is deduplicated and sorted for deterministic output. | ||
| func mergeNoProxy(userNoProxy []string) string { | ||
| entries := sets.New[string](staticNoProxyEntries...) | ||
| entries.Insert(userNoProxy...) | ||
| return strings.Join(sets.List(entries), ",") | ||
| } | ||
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.