Skip to content
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

Disable Keycloak Authorization TLS checks if required #12445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/src/main/asciidoc/security-keycloak-authorization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ In other words, instead of explicitly enforcing access based on some specific ac

By externalizing authorization from your application, you are allowed to protect your applications using different access control mechanisms as well as avoid re-deploying your application every time your security requirements change, where Keycloak will be acting as a centralized authorization service from where your protected resources and their associated permissions are managed.

See the link:security-openid-connect[Using OpenID Connect to Protect Service Applications] guide for more information about `Bearer Token` authentication mechanism.

If you are already familiar with Keycloak, you’ll notice that the extension is basically another adapter implementation but specific for Quarkus applications.
Otherwise, you can find more information in the Keycloak https://www.keycloak.org/docs/latest/authorization_services/index.html#_enforcer_overview[documentation].
Expand Down Expand Up @@ -180,9 +182,10 @@ The OpenID Connect extension allows you to define the adapter configuration usin
[source,properties]
----
# OIDC Configuration
quarkus.oidc.auth-server-url=http://localhost:8180/auth/realms/quarkus
quarkus.oidc.auth-server-url=https://localhost:8543/auth/realms/quarkus
quarkus.oidc.client-id=backend-service
quarkus.oidc.credentials.secret=secret
quarkus.oidc.tls.verification=none
# Enable Policy Enforcement
quarkus.keycloak.policy-enforcer.enable=true
Expand All @@ -196,10 +199,10 @@ To start a Keycloak Server you can use Docker and just run the following command
[source,bash,subs=attributes+]
----
docker run --name keycloak -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -p 8180:8080 {keycloak-docker-image}
docker run --name keycloak -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -p 8180:8080 -p 8543:8443 {keycloak-docker-image}
----
You should be able to access your Keycloak Server at http://localhost:8180/auth[localhost:8180/auth].
You should be able to access your Keycloak Server at http://localhost:8180/auth[localhost:8180/auth] or https://localhost:8543/auth[localhost:8543/auth].
Log in as the `admin` user to access the Keycloak Administration Console.
Username should be `admin` and password `admin`.
Expand Down Expand Up @@ -258,7 +261,7 @@ The application is using bearer token authorization and the first thing to do is
[source,bash]
----
export access_token=$(\
curl -X POST http://localhost:8180/auth/realms/quarkus/protocol/openid-connect/token \
curl --insecure -X POST https://localhost:8543/auth/realms/quarkus/protocol/openid-connect/token \
--user backend-service:secret \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'username=alice&password=alice&grant_type=password' | jq --raw-output '.access_token' \
Expand Down Expand Up @@ -293,7 +296,7 @@ In order to access the admin endpoint you should obtain a token for the `admin`
[source,bash]
----
export access_token=$(\
curl -X POST http://localhost:8180/auth/realms/quarkus/protocol/openid-connect/token \
curl --insecure -X POST https://localhost:8543/auth/realms/quarkus/protocol/openid-connect/token \
--user backend-service:secret \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'username=admin&password=admin&grant_type=password' | jq --raw-output '.access_token' \
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/asciidoc/security-openid-connect.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Bearer Token Authorization is the process of authorizing HTTP requests based on

Please read the link:security-openid-connect-web-authentication[Using OpenID Connect to Protect Web Applications] guide if you need to authenticate and authorize the users using OpenId Connect Authorization Code Flow.

If you use Keycloak and Bearer tokens then also see the link:security-keycloak-authorization[Using Keycloak to Centralize Authorization] guide.

Please read the link:security-openid-connect-multitenancy[Using OpenID Connect Multi-Tenancy] guide how to support multiple tenants.

== Prerequisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.keycloak.representations.adapters.config.PolicyEnforcerConfig;

import io.quarkus.oidc.OidcTenantConfig;
import io.quarkus.oidc.OidcTenantConfig.Tls.Verification;
import io.quarkus.oidc.runtime.OidcConfig;
import io.quarkus.security.identity.SecurityIdentity;
import io.quarkus.security.runtime.QuarkusSecurityIdentity;
Expand Down Expand Up @@ -103,6 +104,11 @@ public void init(OidcConfig oidcConfig, KeycloakPolicyEnforcerConfig config, Htt
adapterConfig.setResource(oidcConfig.defaultTenant.getClientId().get());
adapterConfig.setCredentials(getCredentials(oidcConfig.defaultTenant));

if (oidcConfig.defaultTenant.tls.getVerification() == Verification.NONE) {
adapterConfig.setDisableTrustManager(true);
adapterConfig.setAllowAnyHostname(true);
}

PolicyEnforcerConfig enforcerConfig = getPolicyEnforcerConfig(config, adapterConfig);

if (enforcerConfig == null) {
Expand Down