-
Notifications
You must be signed in to change notification settings - Fork 330
Support for external identity providers #1397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ quarkus.http.compress-media-types=application/json,text/html,text/plain | |
| quarkus.management.enabled=true | ||
| quarkus.micrometer.enabled=true | ||
| quarkus.micrometer.export.prometheus.enabled=true | ||
| quarkus.oidc.enabled=true | ||
| quarkus.otel.enabled=true | ||
|
|
||
| # ---- Runtime Configuration ---- | ||
|
|
@@ -74,6 +75,18 @@ quarkus.log.category."io.smallrye.config".level=INFO | |
| quarkus.management.port=8182 | ||
| quarkus.management.test-port=0 | ||
|
|
||
| # OIDC settings. These settings are required only when using external authentication providers. | ||
| # See https://quarkus.io/guides/security-oidc-configuration-properties-reference | ||
| # Default tenant (disabled by default, set this to true if you use external authentication) | ||
| quarkus.oidc.tenant-enabled=false | ||
|
||
| # quarkus.oidc.auth-server-url=https://auth.example.com/realms/polaris | ||
| # quarkus.oidc.client-id=polaris | ||
| # Roles mapping; see https://quarkus.io/guides/security-oidc-bearer-token-authentication#token-claims-and-security-identity-roles | ||
| # quarkus.oidc.roles.role-claim-path=realm/groups | ||
| # Named tenants: | ||
| # quarkus.oidc.idp1.auth-server-url=https://auth.example.com/realms/polaris2 | ||
| # quarkus.oidc.idp1.client-id=polaris2 | ||
|
|
||
| # quarkus.otel.sdk.disabled is set to `true` by default to avoid spuriour errors about | ||
| # trace collector connections being impossible to establish. This setting can be enabled | ||
| # at runtime after configuring other OTel properties for proper trace data collection. | ||
|
|
@@ -130,7 +143,14 @@ polaris.rate-limiter.token-bucket.window=PT10S | |
|
|
||
| polaris.active-roles-provider.type=default | ||
|
|
||
| # Polaris authentication settings | ||
| polaris.authentication.type=internal | ||
| polaris.authentication.authenticator.type=default | ||
| # Per-realm overrides: | ||
| # polaris.authentication.realm1.type=external | ||
| # polaris.authentication.realm1.authenticator.type=custom | ||
|
|
||
| # Options effective when using internal auth (can be overridden in per realm): | ||
| polaris.authentication.token-service.type=default | ||
| polaris.authentication.token-broker.type=rsa-key-pair | ||
| polaris.authentication.token-broker.max-token-generation=PT1H | ||
|
|
@@ -139,6 +159,27 @@ polaris.authentication.token-broker.max-token-generation=PT1H | |
| # polaris.authentication.token-broker.symmetric-key.secret=secret | ||
| # polaris.authentication.token-broker.symmetric-key.file=/tmp/symmetric.key | ||
|
|
||
| # OIDC Principals mapping | ||
| polaris.oidc.principal-mapper.type=default | ||
| # polaris.oidc.principal-mapper.id-claim-path=sub | ||
| # polaris.oidc.principal-mapper.name-claim-path=preferred_username | ||
| # Per-tenant overrides: | ||
| # polaris.oidc.idp1.principal-mapper.id-claim-path=polaris/principal_id | ||
| # polaris.oidc.idp1.principal-mapper.name-claim-path=polaris/principal_name | ||
|
|
||
| # OIDC Principal roles mapping | ||
| polaris.oidc.principal-roles-mapper.type=default | ||
| # Principal role mapping is done through quarkus.oidc.roles.role-claim-path | ||
| # The properties below define how the roles mapped by Quarkus are converted to Polaris roles | ||
| # polaris.oidc.principal-roles-mapper.filter=PRINCIPAL_ROLE:.* | ||
| # polaris.oidc.principal-roles-mapper.mappings[0].regex=PRINCIPAL_ROLE:(.*) | ||
| # polaris.oidc.principal-roles-mapper.mappings[0].replacement=PRINCIPAL_ROLE:$1 | ||
| # Per-tenant overrides: | ||
| # polaris.oidc.idp1.principal-roles-mapper.type=custom | ||
| # polaris.oidc.idp1.principal-roles-mapper.filter=POLARIS_ROLE:.* | ||
| # polaris.oidc.idp1.principal-roles-mapper.mappings[0].regex=POLARIS_ROLE:(.*) | ||
| # polaris.oidc.idp1.principal-roles-mapper.mappings[0].replacement=POLARIS_ROLE:$1 | ||
|
|
||
| # If the following properties are unset, the default credential provider chain will be used | ||
| # polaris.storage.aws.access-key=accessKey | ||
| # polaris.storage.aws.secret-key=secretKey | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,33 +32,47 @@ | |
|
|
||
| /** | ||
| * A custom {@link SecurityIdentityAugmentor} that adds active roles to the {@link | ||
| * SecurityIdentity}. This is used to augment the identity with active roles after authentication. | ||
| * SecurityIdentity}. This is used to augment the identity with valid active roles after | ||
| * authentication. | ||
| */ | ||
| @ApplicationScoped | ||
| public class ActiveRolesAugmentor implements SecurityIdentityAugmentor { | ||
|
|
||
| @Inject ActiveRolesProvider activeRolesProvider; | ||
| // must run after AuthenticatingAugmentor | ||
| public static final int PRIORITY = AuthenticatingAugmentor.PRIORITY - 1; | ||
|
|
||
| private final ActiveRolesProvider activeRolesProvider; | ||
|
|
||
| @Inject | ||
| public ActiveRolesAugmentor(ActiveRolesProvider activeRolesProvider) { | ||
| this.activeRolesProvider = activeRolesProvider; | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return PRIORITY; | ||
| } | ||
|
|
||
| @Override | ||
| public Uni<SecurityIdentity> augment( | ||
| SecurityIdentity identity, AuthenticationRequestContext context) { | ||
| if (identity.isAnonymous()) { | ||
| return Uni.createFrom().item(identity); | ||
| } | ||
| return context.runBlocking(() -> augmentWithActiveRoles(identity)); | ||
| return context.runBlocking(() -> validateActiveRoles(identity)); | ||
| } | ||
|
|
||
| private SecurityIdentity augmentWithActiveRoles(SecurityIdentity identity) { | ||
| AuthenticatedPolarisPrincipal polarisPrincipal = | ||
| identity.getPrincipal(AuthenticatedPolarisPrincipal.class); | ||
| if (polarisPrincipal == null) { | ||
| private SecurityIdentity validateActiveRoles(SecurityIdentity identity) { | ||
| if (!(identity.getPrincipal() instanceof AuthenticatedPolarisPrincipal)) { | ||
| throw new AuthenticationFailedException("No Polaris principal found"); | ||
| } | ||
| AuthenticatedPolarisPrincipal polarisPrincipal = | ||
| identity.getPrincipal(AuthenticatedPolarisPrincipal.class); | ||
| Set<String> validRoleNames = activeRolesProvider.getActiveRoles(polarisPrincipal); | ||
|
Comment on lines
+69
to
71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a very good question. You'll notice that for now only one impl of When we have federated principals, my suggestion would be to change this Augmentor by either:
My preference would be for 2, but in any case, my intention was to tackle that once we have federated principals. Wdyt? Does this plan work for you?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need a more robust story around roles mapping. For now, most of the work is done by
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferring this improvement makes sense to me. Also +1 to option 2 above.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This plan sounds ok to me. Using the different |
||
| return QuarkusSecurityIdentity.builder() | ||
| .setAnonymous(false) | ||
| .setPrincipal(polarisPrincipal) | ||
| .addRoles(validRoleNames) | ||
| .addRoles(validRoleNames) // replace the current roles with valid ones | ||
| .addCredentials(identity.getCredentials()) | ||
| .addAttributes(identity.getAttributes()) | ||
| .addPermissionChecker(identity::checkPermission) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.service.quarkus.auth; | ||
|
|
||
| import io.quarkus.security.AuthenticationFailedException; | ||
| import io.quarkus.security.identity.AuthenticationRequestContext; | ||
| import io.quarkus.security.identity.SecurityIdentity; | ||
| import io.quarkus.security.identity.SecurityIdentityAugmentor; | ||
| import io.quarkus.security.runtime.QuarkusSecurityIdentity; | ||
| import io.smallrye.mutiny.Uni; | ||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.inject.Inject; | ||
| import org.apache.iceberg.exceptions.NotAuthorizedException; | ||
| import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; | ||
| import org.apache.polaris.service.auth.Authenticator; | ||
| import org.apache.polaris.service.auth.PrincipalAuthInfo; | ||
|
|
||
| /** | ||
| * A custom {@link SecurityIdentityAugmentor} that, after Quarkus OIDC or Internal Auth extracted | ||
| * and validated the principal credentials, augments the {@link SecurityIdentity} by authenticating | ||
| * the principal and setting an {@link AuthenticatedPolarisPrincipal} as the identity's principal. | ||
| */ | ||
| @ApplicationScoped | ||
| public class AuthenticatingAugmentor implements SecurityIdentityAugmentor { | ||
|
|
||
| public static final int PRIORITY = 1000; | ||
|
|
||
| private final Authenticator<PrincipalAuthInfo, AuthenticatedPolarisPrincipal> authenticator; | ||
|
|
||
| @Inject | ||
| public AuthenticatingAugmentor( | ||
| Authenticator<PrincipalAuthInfo, AuthenticatedPolarisPrincipal> authenticator) { | ||
| this.authenticator = authenticator; | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return PRIORITY; | ||
| } | ||
|
|
||
| @Override | ||
| public Uni<SecurityIdentity> augment( | ||
| SecurityIdentity identity, AuthenticationRequestContext context) { | ||
| if (identity.isAnonymous()) { | ||
| return Uni.createFrom().item(identity); | ||
| } | ||
| PrincipalAuthInfo authInfo = extractPrincipalAuthInfo(identity); | ||
| return context.runBlocking(() -> authenticatePolarisPrincipal(identity, authInfo)); | ||
| } | ||
|
|
||
| private PrincipalAuthInfo extractPrincipalAuthInfo(SecurityIdentity identity) { | ||
| QuarkusPrincipalAuthInfo credential = identity.getCredential(QuarkusPrincipalAuthInfo.class); | ||
| if (credential == null) { | ||
| throw new AuthenticationFailedException("No token credential available"); | ||
| } | ||
| return credential; | ||
| } | ||
|
|
||
| private SecurityIdentity authenticatePolarisPrincipal( | ||
| SecurityIdentity identity, PrincipalAuthInfo authInfo) { | ||
| try { | ||
| AuthenticatedPolarisPrincipal polarisPrincipal = | ||
| authenticator | ||
| .authenticate(authInfo) | ||
| .orElseThrow(() -> new NotAuthorizedException("Authentication failed")); | ||
| return QuarkusSecurityIdentity.builder(identity).setPrincipal(polarisPrincipal).build(); | ||
| } catch (RuntimeException e) { | ||
| throw new AuthenticationFailedException(e); | ||
| } | ||
| } | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to document things as I go. This is the best knowledge I can get for this principal attribute.