Repository navigation
[fix][broker] Check the original principal of proxied HTTP requests with its own authentication data - #26748
Merged
Conversation
…ith its own authentication data For proxied HTTP requests, the broker checked the original principal with the request authentication data, which is authenticated as the proxy. Providers that resolve roles from the authentication data, such as MultiRolesTokenAuthorizationProvider, then evaluated the original principal with the roles of the proxy token. - AuthorizationService: check the original principal of proxied requests with AuthenticationDataForwarded, keeping the subscription, for super user, tenant, namespace, namespace and topic policy, topic, broker, cluster, and function, source and sink checks. Add isSuperUserOrTenantAdmin, which uses the provider's own admin checks and also recognizes a tenant admin role when the request carries no token. - AuthenticationDataForwarded: add ofProxiedRequest and getProxiedRequestData. - MultiRolesTokenAuthorizationProvider: for the original principal of a proxied request, use the roles of a token in the request only when it authenticates as the original principal. - PulsarWebResource: the super user check uses the original principal's own authentication data, and for proxied requests needing tenant admin access both the proxy role and the original principal must each be a super user or a tenant admin. Assisted-by: Claude Code
lhotari
requested review from
Technoboy-,
dao-jun,
david-streamlio,
merlimat and
nodece
September 29, 2026 17:09
merlimat
approved these changes
Sep 29, 2026
2 of 3 tasks
ascentstream-bot
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Oct 1, 2026
…ith its own authentication data (apache#26748) (cherry picked from commit f0c9094)
ascentstream-bot
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Oct 2, 2026
…ith its own authentication data (apache#26748) (cherry picked from commit f0c9094)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
For requests that come through a proxy, the broker authorizes both the proxy role and the original principal. On the binary protocol,
ServerCnxchecks the original principal withAuthenticationDataForwardedwhen the proxy does not forward the client's credentials. On HTTP,AuthorizationServiceandPulsarWebResourcechecked the original principal with the request's authentication data, which is authenticated as the proxy. Authorization providers that resolve roles from the authentication data, such asMultiRolesTokenAuthorizationProvider, then evaluated the original principal with the roles of the proxy's token.The tenant admin check for proxied requests (
validateAdminAccessForTenantAsync) also had two inconsistencies. When the proxy role itself was a tenant admin, the original principal was not checked. When it was not, both roles had to be super users, so a tenant admin could not use a super-user proxy.Modifications
AuthorizationService:AuthenticationDataForwardedinstead of the request's authentication data, and a subscription set on the request data is kept. This applies to super user, tenant, namespace, namespace and topic policy, topic, broker, cluster, and function, source and sink checks. The proxy role is still checked with the request's authentication data.isSuperUserOrTenantAdmin(tenant, role, authData), which recognizes super users and tenant admins with the provider's own checks:validateTenantAdminAccessforPulsarAuthorizationProviderand its subclasses (which includes the additional roles of multi-role tokens), otherwise the provider'sisSuperUserandisTenantAdmin. ForPulsarAuthorizationProviderit also checksisTenantAdminfor the role itself, so a tenant admin whose request carries no token, such as a TLS-authenticated proxy, is still recognized.PulsarWebResource:originalPrincipalAuthData()).AuthorizationService#isSuperUserOrTenantAdmin. The original principal is checked with its own authentication data.AuthenticationDataForwarded: addofProxiedRequest(AuthenticationDataSource)andgetProxiedRequestData(), so a provider can look at the proxied request without treating it as authenticated for the original principal.AuthenticationDataForwarded.INSTANCEis unchanged.MultiRolesTokenAuthorizationProvider: for the original principal of a proxied request, the roles of a token in the request are used only when that token is valid and authenticates as the original principal. For example, a client token forwarded by a TLS-authenticated proxy. Otherwise only the original principal's own role is used.PulsarAuthorizationProviderresolves roles as before.Verifying this change
This change added tests and can be verified as follows:
AuthorizationServiceTest#testOriginalPrincipalIsCheckedWithoutProxyAuthData: the original principal is checked withAuthenticationDataForwarded(keeping the subscription) for topic, namespace, policy, tenant, broker, cluster, super user and function, source and sink checks, and the proxy role with the request data.AuthorizationServiceTest#testIsSuperUserOrTenantAdminUsesProviderAdminChecks:isSuperUserOrTenantAdminrecognizes super users and tenant admins, and not roles that are only allowed tenant operations.MultiRolesTokenAuthorizationProviderTest#testProxiedHttpRequestUsesOnlyTheOriginalPrincipalToken(broker-common): only a valid token of the original principal adds roles; the proxy's token, another principal's token and an invalid token of the original principal add none.MultiRolesTokenAuthorizationProviderTest#testTenantAdminRoleWithoutTokenIsRecognized(broker-common): a tenant admin role is recognized when the request carries no token.MultiRolesTokenTlsProxyHttpTest(broker): for a proxy that authenticates with a TLS client certificate and forwards the client's headers, a forwarded token of the original principal adds its roles, a missing token or another subject's token adds none, and a tenant-admin proxy with no token can serve a tenant admin but not an ordinary original principal.MultiRolesTokenAuthorizationProviderTest#testProxiedRequestsCheckOriginalPrincipalWithItsOwnRole(broker): through a proxy whose token carries additional roles, an ordinary original principal does not get those roles for super user, topic, namespace and tenant admin operations, while a proxy forwarding a super user or a tenant admin keeps working.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Public API:
AuthenticationDataForwardedgainsofProxiedRequest(AuthenticationDataSource)andgetProxiedRequestData(), andAuthorizationServicegainsisSuperUserOrTenantAdmin(String, String, AuthenticationDataSource). Custom authorization providers now receiveAuthenticationDataForwardedfor the original principal of proxied HTTP requests, as they already do on the binary protocol.