Skip to content

Commit 9350110

Browse files
committed
use TLS config from BTLPolicy to fetch auth endpoint
Signed-off-by: Huabing Zhao <[email protected]>
1 parent e3c0ae9 commit 9350110

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

internal/gatewayapi/securitypolicy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ func (t *Translator) buildOIDCProvider(policy *egv1a1.SecurityPolicy, resources
712712

713713
// Discover the token and authorization endpoints from the issuer's
714714
// well-known url if not explicitly specified
715+
// EG assumes that the issuer url uses the same protocol and CA as the token endpoint.
716+
// If we need to support different protocols or CAs, we need to add more fields to the OIDCProvider CRD.
715717
if provider.TokenEndpoint == nil || provider.AuthorizationEndpoint == nil {
716718
tokenEndpoint, authorizationEndpoint, err = fetchEndpointsFromIssuer(provider.Issuer, providerTLS)
717719
if err != nil {

test/e2e/testdata/oidc-securitypolicy-backendcluster.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ spec:
6666
maxInterval: 5s
6767
retryOn:
6868
triggers: ["5xx", "gateway-error", "reset"]
69-
issuer: "https://keycloak.gateway-conformance-infra/realms/master"
70-
authorizationEndpoint: "https://keycloak.gateway-conformance-infra/realms/master/protocol/openid-connect/auth"
71-
tokenEndpoint: "https://keycloak.gateway-conformance-infra/realms/master/protocol/openid-connect/token"
69+
issuer: "https://keycloak.gateway-conformance-infra/realms/master" # Test fetching auth endpoint from the issuer url
7270
clientID: "oidctest"
7371
clientSecret:
7472
name: "oidctest-secret"

test/e2e/tests/oidc-backendcluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func init() {
2323
var OIDCBackendClusterTest = suite.ConformanceTest{
2424
ShortName: "OIDC with BackendCluster",
2525
Description: "Test OIDC authentication",
26-
Manifests: []string{"testdata/oidc-keycloak.yaml", "testdata/oidc-securitypolicy-backendcluster.yaml"},
26+
Manifests: []string{"testdata/oidc-keycloak.yaml"},
2727
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
2828
t.Run("oidc provider represented by a BackendCluster", func(t *testing.T) {
2929
testOIDC(t, suite, "testdata/oidc-securitypolicy-backendcluster.yaml")

test/e2e/tests/oidc.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
var OIDCTest = suite.ConformanceTest{
4949
ShortName: "OIDC",
5050
Description: "Test OIDC authentication",
51-
Manifests: []string{"testdata/oidc-keycloak.yaml", "testdata/oidc-securitypolicy.yaml"},
51+
Manifests: []string{"testdata/oidc-keycloak.yaml"},
5252
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
5353
t.Run("oidc provider represented by a URL", func(t *testing.T) {
5454
testOIDC(t, suite, "testdata/oidc-securitypolicy.yaml")
@@ -104,6 +104,13 @@ func testOIDC(t *testing.T, suite *suite.ConformanceTestSuite, securityPolicyMan
104104
ns = "gateway-conformance-infra"
105105
)
106106

107+
podInitialized := corev1.PodCondition{Type: corev1.PodInitialized, Status: corev1.ConditionTrue}
108+
// Wait for the keycloak pod to be configured with the test user and client
109+
WaitForPods(t, suite.Client, ns, map[string]string{"job-name": "setup-keycloak"}, corev1.PodSucceeded, podInitialized)
110+
111+
// Apply the security policy that configures OIDC authentication
112+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, securityPolicyManifest, false)
113+
107114
routeNN := types.NamespacedName{Name: route, Namespace: ns}
108115
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
109116
httpGWAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN, "http"), routeNN)
@@ -115,12 +122,8 @@ func testOIDC(t *testing.T, suite *suite.ConformanceTestSuite, securityPolicyMan
115122
Namespace: gatewayapi.NamespacePtr(gwNN.Namespace),
116123
Name: gwapiv1.ObjectName(gwNN.Name),
117124
}
118-
SecurityPolicyMustBeAccepted(t, suite.Client, types.NamespacedName{Name: sp, Namespace: ns}, suite.ControllerName, ancestorRef)
119125

120-
podInitialized := corev1.PodCondition{Type: corev1.PodInitialized, Status: corev1.ConditionTrue}
121-
122-
// Wait for the keycloak pod to be configured with the test user and client
123-
WaitForPods(t, suite.Client, ns, map[string]string{"job-name": "setup-keycloak"}, corev1.PodSucceeded, podInitialized)
126+
SecurityPolicyMustBeAccepted(t, suite.Client, types.NamespacedName{Name: sp, Namespace: ns}, suite.ControllerName, ancestorRef)
124127

125128
// Initialize the test OIDC client that will keep track of the state of the OIDC login process
126129
oidcClient, err := NewOIDCTestClient(

0 commit comments

Comments
 (0)