Skip to content

pnpr: runtime administration (admin role, teams, users, rules) and admin UI #111

Closed

Description

@zkochan

Status: planned. Phase 1 is in progress.

pnpr permissions can only change through a config deploy. Teams and package rules live in YAML. The npm team endpoints answer teams_config_managed (403) to every write. There is no admin role, and the web UI can only read because CORS allows only GET/HEAD. This plan adds runtime administration in phases. Each phase ships as one pnpm/pnpm PR plus one Bit lane on pnpm.pnpr for the UI.

Current state (origin/main, 2026-10-08)

  • Identity is only a username (pnpr/crates/policy/src/lib.rs). Nothing grants admin rights.
  • When the config is compiled, team members are copied into AccessToken::Team { members } (pnpr/crates/config/src/access.rs). Config is immutable for the process lifetime, and nothing reloads it.
  • Shared state across replicas: users and tokens in the SQL auth backend, and records in the hosted store (read_record / create_record / replace_record_if_current, compare-and-set on S3).
  • CORS: allow_methods([GET, HEAD, OPTIONS]) in pnpr/crates/pnpr/src/server/routing.rs. Credentials travel only in the Authorization header. The OIDC cookie only carries login state, so cross-origin writes are not exposed to CSRF.

Phase 1: admin role and runtime teams

Server:

  • Top-level admins: config: a list of usernames who may administer every registry.
  • Per hosted registry: teamsManagedBy: config | api, defaulting to config, which keeps today's behavior. With api, the registry's YAML teams: only seeds the store the first time. After that the store owns the teams.
  • AccessToken::Team reads a shared, swappable team directory instead of a copied member set. A rule that references a team sees membership changes immediately. A team missing from the directory admits nobody.
  • Teams are persisted as a hosted-store record (.teams/v0/<registry>). Writes are read-modify-write with compare-and-set and retry on conflict. Every replica refreshes its directory from the store when it is older than a short TTL. The refresh runs in the request middleware, so there is no background task, and the first request after startup waits for the load.
  • On api registries, admins can use the npm team endpoints that return teams_config_managed today: create a team, destroy a team, add a member, remove a member. That makes pnpm team / npm team work. Destroying a team that a packages: rule references is refused with 409. config registries keep answering 403.
  • GET /-/pnpr/v0/admin/me returns { "admin": bool, "teams": { "<registry>": "config" | "api" } }, so the UI shows edit controls only where they work.
  • CORS adds PUT, POST, DELETE.

UI (pnpm.pnpr lane):

  • pnprFetch gains write methods. The comment that the app only issues GET goes away.
  • New api/teams hooks and commands, plus a pages/teams page: list teams per scope and their members, and for admins on api registries, create, destroy, add, and remove.
  • A "Teams" nav entry under Server.

Phase 2: user administration

  • UserBackend gains list, create, delete, and set_password for htpasswd, libsql, and sqlx. Deleting a user revokes their tokens.
  • Admin API: GET/PUT/DELETE /-/pnpr/v0/admin/users[/{name}], plus listing and revoking tokens per user.
  • Limitation: htpasswd users stay per-replica. Multi-replica deployments need the SQL backend, as they do today.
  • UI: Users page.

Phase 3: runtime package rules

  • Admins can replace access / publish / unpublish for package patterns a registry already claims. Patterns themselves stay in config, because they feed routing.
  • Stored with the same record and refresh mechanism as teams, and recompiled into PackageRules behind a swappable handle.
  • npm access grant/revoke mapped onto team rules where the shapes match.
  • UI: rule editor on the registry page.

Phase 4: SSO group mapping

  • OIDC login.users bindings may name a claim (for example groups) whose values map to team memberships, refreshed at each sign-in.
  • Optional SCIM endpoint for deprovisioning, once phase 2 exists.

Out of scope

  • A cross-replica push channel. TTL polling bounds staleness instead.
  • Replacing YAML. Config stays a valid source, and api management is opt-in per registry.

Written by an agent (Claude Code, claude-opus-5-5).

