-
Notifications
You must be signed in to change notification settings - Fork 360
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
Envoy Gateway OIDC: Error with Self-Signed Certificate #4838
Comments
cc @zhaohuabing |
Hi @arkodg I am also facing the same issue. Kindly find the details below We are using Envoy Gateway (installed via Helm chart) as the Gateway API in our MicroK8s cluster running on a Red Hat VM in an air-gapped environment. Our setup includes: Backend application running as a pod inside the MicroK8s cluster. Current Behavior: Problem: Goal:
Please find the yaml files we have used:
Even after using backendrefs and BackendTLSPolicy, we are still facing the same OIDC error. |
The specified ca is only used by the envoy. Envoy Gateway doesn't use it to fetch the endpoints from issue's well-known openid configuration url. @williamdlm @shivanidwivedi10 As a workaround, you can explicitly set the |
Thank you for checking this! @zhaohuabing I have tried with authorizationEndpoint and tokenEndpoint as well, with this we are able to get the Keycloak page after entering Username and password, it gives a blank page stating OAuth Flow Failed. |
@shivanidwivedi10 Keycloak should work. Envoy Gateway runs an e2e test with Keycloak for every commit. You can comapre your configuration with the e2e to see if there are any noticable differences. https://github.com/envoyproxy/gateway/blob/main/test/e2e/testdata/oidc-securitypolicy.yaml Are there any errors in the envoy log when the OAuth flow failed? |
Thank you for your response! Using
Here are my configurations for comparison: apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: app1-route
namespace: default
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: eg
rules:
- backendRefs:
- group: ""
kind: Service
name: app1-service
port: 80
matches:
- path:
type: PathPrefix
value: /app1
---
apiVersion: v1
data:
client-secret: MnkyWnpFMThsbWFDYXE0U0VFcVhZU3hmTnBQT2VKb2g=
kind: Secret
metadata:
name: my-app-client-secret
namespace: default
type: Opaque
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
name: oidc-example
namespace: default
spec:
oidc:
clientID: envoy
clientSecret:
group: ""
kind: Secret
name: my-app-client-secret
logoutPath: /protocol/openid-connect/logout
provider:
authorizationEndpoint: https://my.keycloak.org/realms/master/protocol/openid-connect/auth
issuer: https://my.keycloak.org/realms/master
tokenEndpoint: https://my.keycloak.org/realms/master/protocol/openid-connect/token
redirectURL: http://myapp.local:10080/app1
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: app1-route I reviewed them alongside your example, but I didn't notice anything unusual that could explain the issue. |
I adjusted the redirectURL value in my SecurityPolicy to http://myapp.local:10080/oauth2/callback because I have an HTTPRoute that redirects to my service. After making this change, I noticed a change in behavior: when I send a request, I am redirected to the Keycloak login screen instead of receiving an unauthorized response, even though I did not provide a valid token. Furthermore, when I attempt to send a valid token, it still redirects me to the Keycloak login screen. curl -i myapp.local:10080/app1
HTTP/1.1 302 Found
set-cookie: OauthNonce-76fd001b=1733523382007600;path=/;Max-Age=600;secure;HttpOnly
location: https://my.keycloak.org/realms/master/protocol/openid-connect/auth?client_id=envoy&redirect_uri=http%3A%2F%2Fmyapp.local%3A10080%2Foauth2%2Fcallback&response_type=code&scope=openid&state=url%3Dhttp%253A%252F%252Fmyapp.local%253A10080%252Fapp1%26nonce%3D1733523382007600
date: Fri, 06 Dec 2024 22:16:21 GMT
content-length: 0 I expect that when I make a request to the /app1 path with a valid token, the SecurityPolicy will authenticate with my Keycloak and redirect to the service specified in the redirectURL. Any tips or advice on how to achieve the expected behavior? |
@williamdlm The callback url should not be the same as your httproute path matching. Change the redirect url to : http://myapp.local:10080/app1/callback in both the SecurityPlolicy and the Keyloak configuration, then it should work. |
I work with @shivanidwivedi10 We were having an nginx(ingress) as a reverse proxy and it was blocking the request/authentication token from header, due the higher buffer size limit in ingress. We check the logs of ingress controller and found the error logs. Just put the logs in chatgpt and it suggested to add more annotations to ingress resource to increase the buffer size. Wooho!! things starts to work after that. Thanks @zhaohuabing and for you support. @williamdlm if needed more details or information @shivanidwivedi10 can share the annotations we use in ingress. |
@zhaohuabing, thank you for your response. |
Hi @zhaohuabing, I noticed that the log from envoy-default-eg contains the following entry: 2024-12-09T15:34:25.723298373Z envoy {"start_time":"2024-12-09T15:34:20.610Z","method":"POST","x-envoy-origin-path":"/app1","protocol":"HTTP/1.1","response_code":"302","response_flags":"-","response_code_details":"oauth.missing_credentials","connection_termination_details":"-","upstream_transport_failure_reason":"-","bytes_received":"0","bytes_sent":"0","duration":"2","x-envoy-upstream-service-time":"-","x-forwarded-for":"10.244.0.25","user-agent":"insomnia/10.1.1","x-request-id":"2e5d7a69-27ce-4d3d-821b-57602765a2b0",":authority":"myapp.local:10080","upstream_host":"-","upstream_cluster":"httproute/default/app1-route/rule/0","upstream_local_address":"-","downstream_local_address":"127.0.0.1:10080","downstream_remote_address":"127.0.0.1:55240","requested_server_name":"-","route_name":"httproute/default/app1-route/rule/0/match/0/*"} The detail "response_code_details":"oauth.missing_credentials" caught my attention. It seems similar to issue #4718. Could you provide guidance or insights on how to resolve this? |
@williamdlm which version are you on ? can you bump to v1.2.2 |
Hello @williamdlm. |
I'm actually using version 1.2.3; however, as per your recommendation, I tried v1.2.2, but the problem persists. 2024-12-10T11:58:39.455121669Z envoy {"start_time":"2024-12-10T11:58:32.755Z","method":"POST","x-envoy-origin-path":"/app1","protocol":"HTTP/1.1","response_code":"302","response_flags":"-","response_code_details":"oauth.missing_credentials","connection_termination_details":"-","upstream_transport_failure_reason":"-","bytes_received":"0","bytes_sent":"0","duration":"0","x-envoy-upstream-service-time":"-","x-forwarded-for":"10.244.0.10","user-agent":"insomnia/10.1.1","x-request-id":"a395385d-0d90-4fa1-9e8d-2fb35a706cc6",":authority":"myapp.local:10080","upstream_host":"-","upstream_cluster":"httproute/default/app1-route/rule/0","upstream_local_address":"-","downstream_local_address":"127.0.0.1:10080","downstream_remote_address":"127.0.0.1:50008","requested_server_name":"-","route_name":"httproute/default/app1-route/rule/0/match/0/*"} |
This comment was marked as off-topic.
This comment was marked as off-topic.
@williamdlm @sachinshaji |
Hi @zhaohuabing, Thanks again for your response. I understand that this is the default behavior of Keycloak, but I would like it to use the Client Credentials Flow. When I send a request, Envoy's default behavior of redirecting to the Keycloak login screen triggers the Authorization Code Flow with User Authentication in Keycloak. Is there a configuration in Envoy to force Keycloak to use the Client Credentials Flow? What I need is for it to validate the token already sent in the request header, and if valid, redirect to the specified URL. NOTE: I believe the necessary configurations for the Client Credentials Flow are already enabled in Keycloak. |
@williamdlm the Envoy OAuth2 filter currently only supports the auth code flow. If you alreay have a token in the request header, you can use the JWT authn in the |
@zhaohuabing , Thank you for the clarification! I followed your suggestion and used the JWT authentication in the SecurityPolicy to validate the token, and it worked perfectly. Do you know if there are any plans to update the Envoy OAuth2 filter to support the Client Credentials flow in the future? |
@williamdlm |
I have a Kubernetes cluster using Envoy Gateway and I need it to always authenticate with a Keycloak instance running outside the cluster. Since it is in a development environment, it uses a self-signed certificate.
However, when I check this resource after it's created, I get the following error message:
I found a similar case reported here: #3622
Based on the suggestion in the comments here: #3622 (comment)
I tried the following:
However, the same error persists: "tls: failed to verify certificate: x509: certificate signed by unknown authority."
I need help with this, preferably with an example of the correct way to make this work.
The text was updated successfully, but these errors were encountered: