Hi folks,
Following an informal "Polaris users discussion" I had last week in France,
a couple of users shared a common use case that we currently do not support.
Let me share the context :)
With credential-mode=external, a principal is authenticated entirely from
its token: it doesn't need to exist in Polaris, so there's nothing to sync
from the IdP. But its roles are taken verbatim from the token and have no
grants in the metastore. So this mode requires an external authorizer (OPA,
Ranger), and startup is refused with the default authorizer.
The users have asked for a middle ground. The IdP stays the source of truth
for users and their group or role membership. But they want Polaris RBAC
(principal roles, catalog roles and grants, managed with the Management
API) to remain the source of truth for authorization, without deploying an
external authorizer.
Today, the only way to get that is internal credential mode. There, every
principal and every principal-role assignment must exist in Polaris, and
the token can only activate roles that are already granted. In practice,
that means syncing users and group membership from the IdP. This is a bit
similar to the use case discussed in #441 ("Federated Users and Federated
Roles").
I would like to propose a third credential mode:
polaris.authentication.credential-mode=external-with-internal-roles
In this mode:
- As with external principals, the caller is authenticated from the token
only. There is no principal lookup, and principals are never created in
Polaris.
- The roles emitted by the role mapper name principal roles managed in
Polaris, using the usual PRINCIPAL_ROLE:<name> convention. Each existing
principal role is activated, along with the catalog roles granted to it.
Roles that don't exist in Polaris are ignored.
- Role membership comes from the token. Principal roles are never assigned
to external principals in Polaris.
- The default authorizer works. As with external principals, the
authentication type must not be internal.
- PRINCIPAL_ROLE:ALL is rejected (401), since an external principal has no
grants to expand.
- In mixed authentication, tokens issued by Polaris itself still resolve to
internal principals, as today.
Here's an example: the IdP group "polaris_analyst" maps to the Polaris
principal role "analyst":
polaris.authentication.type=external
polaris.authentication.credential-mode=external-with-internal-roles
polaris.oidc.principal-mapper.name-claim-path=preferred_username
quarkus.oidc.roles.role-claim-path=groups
polaris.oidc.principal-roles-mapper.filter=polaris_.*
polaris.oidc.principal-roles-mapper.mappings[0].regex=polaris_(.*)
polaris.oidc.principal-roles-mapper.mappings[0].replacement=PRINCIPAL_ROLE:$1
Administrators are simply users whose roles map to the service_admin
principal role created at bootstrap.
I created a draft PR to illustrate the impl:
https://github.com/apache/polaris/pull/6066
The change is small and doesn't touch the PolarisAuthorizer SPI or
PolarisCredential. It adds a new CredentialMode value and a new
INTERNAL_PRINCIPAL_ROLES attribute key in PolarisPrincipalAttributes. With
that attribute set, the Resolver loads an external principal's roles by
name from the metastore, with their grants, instead of creating stand-in
roles, so the default authorizer works unchanged.
Since an external principal's name is asserted by the IdP, the PR also
makes sure an external principal is never treated as the root principal,
whatever its name. The details are in the PR description.
I have a few open questions for you:
1. Naming and config shape: a third credential-mode value (as I propose in
the PR) or a separate option, e.g.
polaris.authentication.external-principal-roles=internal|external?
2. Unknown roles: should roles that don't exist in Polaris be ignored (my
current proposal which tolerates unrelated IdP groups) or rejected?
3. PRINCIPAL_ROLE:ALL: reject (my current proposal) or ignore?
4. #5439 plans to remove the stand-in principal and roles from the
Resolver. This mode still needs a caller principal, because the default
authorizer calls resolveAll(). I think the two are compatible, but it
should be taken into account there.
5. Trust model: the IdP decides who holds which principal role, including
service_admin. That is inherent to the feature and documented, with a
recommendation to restrict roles using the role mapper filter. I'm
interested in other suggestions.
Thoughts? Feedback is welcome on this thread or the PR.
Thanks!
Regards
JB