Skip to content

P3MDI SSO pilot

The Hub calls https://app.p3mdi.id/api/sso. Traefik forwards that exact path to the Deno container on KVM4. The Hub’s database stays in Supabase.

  1. In Authentik, create a confidential OAuth2/OpenID Connect application with slug soedirman-hub. Select an RS256 signing certificate, keep the per-application issuer, and register https://app.p3mdi.id/login as a strict redirect URI. Bind the application to the pilot group.

  2. Apply supabase/migrations/20261117_p3mdi_sso.sql to the Hub database.

  3. Copy ops/p3mdi-sso to KVM4, for example to /opt/soedirman-hub-sso. In that directory, put the following settings in a root-only .env file. Use the Hub’s existing Supabase project URL and create an sb_secret_... key for this service in Settings → API Keys.

    P3MDI_HUB_ORIGIN=https://app.p3mdi.id
    P3MDI_OIDC_CLIENT_ID=
    P3MDI_OIDC_CLIENT_SECRET=
    SUPABASE_URL=
    SUPABASE_SECRET_KEY=

    Run docker compose up -d --build. The service joins the existing coolify Docker network. A GET to https://app.p3mdi.id/api/sso returns a public client ID when all settings are present, or HTTP 503 when SSO is unconfigured. Only the public client ID reaches the browser.

  4. Link each pilot account using the Authentik issuer and the verified subject from that application’s OIDC identity. Confirm the Serdik NOSIS or Pengasuh NRP against the roster before inserting the link. Keep Authentik’s subject mode fixed after linking users.

INSERT INTO portal_private.p3mdi_identities (issuer, subject, user_type, user_code)
VALUES (
'https://auth.p3mdi.id/application/o/soedirman-hub/',
'<verified subject>',
'serdik',
'<existing NOSIS>'
);

Check that a linked member sees the same profile, roles, groups, and records through SSO and PIN. Check that an unlinked account is denied, a replayed callback fails, and PIN login works. Use pilot accounts that have already completed any mandatory PIN change.

Deleting a link stops future SSO sign-ins for that identity. Revoke existing Hub sessions if access needs to stop immediately. If a NOSIS or NRP is reassigned, remove its former identity link and revoke its sessions before reusing the code.

To hide the SSO option, remove the client ID from the service’s .env and run docker compose up -d. PIN login remains available.

Super Admins can open Pengaturan → Akun SSO to view the Serdik accounts and activate one account or all inactive accounts. Confirm identity links and complete a pilot login before bulk activation.

The management endpoint validates the active Hub session and requires the effective super_admin role. It accepts only existing internal accounts in the Soedirman Hub Serdik Authentik group. Activation updates the account’s active status.

For a replacement deployment, set P3MDI_HUB_PUBLIC_KEY to the Hub’s existing Supabase public key and P3MDI_SERDIK_GROUP_ID to the Authentik group’s UUID. Set P3MDI_ACCOUNT_API_TOKEN to an Authentik service-account token with object-level view and change permissions on just the group’s Serdik accounts. Keep the token in the SSO container’s server-only .env. Grant the same object permissions for newly provisioned Serdik and revoke grants for removed accounts.

