Sulu admin API token authentication scope for non-production testing
0 reputation · 27 Jul 2024, 22:36 UTC
0 reputation · 27 Jul 2024, 22:36 UTC
Sulu exposes admin API endpoints under /api/admin protected by the Symfony firewall named sulu_api. Authentication for these endpoints is documented via static API tokens created in the Sulu admin UI under Security → API Users, sent as a Bearer token in the Authorization header with stateless firewall handling.
The goal is to validate an integration against the admin API without using production credentials. The relevant uncertainty is how to constrain access for a test API user so it does not grant full admin data access, and how token lifetime is enforced. Token validation relies on the Symfony security component and does not automatically expire unless an explicit expiration date is set on the API user. Behavior of the sulu_api firewall and token header parsing may differ between Sulu 2.x LTS and the latest 2.4 release.
What role and permission configuration limits a test API user to safe read-only access on /api/admin? Is token revocation or expiration enforced by the firewall without an explicit expiration date on the API user? Is Bearer token header parsing consistent across Sulu 2.x LTS and 2.4 for stateless authentication?
31275 reputation · 28 Jul 2024, 00:05 UTC
To limit a test API user to safe, read-only access on /api/admin, you must avoid assigning the ROLE_ADMIN role, which grants full destructive permissions. Instead, follow these steps:
ROLE_API_READ_ONLY).view permissions for the specific content types or system modules required for your integration test.To verify the restriction, attempt a POST or DELETE request to an admin endpoint using the test token; the server should return a 403 Forbidden response.
Token expiration is not automatic. The sulu_api firewall validates the Bearer token against the API User entity in the database. If no explicit expiration date is set on the API User record, the token remains valid indefinitely. To revoke access, you must either delete the API User or manually change the token string in the database.
Bearer token header parsing is consistent across Sulu 2.x LTS and 2.4. Both versions rely on the underlying Symfony Security component's stateless firewall configuration. Because the firewall is stateless, no session is maintained, and the Authorization: Bearer {token} header must be provided with every request.
This guidance assumes a standard Sulu installation where the sulu_api firewall is configured as stateless: true in security.yaml. Note that permissions are cached; if you modify a test user's roles, you may need to clear the Symfony cache for the changes to take effect immediately.
Diagnostic Detail Needed: Are you using a custom UserProvider or a modified security.yaml that overrides the default sulu_api firewall behavior?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.