Activity

  1. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Phase 1 landed in pnpm/pnpm#16725: the auth.admins role, teamsManagedBy: api, store-backed team rosters, and npm team writes. The registry directory reports admin and teamsManagedBy in place of the planned /-/pnpr/v0/admin/me. The UI half is Bit change request https://bit.cloud/pnpm/pnpr/~change-requests/team-administration.

    Starting phase 2: user administration.


    Written by an agent (Claude Code, claude-opus-5-5).

  2. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Phase 2 landed in pnpm/pnpm#16729: the admin account API (/-/pnpr/v0/admin/users), admin-created accounts that bypass max_users, and token revocation on removal. The UI half (an Accounts screen) is on Bit main through the user-administration lane.

    One deliberately open case is recorded in that PR: a login racing a removal whose final token sweep fails keeps its token until the removal is repeated.

    Starting phase 3: runtime package rules.


    Written by an agent (Claude Code, claude-opus-5-5).

  3. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Phase 3 landed in pnpm/pnpm#16732: rulesManagedBy: api and /-/pnpr/v0/admin/rules/{ecosystem}/{name}. Admins replace a hosted registry's default access and the access/publish/unpublish lists of its declared patterns. PackageRules is now a live handle, so the resolver sees changes too. The UI (a Package rules panel on the Registries screen) is on Bit main.

    Follow-ups left by phase 3:

    • Map npm access grant/revoke onto rules.
    • Optimistic concurrency for the rules API (If-Match), if concurrent admin edits turn out to matter. Today it is last-writer-wins by design.
    • pnpm.design/actions/[email protected] declares a react-router-dom ^5.3.4 peer while pnpr-web uses v6. Three pnpr-ui components now pin ^6.30.6 to work around it.

    Remaining: phase 4 (OIDC group-to-team mapping, SCIM).


    Written by an agent (Claude Code, claude-opus-5-5).

  4. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Phase 4 (group mapping) landed in pnpm/pnpm#16735. auth.oidc[].login.groups maps an ID-token groups claim to registry teams. The memberships last for the session and ride on the request identity, not the roster.

    Every phase of the plan has now shipped except SCIM, which was left out deliberately: it needs its own provisioning surface and credential type.

    Open follow-ups:

    • SCIM provisioning and deprovisioning.
    • Map npm access grant/revoke onto rules.
    • Optimistic concurrency (If-Match) for the rules API.
    • pnpm.design/actions/button's react-router-dom ^5.3.4 peer (three pnpr-ui components pin v6 to work around it).
    • The deliberately open login-versus-removal case from feat(pnpr): let admins manage accounts through an admin API pnpm#16729.

    Written by an agent (Claude Code, claude-opus-5-5).

  5. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Progress on the follow-ups:

    SCIM plan (deprovisioning first)

    Constraint: an OIDC sign-in creates no account row, and its session lives in memory on one replica. Deleting an account row is therefore not enough to deprovision anyone.

    • Config: auth.scim.token, a bearer secret (${VAR} substitution applies). It only authenticates /scim/v2/*. It is not a user token and is not admin on the npm API.
    • Directory record: SCIM state lives in the hosted store (.scim-users/v0) and replicas reload it on the managed-state TTL, like rosters and rules. A user's SCIM id is the username.
    • Users:
      • GET /scim/v2/Users, with filter=userName eq "...", startIndex, and count.
      • GET /Users/{id}.
      • POST /Users.
      • PUT /Users/{id} and PATCH /Users/{id}, for active only.
      • DELETE /Users/{id}.
    • Deprovisioning happens on active: false or DELETE. It:
      • revokes every stored token of that username;
      • removes a password account if one exists;
      • drops this replica's OIDC sessions for the username.
    • Enforcement: authentication refuses any user identity whose username the record marks inactive. That covers a session or token on another replica within the TTL. It also refuses a later OIDC sign-in.
    • Provisioning (POST, or active: true) only marks the username active. It does not create a password, because the IdP is the sign-in path.
    • Groups: out of the first PR. OIDC login.groups already carries memberships per session. A SCIM Groups resource onto teamsManagedBy: api rosters can follow if an IdP needs push-based groups.
    • Discovery: ServiceProviderConfig, ResourceTypes, and Schemas, at the minimum Entra ID and Okta need to connect.

    Written by an agent (Claude Code, claude-opus-5-5).

  6. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Merged:

    Still open, both rebased onto main:

    Waiting for review: Bit change requests rules-if-match (pnpr) and router-peer (design).


    Written by an agent (Claude Code, claude-opus-5-5).

  7. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    Merged:

    Every pnpm/pnpm follow-up from this plan has now landed. Still open: the Bit change requests rules-if-match (pnpr UI) and router-peer (design system). After router-peer merges, the three pnpr-ui pins of react-router-dom ^6.30.6 can go.


    Written by an agent (Claude Code, claude-opus-5-5).

  8. zkochan commented on Oct 8, 2026

    @zkochan
    MemberAuthor

    The Bit follow-ups have landed too:

    • pnpm.pnpr/rules-if-match: the admin UI sends If-Match on rules edits.
    • pnpm.design/router-peer: link, button, and cta-button accept react-router-dom 6 as a peer.
    • pnpm.pnpr/drop-router-pins: the pnpr UI components no longer pin react-router-dom themselves and use the tagged design-system versions.

    Nothing from this plan is left open in pnpm/pnpm or on bit.cloud.


    Written by an agent (Claude Code, claude-opus-5-5).

  9. zkochan commented on Nov 8, 2026

    @zkochan
    MemberAuthor

    Every phase and follow-up has merged (pnpm/pnpm#16725, pnpm/pnpm#16729, pnpm/pnpm#16732, pnpm/pnpm#16735, pnpm/pnpm#16738, pnpm/pnpm#16739, pnpm/pnpm#16740 and pnpm/pnpm#16742).

    Written by an agent (Claude Code, claude-opus-5-5).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions