Repository navigation
feat: manage permissions and organization roles from the CLI - #356
Merged
Merged
Conversation
…ions and seamless roles Wraps the auth API v0.23 permission catalogue, organization role catalogue and role to permission mappings. roles set replaces a role's whole mapping and asks before taking a permission away. An instance before v0.23 answers with a message naming the release it needs. Part of #343
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.
Needs auth API v0.23. Every command here calls routes that first ship in
seamless-auth-apiv0.23.0, which is not released yet. Against v0.22 and earlier each command exits 1 with "This instance has no permission catalogue. Permissions and organization roles need Seamless Auth API v0.23 or later." Merge before or after the API release; publishing the CLI first is safe for that reason.Part of #343 (roles and permissions; webhooks and hooks are still open there).
What
Two new instance-management commands, both with
--json:Routes:
GET/POST /admin/permissions,PATCH/DELETE /admin/permissions/:permissionName,GET /admin/roles,PUT /admin/roles/:kind/:roleName/permissions,POST /admin/organization-roles,PATCH/DELETE /admin/organization-roles/:roleName.How
src/core/admin.ts, next to the other admin wrappers. They usecall(), so writes get the existing step-up retry and a 403 still goes throughforbidden(). Responses are parsed with loosened@seamless-auth/types0.38.0schemas/permissionschemas.{ "error": "Not Found" }. A missing permission or role on v0.23 is also a 404, but it names what was missing (Permission not found,Role not found). Collection routes treat any 404 as a missing route; per-name routes look at the body.roles setreplaces the whole mapping, like the API. It reads the current mapping first and asks before taking a permission away (non-interactive runs need--force). Adding permissions does not ask.detailson a 400 or 409 are added to the error message, for exampleCould not delete permission invoices:write (409: Permission is still granted by a role), roles: organization role billing.PermissionNameSchemabefore the request, with a readable message instead of the raw regex.fail,positionalsandvalidateare moved intoadminShared.tsfor the new commands.resources.tskeeps its own copies for now.seamless help permissions,seamless help roles), README, the AGENTS.md command list, and a minor changeset are included. No config keys changed, soWRITABLE_KEYSis untouched.Verification
npm run coverage(the pre-commit hook): 1994 passed, 28 skipped. Lines 99.24%, branches 96.54%, above the floor.npm run buildpasses.seamless-auth-apiorigin/main(bed4994), built into an image and run with itsdocker-compose.yml. I registered an owner, enrolled TOTP, signed in with the CLI's owncompleteLogin, then ran the realrunPermissionsandrunRoles. Every write needed a step-up throughSEAMLESS_TOTP_CODEand passed. Checked: create, the duplicate 409, update and its 404, list, organization role create,roles seton both kinds, an unknown role 404, an unknown permission 400, delete refused while a role grants it (names the role), the built-in role refusal, delete, and--jsonoutput.ghcr.io/fells-code/seamless-auth-api:v0.22.0: all nine subcommands exit 1 with the v0.23 message above.Not covered: there is no committed e2e test for these commands. The live run was a one-off harness, because the admin and TOTP bootstrap it needs is not in the repo's gated e2e.