Skip to content

Add app requests - #748

Open
Jeff-Rowell wants to merge 26 commits into
group-request-service-principalsfrom
app-requests
Open

Jeff-Rowell wants to merge 26 commits into
group-request-service-principalsfrom
app-requests

Conversation

@Jeff-Rowell

@Jeff-Rowell Jeff-Rowell commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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_ID allowlist. 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 for APP_CREATOR_ID.

Description of Changes

  • Depends on Bug fix: Apply the app group lifecycle plugin when creating an app #796. This branch merges Bug fix: Apply the app group lifecycle plugin when creating an app #796, which makes CreateApp apply 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.
  • Data: a new app_request table holds:
    • the requester (a user or a service principal; a check constraint requires exactly one);
    • the requested name, description, tags, and lifecycle plugin with its app-level config;
    • requested_owners_group, a NamedGrants: the app's owners, who own its owners group, and any members of that group;
    • requested_app_groups, each entry {name, description, grants} with grants a NamedGrants;
    • requested and resolved owner and member end dates, the access justification, and resolution fields.
      app gains created_by_service_principal_id.
  • Operations:
    • CreateAppRequest.validate checks the request and returns what it loaded: the name must be free; an existing owners group must have no owners (owner_group_conflict, which POST /api/apps now 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, as POST /api/apps does); 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.
    • ApproveAppRequest re-checks all of that, runs CreateApp with 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.
    • RejectAppRequest lets admins reject any request and requesters withdraw their own. Both raise for a missing request. DeleteUser rejects a deleted user's pending app requests, as it already does for group requests.
  • Reviewers: request_reviewers assigns app requests to Access admins, so notifications, the assignee filter, and the new /api/app-requests/{id}/reviewers endpoint read the one definition.
  • API: /api/app-requests provides list (status, requester, assignee, resolver, and q filters), 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.
  • Plugin interface: a new app_request_created conditional-access hook (its response's ending_at and membership_ending_at cap the grants) and new access_app_request_created / access_app_request_completed notification hooks. Service principals get no requester-facing notification.
  • Audit: new APP_REQUEST_CREATE / _APPROVE / _REJECT events.
  • Shared with group requests: the request router helpers (requester filter and search, retry replacement, named principals), the conditional-access dispatch, end-date resolution, and grant building, which group requests now use too. AppGroup.prefix_for builds an app's group prefix.
  • UI:
    • a create dialog with fields for the app owners, the owners group's members, and an editable initial-groups list, plus the access justification;
    • list and detail pages at /app-requests, with admin approve/reject and requester withdraw;
    • nav entries, and canApproveAppRequest in authorization.tsx;
    • a "Request an App" button for non-admins on the Apps list.
      The length and end-date fields and useTagsByIds move to src/components/AccessDuration.tsx and src/useTagsByIds.ts, shared by both request types.
  • Failures and retries: a retry is validated before it replaces the pending request, and each grant is made on its own, so a failed grant is noted in the resolution reason without stranding the request. The requester is read again after the grants, so its completion notification still goes out.
  • Provenance: groups created by an approved service principal request, including the owners group, record the principal. Groups absorbed by the new app don't.

Validation of Changes

  • New tests/test_app_request.py covers:
    • the full user flow: create, admin notification, 403s for the requester and a non-admin, admin approval, owners group ownership and membership granted separately, an initial group with separate end dates, completion notification;
    • the requester as the default owner, and the tag owner time limit;
    • create validation (taken name, reserved owners group, duplicates, unknown IDs and tags, existing group names, bare names given the prefix);
    • a name taken between request and approval (409, request stays pending, no approval logged);
    • withdraw, retry replacement, and an invalid retry;
    • a service principal that must name an owner and can't approve;
    • plugin approve and deny, with provenance and capped end dates;
    • the access justification;
    • Access admins assigned, through the assignee filter and the reviewers endpoint;
    • explicit indefinite, departed principals, departed requesters, and a failed grant still notifying the requester.
  • New TestAppRequestPluginConfig in tests/test_app_group_lifecycle_plugin.py: the requested plugin applied on approval, and invalid config or an unknown plugin refused at filing.
  • Full backend suite (SQLite), ruff, and ty pass. Vitest, tsc, prettier, and ESLint pass.
  • Migration applied, checked with alembic check, downgraded, and re-applied on SQLite.
  • Postgres CI run
  • Manual UI check of the create, review, and withdraw flows

Guidance for Reviewers

  • Review file by file. Start with api/operations/approve_app_request.py and api/operations/_app_requests.py.
  • End dates: the API lets approvers replace the end dates, the same way it does for group requests. A sent date applies to that approval only, plugin caps only shorten, tag limits apply, and the recorded end dates are the capped ones. The review page offers durations up to the requested one, never sends a date past it, and offers Indefinite only when the request has no end date. Approvers can't edit the requested app, owners, or groups; to change those, reject and refile. Named users and roles that are no longer active are skipped at approval and listed in the resolution reason; approval fails only if no app owner is still active.
  • Owners group membership differs from POST /api/apps, which still makes app owners members of the owners group too. Changing that belongs in its own PR.
  • The plugin is API-only for now. The request dialog doesn't offer the lifecycle plugin fields.
  • Release note for operators: new hooks, new audit event types, and new notification hooks.

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
image

The app request form
image

An app request from a service principal
image

An app request from a user
image

@Jeff-Rowell
Jeff-Rowell marked this pull request as ready for review November 6, 2026 23:11
Jeff-Rowell and others added 12 commits November 24, 2026 17:19
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.
…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>
github-actions[bot]

This comment was marked as outdated.

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 barborico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/approve_app_request.py Outdated
(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}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/create_app_request.py Outdated
):
return app_request

approvers = await get_access_owners()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/approve_app_request.py Outdated
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/approve_app_request.py Outdated
logging.getLogger("access.audit").info(
AuditLogSchema().dumps(
{
"event_type": EventType.app_request_approve,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is logged before CreateApp runs, so a failed create still records an approval. Move it after the app
exists.

Comment thread api/operations/approve_app_request.py Outdated
]

prefix = (
f"{AppGroup.APP_GROUP_NAME_PREFIX}{app_request.requested_app_name}{AppGroup.APP_NAME_GROUP_NAME_SEPARATOR}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread api/operations/approve_app_request.py Outdated
return cap if requested is None else min(requested, cap)


async def ensure_app_group_names_free(names: list[str]) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: create_app_request.py imports this from the approve module; move it next to the other app-name checks.

Comment thread api/operations/create_app_request.py Outdated
logger = logging.getLogger(__name__)


async def validate_app_groups(app_name: str, app_groups: list[AppRequestGroup]) -> list[AppRequestGroup]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/approve_app_request.py Outdated
await db.session.scalars(select(AppRequest).where(AppRequest.id == self.app_request_id).with_for_update())
).first()
if app_request is None:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ApproveAppRequest.execute returns None for a missing request while RejectAppRequest.execute asserts. Pick one
behavior, ideally a clean error.

Comment thread api/operations/create_app_request.py Outdated
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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/operations/approve_app_request.py Outdated
notify=self.notify,
).execute()

# The app's owners own and are members of its owners group.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

github-actions[bot]

This comment was marked as outdated.

Jeff-Rowell and others added 3 commits November 30, 2026 12:37
- 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>
@github-actions

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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.

Comment on lines +197 to +209
# 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()
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants