Repository navigation
Add app requests - #748
Add app requests#748Jeff-Rowell wants to merge 26 commits into
Conversation
Users and service principals can request a new app with its owners, tags, and initial app groups, each group naming its own owners and members. Access admins approve them, or a conditional-access plugin through the new app_request_created hook. Approval creates the app as a direct create would and grants each named owner and member, with separate owner and member end dates that a plugin or approver may shorten. A service principal's request must name an owner, and the app records the service principal that requested it. Requests route to Access admins through new app request notification hooks.
A dialog to request an app with its owners, tags, and initial app groups, a list of app requests, and a review page where Access admins approve or reject a request and may shorten its end dates, and requesters may withdraw their own. Linked from the nav and, for non-admins, the Apps list.
- The approver's end dates replace the requested ones (null is indefinite), plugin end dates only shorten, and the recorded end dates are the tag-capped ones the grants actually got. - A request without members has no membership window. - Tags that require a reason now require the request to give one. - Groups an approved service principal request creates, including the owners group, record the service principal; groups absorbed by the new app do not. - Initial app group names follow the group name pattern and length. - A service principal's withdrawal is recorded in resolver_service_principal_id, and deleting the service principal rejects its pending app requests. - The operation takes typed AppRequestGroup entries, the router uses the shared request helpers, and conditional-access dispatch reads the request's status from the database, since creating an app can expunge the session and leave a stale instance behind.
…pals Approval end dates offer every duration the tag limits allow and send an explicit null for Indefinite over a requested end date, using a resolvedEndingAt helper shared with the group request review page. The detail page lists the named owners, counts named users or roles no longer active, and disables Approve with a warning when any remain. A service principal that withdrew its own request is shown as the resolver. Assigned to Me is shown only to Access admins, and Request an App is shown to everyone on the Apps list.
- A retry is validated before it replaces the requester's pending request, so a bad resubmission leaves the pending one in place. - The approver's end dates apply to that approval only, instead of being saved onto the request before it runs. - Named users and roles that are no longer active are skipped at approval and listed in the resolution reason, so a departed member doesn't make the request impossible to approve; at least one app owner must remain. - Each grant is carried out on its own after the app is created; a failed one is logged and named in the resolution reason, and the request is still approved.
…past departed principals
…eparted requester Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebasing onto main drops the merges of group-request-service-principals into this branch, and with them the resolutions they made: the app create route and the group request router keep main's code, and the shared access-length helpers stay with the group request pages. This commit restores that end state on top of the replayed commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring the app request pages in line with main's lint pass over the group request pages they follow: read search input through useSearchInput, show API errors with requestErrorMessage, mark navigate calls as fire-and-forget, and type the test mocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the formatting the openapi-client-drift check produces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41745b8 to
ddb338a
Compare
POST /api/apps accepted app_group_lifecycle_plugin and plugin_data in
CreateAppBody but dropped them, so an app could only get its plugin
through a follow-up PUT. The app create form already sends both fields
for Access admins, so their configuration was silently lost.
CreateApp now takes both fields. Before writing anything, it validates
plugin_data against the chosen plugin's app-level configuration. It
checks whenever a plugin is chosen, so an unknown plugin id is rejected
even without plugin_data. It then sets both fields on the app, which
also puts them in the app_create audit event. The owner group and any
initial app groups are created under an app that already has the
plugin, so the plugin gets group_created for them.
The route maps the operation's errors the same way the group request
routes do: a ValueError becomes a 400, and a filtering error becomes a
400 for an unknown plugin id or a 500 for a misbehaving plugin. Plugin
config stays Access-admin-only, as on PUT. An app creator who isn't an
admin gets a 403 when supplying either field but can still create an
app without them.
PUT /api/apps/{id} validated only when the body carried plugin_data,
so it accepted a new, unregistered plugin id sent on its own. It now
rejects that with a 400. A stored id that is re-sent unchanged is left
alone, because the edit form sends it on every save and an app whose
plugin was dropped from the deployment must stay editable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
barborico
left a comment
There was a problem hiding this comment.
Parity with POST /api/apps is good: the request path refuses everything the direct path does, and a little more.
The blocking items are the lifecycle plugin fields, a dropped notification, reviewer routing, and the reason
constraint. There's also a fair amount of duplication with the group request and app create paths.
| member_role_ids: list[str] = Field(default_factory=list) | ||
|
|
||
|
|
||
| class CreateAppRequestBody(BaseModel): |
There was a problem hiding this comment.
App requests must carry app_group_lifecycle_plugin and plugin_data, as the RFC specifies. POST /api/apps
currently ignores both fields, but that's a bug, and we shouldn't copy it into a new create path. The fix for the
direct route is in #796; validate and apply both fields here the same way,
with tests.
| (f"{group.name} member role {r}", add_role(r, group_id, False, True, membership_ending_at)) | ||
| for r in group.member_role_ids | ||
| ] | ||
| failed = await carry_out_grants(grants, f"app request {self.app_request_id}") |
There was a problem hiding this comment.
If a grant fails, carry_out_grants rolls back, which expires requester_user. It's then passed detached to
ACCESS_APP_REQUEST_COMPLETED, and the hook's first attribute read raises, so the notification is silently
dropped. Re-fetch the requester after the grants, as ApproveGroupRequest does.
| ): | ||
| return app_request | ||
|
|
||
| approvers = await get_access_owners() |
There was a problem hiding this comment.
App requests should use main's single definition of who reviews a request (api/models/request_reviewers.py)
rather than calling get_access_owners() directly. That way "Assigned to Me" and the reviewers endpoint cover
them too.
| created.created_by_service_principal_id = app_request.requester_service_principal_id | ||
| await db.session.commit() | ||
|
|
||
| created_reason = f"App request approved: {app_request.request_reason}" |
There was a problem hiding this comment.
Same as #746: the prefix always satisfies the reason constraints, and nothing checks the reason at creation. Use
the access justification described there, and require it when the app's tags require a reason.
| logging.getLogger("access.audit").info( | ||
| AuditLogSchema().dumps( | ||
| { | ||
| "event_type": EventType.app_request_approve, |
There was a problem hiding this comment.
This is logged before CreateApp runs, so a failed create still records an approval. Move it after the app
exists.
| ] | ||
|
|
||
| prefix = ( | ||
| f"{AppGroup.APP_GROUP_NAME_PREFIX}{app_request.requested_app_name}{AppGroup.APP_NAME_GROUP_NAME_SEPARATOR}" |
There was a problem hiding this comment.
Nit: The App-{name}- prefix f-string is now built in four places (CreateApp, owner_group_conflict,
validate_app_groups, approve_app_request.py). Put it on AppGroup, for example
AppGroup.prefix_for(app_name).
| return cap if requested is None else min(requested, cap) | ||
|
|
||
|
|
||
| async def ensure_app_group_names_free(names: list[str]) -> None: |
There was a problem hiding this comment.
Nit: create_app_request.py imports this from the approve module; move it next to the other app-name checks.
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def validate_app_groups(app_name: str, app_groups: list[AppRequestGroup]) -> list[AppRequestGroup]: |
There was a problem hiding this comment.
Nit: validate stashes self._requester, self._tags, and friends for execute, so the two must be called in order.
That departs from the two-method operation pattern; return the loaded values instead.
| await db.session.scalars(select(AppRequest).where(AppRequest.id == self.app_request_id).with_for_update()) | ||
| ).first() | ||
| if app_request is None: | ||
| return None |
There was a problem hiding this comment.
Nit: ApproveAppRequest.execute returns None for a missing request while RejectAppRequest.execute asserts. Pick one
behavior, ideally a clean error.
| return any(group.member_user_ids or group.member_role_ids for group in app_groups) | ||
|
|
||
|
|
||
| async def ensure_app_name_available(app_name: str) -> None: |
There was a problem hiding this comment.
Nit: ensure_app_group_names_free, owner_group_conflict, ensure_app_name_available, has_member_grants,
partition_active_*, current_status, and validate_app_groups need args, returns, and raises.
| notify=self.notify, | ||
| ).execute() | ||
|
|
||
| # The app's owners own and are members of its owners group. |
There was a problem hiding this comment.
App owners should own the app's owners group, not also be members of it. Ownership and membership of -Owners carry different responsibilities, so membership should be granted separately. Grant only ownership here (add_users(owners_group_id, owner_user_ids, [], …) and add_role(r, owners_group_id, False, True, …)), and update the schema docstring and the form's helper text to match. If a request needs to seed members of the owners group, the app request dialog should expose that as its own multi-select field for -Owners membership.
This copies CreateApp on main, which does the same for POST /api/apps. That should change too, but in its own PR.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in' into app-requests
- Carry the app's lifecycle plugin and its config on the request, validated at filing and applied by CreateApp on approval, as POST /api/apps does. - Make the app's owners own its owners group only; members of that group are named separately, and the owners group and each initial group carry NamedGrants. - Add an access justification, required when the app's tags require a reason for the access a request names. - Route app requests through request_reviewers for notifications, the assignee filter, and a new reviewers endpoint. - Log approval once the app exists, re-read the requester after the grants, key off the loaded request, refuse a departed requester and a missing request with clean errors, and have validate return what it loaded. - Share the app-name checks, end-date resolution, grant building, request router helpers, and conditional-access handling with group requests and POST /api/apps, and add AppGroup.prefix_for. - Accept initial app group names without the app's prefix, so the request dialog no longer retypes it, and move the shared length and end-date fields and useTagsByIds out of the group request pages. - Show Request an App to non-admins only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
AI review
No blockers; 2 advisory findings.
Reviewed commit a86c6bd9fbb96fe7bf8a8df182b9aac1942ea4fe.
Where reviewers should focus
api/operations/approve_app_request.py: Creates an app from any user's or service principal's request, takes over existing groups with the app's prefix, and grants owners and members, including on plugin approval.api/routers/app_requests.py: New mutating routes that decide who may approve (Access admins only) and who may withdraw (the requester).api/operations/_app_requests.py: Validation shared by filing and approval: name availability, initial group names, active principals, and access-reason constraints.api/operations/create_app.py: CreateApp now applies and validates a lifecycle plugin, and POST /api/apps gains a 403 for app creators who configure one.api/operations/create_group_request.py: Group request conditional-access handling was refactored into a shared helper that reads status from the database.
Risk areas: risk:auth, risk:tags, risk:routing, risk:async-orm, risk:plugin-api, risk:migration, risk:audit.
Findings
- Advisory / Security: Approval silently puts existing groups with the app's prefix under the requested app (55% confidence, api/operations/approve_app_request.py:197-209)
- Advisory / Correctness: Prefixed initial group names are never checked against the 255-character column width (45% confidence, api/operations/_app_requests.py:98)
Details are inline.
Blockers above fail this check. Push a fix to run the review again.
Automated review. A maintainer still reviews every pull request.
| # Creating the app absorbs any existing groups already carrying its prefix; | ||
| # only the groups it creates are credited to the requesting service principal. | ||
| preexisting_group_ids = set( | ||
| ( | ||
| await db.session.scalars( | ||
| select(OktaGroup.id) | ||
| .where( | ||
| OktaGroup.name.istartswith(AppGroup.prefix_for(app_request.requested_app_name), autoescape=True) | ||
| ) | ||
| .where(OktaGroup.deleted_at.is_(None)) | ||
| ) | ||
| ).all() | ||
| ) |
There was a problem hiding this comment.
Advisory / Security: Approval silently puts existing groups with the app's prefix under the requested app
CreateApp turns every active non-app group named App-<name>-* into an app group of the new app. The app owners named in the request (by default the requester) can then manage those groups, because app owners manage app groups. ensure_app_group_names_free refuses an initial group whose name matches an existing group, on the grounds that 'creating the app would take it over'. A matching group the request does not name is still taken over, with nothing shown to the approver. This block already finds those groups (preexisting_group_ids) but only uses them to skip provenance. Through the new request path, any user can file a request that, once an admin approves it or a conditional-access plugin auto-approves it, gives them management of groups they never owned (for example a plain App-Foo-Secrets group). Fix: refuse the request with a ConflictError, at filing and again here at approval, when active non-app groups carry the prefix. Alternatively, list them in the request detail so the approver sees them. Add a regression test with a pre-existing plain App-<name>-X group that the request does not name.
| seen: set[str] = set() | ||
| validated = [] | ||
| for group in app_groups: | ||
| name = group.name if group.name.startswith(prefix) else prefix + group.name |
There was a problem hiding this comment.
Advisory / Correctness: Prefixed initial group names are never checked against the 255-character column width
AppRequestGroup.name is limited to 255 characters before the App-<app>- prefix is added here, and the full name is never checked again. A request with a long app name or long group names passes filing. At approval, CreateApp saves the app first, then fails creating the over-long group (Postgres rejects anything over the Unicode(255) width). The result is an app with no groups or grants, the request still pending, and every later approval failing with a 409 because the name is now taken. SQLite does not enforce widths, so the SQLite suite would not catch this. Fix: after prefixing, raise InvalidRequestError when len(name) > 255, and check the owners group name the same way. Add a test.
Summary
Adds app requests: users and service principals can request a new app with its owners, tags, and initial app groups (each group with its own owners and members). Access admins or a conditional-access plugin approve them. Includes the UI. Stacked on #747.
Urgency: Low, 1-2 weeks
Expected review effort: HIGH
Motivation
Creating an app today is a direct call limited to Access admins or the
APP_CREATOR_IDallowlist. Services that create apps per project or tenant need the allowlist, and humans have no way to ask for an app. An app request gives both the same path: name the app, its owners, and its initial groups, then let an admin, or an operator's plugin rule, approve it. This is the replacement path forAPP_CREATOR_ID.Description of Changes
CreateAppapply and validate an app's lifecycle plugin. Its commit drops out of this diff once Bug fix: Apply the app group lifecycle plugin when creating an app #796 lands.app_requesttable holds:requested_owners_group, aNamedGrants: the app's owners, who own its owners group, and any members of that group;requested_app_groups, each entry{name, description, grants}withgrantsaNamedGrants;appgainscreated_by_service_principal_id.CreateAppRequest.validatechecks the request and returns what it loaded: the name must be free; an existing owners group must have no owners (owner_group_conflict, whichPOST /api/appsnow calls too); app group names are unique, not the owners group, and not the name of any existing group (a name without the app's prefix is given it, asPOST /api/appsdoes); every named ID must be active; the plugin config must validate; and the access justification must be given when the app's tags require a reason. A user's request with no owners defaults to the requester. A service principal's must name one. Tag time limits cap the end dates at creation.ApproveAppRequestre-checks all of that, runsCreateAppwith the plugin, then grants each owner and member with its own end date. App owners own the owners group; members of that group are granted separately. It fails with 409 when the requester is no longer active, and is logged once the app exists and its grants are made.RejectAppRequestlets admins reject any request and requesters withdraw their own. Both raise for a missing request.DeleteUserrejects a deleted user's pending app requests, as it already does for group requests.request_reviewersassigns app requests to Access admins, so notifications, the assignee filter, and the new/api/app-requests/{id}/reviewersendpoint read the one definition./api/app-requestsprovides list (status, requester, assignee, resolver, andqfilters), read, reviewers, create, and resolve. Only Access admins approve, and nobody approves their own request. A retry replaces the same requester's pending request for the same name. An end date sent as null approves indefinitely.app_request_createdconditional-access hook (its response'sending_atandmembership_ending_atcap the grants) and newaccess_app_request_created/access_app_request_completednotification hooks. Service principals get no requester-facing notification.APP_REQUEST_CREATE/_APPROVE/_REJECTevents.AppGroup.prefix_forbuilds an app's group prefix./app-requests, with admin approve/reject and requester withdraw;canApproveAppRequestinauthorization.tsx;The length and end-date fields and
useTagsByIdsmove tosrc/components/AccessDuration.tsxandsrc/useTagsByIds.ts, shared by both request types.Validation of Changes
tests/test_app_request.pycovers:TestAppRequestPluginConfigintests/test_app_group_lifecycle_plugin.py: the requested plugin applied on approval, and invalid config or an unknown plugin refused at filing.alembic check, downgraded, and re-applied on SQLite.Guidance for Reviewers
api/operations/approve_app_request.pyandapi/operations/_app_requests.py.POST /api/apps, which still makes app owners members of the owners group too. Changing that belongs in its own PR.Screenshots
From a local build seeded with test data. TODO: retake; these predate the owners group members field, the access justification, and the unprefixed group names.
The app requests list

The app request form

An app request from a service principal

An app request from a user
