collado-mike commented on code in PR #1397: URL: https://github.com/apache/polaris/pull/1397#discussion_r2069879396
########## quarkus/service/src/main/java/org/apache/polaris/service/quarkus/auth/external/mapping/DefaultPrincipalMapper.java: ########## @@ -0,0 +1,63 @@ +/* + * 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.external.mapping; + +import static org.apache.polaris.service.quarkus.auth.external.OidcTenantResolvingAugmentor.getOidcTenantConfig; + +import io.quarkus.security.identity.SecurityIdentity; +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import java.util.Optional; +import java.util.OptionalLong; +import org.eclipse.microprofile.jwt.JsonWebToken; + +/** + * A default implementation of {@link PrincipalMapper}. It maps the {@link SecurityIdentity} to a + * Polaris principal by extracting the ID and name from the JWT claims, based on the configuration + * provided in the OIDC tenant. + */ +@ApplicationScoped +@Identifier("default") +public class DefaultPrincipalMapper implements PrincipalMapper { + + @Inject ClaimsLocator claimsLocator; Review Comment: constructor inject? ########## quarkus/service/src/main/java/org/apache/polaris/service/quarkus/auth/external/OidcTenantResolvingAugmentor.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.external; + +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.polaris.service.quarkus.auth.external.tenant.OidcTenantResolver; +import org.eclipse.microprofile.jwt.JsonWebToken; + +/** + * A {@link SecurityIdentityAugmentor} that resolves the Polaris OIDC tenant configuration for the + * given identity and adds it as an attribute to the {@link SecurityIdentity}. + */ +@ApplicationScoped +public class OidcTenantResolvingAugmentor implements SecurityIdentityAugmentor { Review Comment: I think a lot of these classes can be package private. Any reason to expose them outside of this package? ########## quarkus/service/src/main/java/org/apache/polaris/service/quarkus/auth/external/mapping/ClaimsLocator.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.external.mapping; + +import jakarta.annotation.Nullable; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.json.JsonNumber; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.eclipse.microprofile.jwt.JsonWebToken; + +/** A utility class for locating claims in a JWT token by path. */ +@ApplicationScoped +public class ClaimsLocator { Review Comment: package private? ########## quarkus/service/src/main/java/org/apache/polaris/service/quarkus/auth/ActiveRolesAugmentor.java: ########## @@ -32,33 +32,42 @@ /** * 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 { + // must run after AuthenticatingAugmentor + public static final int PRIORITY = AuthenticatingAugmentor.PRIORITY - 1; + @Inject 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); Review Comment: I wonder if the `ActiveRolesProvider` doesn't need more context about the roles the principal should have. E.g., in the external auth case, the token indicates the roles, whereas in the internal case, we have to look up grant records. How does the role provider know whether to accept the tokens contents or to validate the grants? ########## quarkus/service/src/main/java/org/apache/polaris/service/quarkus/auth/external/OidcTenantResolvingAugmentor.java: ########## @@ -0,0 +1,69 @@ +/* + * 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.external; + +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.polaris.service.quarkus.auth.external.tenant.OidcTenantResolver; +import org.eclipse.microprofile.jwt.JsonWebToken; + +/** + * A {@link SecurityIdentityAugmentor} that resolves the Polaris OIDC tenant configuration for the + * given identity and adds it as an attribute to the {@link SecurityIdentity}. + */ +@ApplicationScoped +public class OidcTenantResolvingAugmentor implements SecurityIdentityAugmentor { + + public static final String TENANT_CONFIG_ATTRIBUTE = "polaris-tenant-config"; + + // must run before PrincipalAuthInfoAugmentor + public static final int PRIORITY = PrincipalAuthInfoAugmentor.PRIORITY + 100; + + public static OidcTenantConfiguration getOidcTenantConfig(SecurityIdentity identity) { + return identity.getAttribute(TENANT_CONFIG_ATTRIBUTE); + } + + @Inject OidcTenantResolver resolver; Review Comment: Why no constructor injection? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org