Repository navigation
Require authentication on permission policies when role-based authorization is disabled - #5979
Merged
Merged
Conversation
…disabled
PermissionPolicyProvider chose between the role-checking policy and an
allow-all policy by looking only at
Authentication.RoleBasedAuthorizationEnabled. With authentication enabled
and RBAC at its default of false, every permission resolved to allow-all.
Every controller action carries a permission policy, so the
RequireAuthenticatedUser fallback policy never applied. Requests without a
token, or with an invalid or expired token, reached the controllers on the
error, audit and monitoring instances.
The provider now uses both settings:
- Authentication disabled: allow-all. RBAC is ignored.
- Authentication enabled, RBAC disabled: every permission requires an
authenticated user. This is the behavior from before role-based access
control was added.
- Authentication and RBAC enabled: unchanged.
Other changes:
- The startup log line for the authentication settings includes the RBAC
setting.
- The monitoring container health check calls the anonymous root endpoint
instead of /connection. /connection requires an authenticated user when
authentication is enabled.
Tests:
- Unit tests evaluate every permission through the real registrations, for
each combination of the two settings.
- New When_authentication_is_enabled_without_role_based_authorization
acceptance fixtures on all three instances. When RBAC was added, the
existing fixtures were switched to RBAC enabled only, which removed the
coverage for the default configuration.
- A request without a token to every route that is not [AllowAnonymous]
gets 401. This test fails without the fix.
- A valid token without roles is accepted.
- The existing When_authentication_is_enabled fixtures (RBAC enabled) also
run the every-route test.
Co-authored-by: Ramon Smits <ramon.smits@gmail.com>
dvdstelt
approved these changes
Oct 9, 2026
ramonsmits
enabled auto-merge (squash)
October 9, 2026 13:48
ramonsmits
added a commit
that referenced
this pull request
Oct 9, 2026
…disabled (#5979) (#5982) PermissionPolicyProvider chose between the role-checking policy and an allow-all policy by looking only at Authentication.RoleBasedAuthorizationEnabled. With authentication enabled and RBAC at its default of false, every permission resolved to allow-all. Every controller action carries a permission policy, so the RequireAuthenticatedUser fallback policy never applied. Requests without a token, or with an invalid or expired token, reached the controllers on the error, audit and monitoring instances. The provider now uses both settings: - Authentication disabled: allow-all. RBAC is ignored. - Authentication enabled, RBAC disabled: every permission requires an authenticated user. This is the behavior from before role-based access control was added. - Authentication and RBAC enabled: unchanged. Other changes: - The startup log line for the authentication settings includes the RBAC setting. - The monitoring container health check calls the anonymous root endpoint instead of /connection. /connection requires an authenticated user when authentication is enabled. Tests: - Unit tests evaluate every permission through the real registrations, for each combination of the two settings. - New When_authentication_is_enabled_without_role_based_authorization acceptance fixtures on all three instances. When RBAC was added, the existing fixtures were switched to RBAC enabled only, which removed the coverage for the default configuration. - A request without a token to every route that is not [AllowAnonymous] gets 401. This test fails without the fix. - A valid token without roles is accepted. - The existing When_authentication_is_enabled fixtures (RBAC enabled) also run the every-route test. (cherry picked from commit ff995c9) Co-authored-by: Dennis van der Stelt <dvdstelt@gmail.com>
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.
Fixes:
Problem
When
Authentication.EnabledistrueandAuthentication.RoleBasedAuthorizationEnabledis left at its default offalse, the error, audit and monitoring instances accept requests without a bearer token, with an invalid token or with an expired token on every action that carries a permission policy. The request runs as if a signed-in user had sent it.PermissionPolicyProviderchose between the role-checking policy and a shared allow-all policy by looking only at the RBAC setting. The allow-all policy has no authenticated-user requirement. TheRequireAuthenticatedUserfallback policy does not help, because ASP.NET Core only applies it to endpoints without authorization metadata, and every controller action carries[Authorize(Policy = ...)].Introduced in 6.18.0 by #5518. When that change broke the
Should_reject_requests_*acceptance tests, the fixtures were switched to RBAC enabled, which removed the coverage for the default configuration.Change
The provider now takes both settings into account:
Supporting changes:
/connection. The old target requires an authenticated user whenever authentication is enabled and only appeared to work because of this defect. The error and audit images already check anonymous routes.Constraints
[AllowAnonymous]routes are unaffected: the root endpoints,/api/configuration, the health endpoints and the audit-count route stay open as before.EffectivePermissionsalready reports to ServicePulse.Verification
AddServiceControlAuthenticationandAddServiceControlAuthorizationregistrations for each combination of the two settings. Against the previous provider, two of them fail, including anonymous callers being allowed every permission with authentication enabled and RBAC disabled.When_authentication_is_enabled_without_role_based_authorizationacceptance fixture on all three instances (2 tests each):[AllowAnonymous]gets 401. Against the previous provider, this test fails.When_authentication_is_enabledfixtures (RBAC enabled) also run the every-route test.