Repository navigation
Narrow admin roles (ROLE_CMS_ADMIN, ROLE_USER_ADMIN) and additive http_cache lists - #611
Merged
Merged
Conversation
ROLE_CMS_ADMIN replaces ROLE_ADMIN in every bundle check, ROLE_USER_ADMIN replaces ROLE_SUPER_ADMIN for user management, with an escalation guard; the bundle merges its role hierarchy into the application's. The http_cache class lists always keep the CWA defaults, and normalizing a user no longer writes its reachable roles onto the entity.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #611 +/- ##
============================================
+ Coverage 97.18% 97.19% +0.01%
- Complexity 5475 5513 +38
============================================
Files 451 455 +4
Lines 14103 14174 +71
============================================
+ Hits 13706 13777 +71
Misses 397 397
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Narrows the admin roles and adds the extension points the module's e-commerce design needs. Breaking.
Admin roles
The bundle adds this hierarchy to
security.role_hierarchy(Security\AdminRoles::HIERARCHY):role_hierarchyprototype hasperformNoDeepMerging(), so a prependedROLE_ADMIN: [ROLE_CMS_ADMIN]is replaced by the site'sROLE_ADMIN: ROLE_USER.AdminRoleHierarchyCompilerPassTestpins that. The bundle still prepends the hierarchy, so that one is always configured (with none configured, SecurityBundle removes the hierarchy voter). ThenAdminRoleHierarchyCompilerPassadds the bundle's roles into the finalsecurity.role_hierarchy.rolesparameter, keeping every role the site or another bundle already lists for that key.ROLE_ADMIN: ROLE_USERwritten as a scalar (as in the template and the test app), ROLE_ADMIN reaches both ROLE_CMS_ADMIN and ROLE_USER, and neither entry hides the other. Pinned inAdminRoleHierarchyCompilerPassTest::test_a_site_role_admin_given_as_a_scalar_keeps_its_role_and_gains_the_cms_admin_role, and on the booted test app inSecurity\AdminRolesTest. A site role added under ROLE_ADMIN (e.g.ROLE_SHOP_ACCOUNTS) is reachable alongside ROLE_CMS_ADMIN.ROLE_ADMINcheck is nowROLE_CMS_ADMIN: content writes and publishing,Route.liveAt,isReachableWithoutRoute, collaboration state, realtime, component usage, the orphan reports and deletions, and both purge endpoints. Existing ROLE_ADMIN and ROLE_SUPER_ADMIN users keep exactly their access: every existing admin test passes unchanged. The only exception is twoUserPutTestassertions on the outputroles, which now also list ROLE_CMS_ADMIN.Security\AdminRolesTestshows that a user with only ROLE_CMS_ADMIN can use each area and a user with only ROLE_USER_ADMIN gets a 403.user:create --adminstill creates a ROLE_ADMIN user, and--super-adminstill creates a ROLE_SUPER_ADMIN user. Both are unchanged.Config defaults now
is_granted('ROLE_CMS_ADMIN')(the template can drop its copies)publishable.permissionnow defaults tois_granted('ROLE_CMS_ADMIN'). It keepscannotBeEmpty(), and thepublishablenode is no longerisRequired(), which avoids theuser.email_verificationrequired config children are never enforced #214 trap.routable_securitynow defaults tois_granted('ROLE_CMS_ADMIN').nullmeans no check at all:RoutableVoter,RoutableExtensionandComponentVotergrant every reader a page or page data that no live route reaches. That contradicts the reachability rule.nullstill switches it off.User management: ROLE_USER_ADMIN
User:superAdmingroup.UserContextBuildernow adds it for ROLE_USER_ADMIN.UserResourceMetadataCollectionFactorysets the security of everyAbstractUseroperation:GetCollectionandPost:is_granted('ROLE_USER_ADMIN')Get: that, or(user and object.getId() == user.getId())PatchandPut:(is_granted('ROLE_USER_ADMIN') and is_granted('manage_user', object)), or the user themselvesDelete: the first part only/mekeepsIS_AUTHENTICATED_FULLY.ContentWriteSecurityResourceMetadataCollectionFactoryprecedent. An operation's ownsecuritybecomes(<bundle>) and (<own>). The opt-out isextraProperties: ['user_admin_security' => false](UserResourceMetadataCollectionFactory::OPT_OUT_EXTRA_PROPERTY). Pinned inUserResourceMetadataCollectionFactoryTest.App\Entity\Userchecks are not merely redundant. Itsis_granted('ROLE_SUPER_ADMIN')ANDed with the bundle's check would lock out a user admin. Remove thesecurity:from all five operations, as this PR does for the test app'sUser.Escalation guard
UserManagementVoter(manage_user) grants only when the caller reaches every role the target reaches. A ROLE_USER_ADMIN therefore gets a 403 when they edit, PUT, change the roles of or delete a CMS admin, an admin or a super admin. A role outside the hierarchy also outranks them.#[AssignableRoles]onAbstractUseris a class constraint inDefault. Any added role that the token user does not reach is a 422 onroles. Added means new compared with the unit of work's original roles, or every role of a new user.rolesat all (onlyUser:superAdmincan write it), so a PATCH of their own roles is ignored. A user admin raising their own roles gets a 422.User\UserAdminTest./mereachable rolesUserNormalizerno longer callssetRoles()on the entity, which broke #389's rule. It now writes the reachable roles into the normalizedrolesonly.MeTestpins that/melists every reachable role, and that a flush after normalization stores only the original roles.Extension points
cacheHeaders: ['public' => false, 'no_store' => true], respondsprivate, no-storewith nos-maxage. This uses a newDummyVisitorDependentResourcein the test app, and is inHttpCache\ExtensionResourceCacheTest.http_cacheclass lists are additive.personalised_resource_classes,scheduled_expiry_resource_classesandpurge_rendered_html_classesalways keep the CWA defaults (Configuration::*_CLASSES, re-added byvalidate()->always()). Configured or prepended classes are added to them, and theinfotext says so.ConfigurationTestpins it with a second bundle's prepended config.DummyResourceWithFilters) purges its IRI.Items 1 and 3 already worked and are now pinned. CLAUDE.md gets the admin roles entries, an "Extending CWA" section, the singleflight note on
markNeverStored(), and the ROLE_CMS_ADMIN renames.Not covered by the design, decided here
ComponentPositionadmin groups.ComponentPosition:read:role_admin(pageDataProperty,pageDataClass) is now…:role_cms_admin. These groups are built from reachable roles, so ROLE_ADMIN still gets them.Route:cwa_resource:read:ROLE_ADMINis now…:role_cms_admin. No context builder ever adds a group forRoute, and Route operations set nogroups, so the group never had any effect.associatedResourcesis serialized for every caller today. That is unchanged here and may be worth a look.AuthenticationTrait::loginWithRoles()is tested inAuthenticationTraitTest.Local runs
vendor/bin/paratest -p8: 6265 tests green.API_PLATFORM_USE_SYMFONY_LISTENERS=1: green.php-cs-fixerandphpstan: clean.🤖 Generated with Claude Code