Manage identity from the Hub profile (#62)

Section titled “Manage identity from the Hub profile (#62)”

The Authentik database stays the single identity store; the Hub keeps only the link rows and an audit trail (portal_private.sso_audit). The broker exposes management endpoints that always authorize via the caller’s Hub session:

  • GET /api/sso/profile and PATCH /api/sso/profile — self-service: read and update your own Core profile (name, email). Email and name are the platform-wide fields distributed through OIDC claims at next login.
  • POST /api/sso/link (OIDC callback with PKCE, session token) and DELETE /api/sso/link — link or unlink the signed-in account. The subject comes only from a verified token and is bound to the session’s user, so it cannot be attached to another account.
  • POST /api/sso/accounts/create, PATCH /api/sso/accounts, DELETE /api/sso/accounts?id= — Super Admin CRUD on any account in the Serdik group. Deletion requires the account to be inactive and unlinks its Hub identity.

Every mutation writes portal_private.sso_audit (actor, action, target, before/after for name, email, active). portal_sso_audit_list shows admins all entries; other accounts only see entries where they are the actor or the target. Apply supabase/migrations/20261125_sso_identity_management.sql before deploying the broker.

Deploy the updated broker, apply supabase/migrations/20261126_first_login_setup.sql, then deploy the frontend. The broker’s existing Authentik role also needs the object permission authentik_core.reset_user_password on managed Serdik accounts. Keep this permission scoped to those accounts, including when provisioning new members.

Accounts with must_change_pin = true see Buat PIN baru, followed by Ganti kata sandi SSO and Tambahkan email pribadi for accounts already linked to SSO. Unlinked staff accounts retain PIN-only setup. Accounts that completed setup are not prompted again.

GET /api/sso/setup resumes server-held progress. POST /api/sso/setup saves one step at a time. The broker derives the target account from the authenticated Hub session and its existing identity link. Passwords go to Authentik’s password API; they are never stored in Hub, browser storage, or the audit record. Personal email is saved in Authentik; this flow does not verify email ownership.

The database keeps must_change_pin true until all required steps finish, so existing access restrictions stay in effect after PIN creation. Other Hub sessions are revoked when the PIN is created and when setup finishes. Ordinary PIN changes still require the old PIN; their endpoint cannot complete first-login setup. Link changes require completed setup and go through the broker.

Run the SQL regression fixture only in a disposable empty PostgreSQL database: psql -f tests/sql/first-login-setup.test.sql. CI runs it in an isolated container and runs the broker tests in ops/p3mdi-sso/setup_test.ts.

Account management and identity confirmation

Section titled “Account management and identity confirmation”

Apply supabase/migrations/20261127_sso_account_management.sql and install the scoped Authentik integration in ops/authentik/README.md before deploying the updated broker and frontend. Authentik remains the identity source. Both member settings and admin account management link to https://auth.p3mdi.id/if/user/ in a new tab.

Members can update name/email, change their SSO password, review recent identity changes, inspect Hub and SSO browser sessions, and end other Hub sessions and all SSO browser sessions. Sensitive changes require a fresh Authentik login using OIDC prompt=login, max_age=0, PKCE, state, and nonce. The signed token’s subject must match the existing Hub identity link, and its authentication time must be within five minutes. Confirmation is stored server-side for that Hub session and expires after five minutes. A PIN login alone does not authorize these changes. Email changes save the address; they do not verify ownership.

Super Admins can filter managed accounts by member/NOSIS/email, group, active state, and setup completion. Account creation selects an existing, unlinked Serdik record and provisions an inactive Authentik account, assigns a random temporary password, links the stable subject, then activates it. A failed activation leaves an inactive linked account with a warning. A failed provision before linking attempts to remove only the newly created account. Username edits preserve the stable subject and member records.

Admin password resets return a temporary password only in the immediate response. The interface keeps it in memory for private distribution, clears it when dismissed or unmounted, and requires the recipient to replace it in Hub. The reset revokes the recipient’s Hub sessions without requiring them to recreate an already personal PIN. Administrators cannot reset, deactivate, or delete their own account through these admin controls. Deletion requires an inactive account and session revocation first.

Session revocation covers Hub sessions and Authentik browser sessions. Sessions or access tokens already issued to other applications can remain valid until those applications reauthenticate or the tokens expire. The current Hub session is preserved for self-service revocation. Passwords are excluded from audit and browser storage; audit entries include password-change/reset and session-revocation events without credential values.

Broker routes: /api/sso/security handles confirmation and self-service password changes; /api/sso/sessions lists and revokes sessions; /api/sso/accounts/directory joins managed identities to Hub members; /api/sso/accounts/reset-password performs admin resets. All broker mutations retain the same-origin check. CI runs the broker authorization tests and tests/sql/sso-management.test.sql in an isolated database.