authz-keycloak and mTLS does not work #11538
Replies: 2 comments 1 reply
-
@michalspondr Zdravím! Jsem tady, abych ti pomohl s tvým problémem. Jsem bot, který ti může pomoci s opravou chyb, odpovědět na otázky a stát se přispěvatelem. I found a similar open issue that might be relevant to your problem: authz-keycloak plugin keeps answering invalid_grant/Invalid bearer token. The suggested solution is to double-check if your request's grant type is valid [1]. Additionally, there is a closed issue that might provide some insights: bug: apisix failed to verify the validity of the server certificate. One of the solutions mentioned is to enable the Given your setup, here are a few things you might want to check:
You can try adding the apisix:
ssl:
enable: true
listen_port: 9443
ssl_trusted_certificate: /usr/local/apisix/conf/cert/rootCA.pem
cert: /usr/local/apisix/conf/cert/apisix.crt
key: /usr/local/apisix/conf/cert/apisix.key
proxy_ssl_verify: true If the issue persists, you might want to review the Keycloak and APISIX logs for more detailed error messages that could provide further clues. |
Beta Was this translation helpful? Give feedback.
-
Response from APISIX Slack: |
Beta Was this translation helpful? Give feedback.
-
I want to have mTLS between APISIX 3.9.1 and Keycloak 25.0.4. Keycloak mTLS is configured correctly, communication works between curl and Keycloak. I assume certificates are also created correctly, because mTLS works between different client and Keycloak using same certificates. Both APISIX and Keycloak run as Docker containers. /etc/hosts contains adp and keycloak domains set to 127.0.0.1, also all possible way of alternative domain names are added to certificate as extension. APISIX is run in a standalone mode, thus admin API is not used, I use fixed configuration:
In route definitions I use authz-keycloak plugin (note https://keycloak is used):
cert and key have same content as /usr/local/apisix/conf/cert/apisix.crt and /usr/local/apisix/conf/cert/apisix.key (I was not able to use the files directly, that's why I hardcoded the certificates).
Now I am able to get access token from Keycloak:
curl --cert apisix.crt --key apisix.key --cacert rootCA.pem -d "client_id=myclient" -d "client_secret=$SECRET" -d "grant_type=client_credentials" https://keycloak:8443/realms/myrealm/protocol/openid-connect/token
But I use this access token like this:
curl --cert client.crt --key client.key --cacert rootCA.pem https://adp:9443/api/status -H "Authorization: Bearer $ACCESS_TOKEN"
I get this error in APISIS log:
I am able to call Keycloak API using mTLS from APISIX Docker container itself, but the APISIX application itself can not do it.
Any idea where is my configuration wrong? If Keycloak KC_HTTPS_CLIENT_AUTH parameter is set to request instead of required, then TLS is used correctly. Also without the authz-keycloak it works obviously, but then there is no OAuth involved.
Thank you for any hints.
Beta Was this translation helpful? Give feedback.
All reactions