First stable release. Notes: docs/release/RELEASE_NOTES_v1.0.0.md Lab record: docs/release/LIVE_RESULTS_v1.0.0.md
15 KiB
WS-02 MVP API Design — Identity & Access (Go Bootstrap)
Summary
This document defines a minimal-infrastructure WS-02 MVP for Kryptkeeper’s Go bootstrap service covering:
login+refreshtoken flow- API key authentication path (
Authorization: Bearer kk_<kid>_<secret>) - RBAC enforcement matrix aligned to DEC-001..DEC-005
- Backward-compatible behavior with existing bearer auth modes (
bootstrap|jwt|oidc) - Incremental implementation order with ship-safe smoke tests
Design goals for MVP:
- No new hard infra dependencies (no Redis, no message bus)
- Reuse existing runtime patterns (
/api/v1, kebab-case resources, JSON, current 401 envelope) - Preserve existing endpoint behavior by default; new capabilities are additive and flag-gated
Subtask Decomposition
- [1] Capture constraints from existing contracts + DEC decisions — DONE
- [2] Define WS-02 MVP resource model and auth decision flow — DONE
- [3] Specify concrete endpoint contracts (login/refresh/api-keys) — DONE
- [4] Define RBAC + scopes enforcement matrix aligned to DEC-001..DEC-005 — DONE
- [5] Define incremental rollout order + fallback compatibility + smoke tests — DONE
Constraints and Decision Alignment
DEC-001 (canonical V1 roles)
MVP role set (no deviations):
pki-adminpki-operatorpki-viewerpki-auditordiscovery-operatorservice-account
DEC-002 (custom roles deferred)
- No custom role CRUD in WS-02 MVP.
- API contracts remain extension-ready (
roleas enum now; can become registry-backed later).
DEC-003 (API key semantics)
- Token format:
kk_<kid>_<secret> - Store only
kid+ verifier (HMAC-SHA-256with server-side pepper) - Effective permissions: role permissions ∩ API key scopes
- Scopes can only restrict, never elevate.
DEC-004 (audit log ID type)
- Auth/API-key events continue to emit into
/api/v1/auditwithidasint64/BIGINT-compatible.
DEC-005 (naming)
- Canonical endpoint path:
/api/v1/api-keys(kebab-case plural)
MVP Architecture (Minimal Infra)
graph LR
C[Client] --> A[Go API Handlers]
A --> M[Auth Middleware]
M --> B[Bearer Router]
B -->|kk_ prefix| K[API Key Verifier]
B -->|non kk_| T[Existing Mode Verifier bootstrap/jwt/oidc]
K --> P[RBAC + Scope Evaluator]
T --> P
P --> H[Endpoint Handler]
H --> D[(SQLite/Postgres existing DB)]
H --> AU[Audit Provider]
Infra posture:
- Required: existing app process + existing DB provider path already used by service.
- Not required: Redis/session store/queue/external policy engine.
- Refresh token state stored in DB table (or in-memory fallback for local dev only).
Auth Decision Flow (Backward-Compatible)
sequenceDiagram
participant Client
participant API as Kryptkeeper API
participant Auth as Authenticator
participant AK as API Key Store
Client->>API: Request + Authorization: Bearer <token>
API->>Auth: authenticate(token)
alt token starts with "kk_" and API key auth enabled
Auth->>AK: verify kid + secret verifier + expiry
AK-->>Auth: principal(role, scopes) or invalid
else non-API-key token
Auth->>Auth: existing bootstrap/jwt/oidc validation path
end
Auth->>Auth: authorize(role permissions ∩ scopes)
alt authorized
API-->>Client: 2xx
else unauthenticated/unauthorized
API-->>Client: 401 or 403 (existing envelope)
end
Compatibility rules:
- Existing bearer token modes remain intact for all current endpoints.
- API key path is additive and can be enabled by feature flag.
- Existing 401 envelope remains unchanged for protected v1 endpoints:
{
"error": "unauthorized",
"message": "invalid or missing bearer token"
}
Endpoint Contracts (WS-02 MVP)
1) POST /api/v1/auth/login
Authenticate local user credentials and mint access + refresh tokens.
- Auth required: No
- Rate limit: 10 req/min per source IP
Request body
{
"email": "alex@example.com",
"password": "correct horse battery staple"
}
200 response
{
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "rfr_2jY...",
"refresh_expires_in": 2592000,
"principal": {
"user_id": "550e8400-e29b-41d4-a716-446655440000",
"email": "alex@example.com",
"role": "pki-operator"
}
}
}
Error statuses
400invalid/missing fields401invalid credentials403account inactive429too many attempts
Error example (401)
{
"error": "unauthorized",
"message": "invalid credentials"
}
2) POST /api/v1/auth/refresh
Rotate refresh token and issue a new access token.
- Auth required: No bearer header required; uses refresh token in body
- Rate limit: 30 req/min per source IP
Request body
{
"refresh_token": "rfr_2jY..."
}
200 response
{
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "rfr_9Lk...",
"refresh_expires_in": 2592000
}
}
Error statuses
400missing token401invalid/expired/replayed refresh token429too many attempts
Error example (401)
{
"error": "unauthorized",
"message": "invalid refresh token"
}
3) GET /api/v1/api-keys
List API keys.
- Auth required: yes (bearer JWT/OIDC/bootstrap/API key)
- Pagination: required (
limitdefault 25, max 100,cursoropaque string) - Rate limit: 120 req/min per principal
Query params
limit(optional int)cursor(optional string)user_id(optional UUID, admin-only)
200 response
{
"data": [
{
"id": "4d6f8b10-2e31-4c9c-9a43-d8e3fcb11a9c",
"name": "ci-prod",
"kid": "a1b2c3d4",
"key_prefix": "kk_a1b2c3d4_",
"role": "service-account",
"scopes": ["certificates:read", "certificates:write"],
"expires_at": "2026-10-01T00:00:00Z",
"last_used_at": "2026-04-07T11:00:00Z",
"created_at": "2026-04-07T10:00:00Z",
"user_id": "550e8400-e29b-41d4-a716-446655440000"
}
],
"meta": {
"total": 1,
"limit": 25,
"next_cursor": null,
"prev_cursor": null
}
}
Status codes
200success401unauthenticated403forbidden (cross-user access)
4) POST /api/v1/api-keys
Create API key (secret returned once).
- Auth required: yes
- Rate limit: 20 req/min per principal
Request body
{
"name": "ci-prod",
"role": "service-account",
"scopes": ["certificates:read", "certificates:write"],
"expires_at": "2026-10-01T00:00:00Z"
}
201 response
Headers:
Location: /api/v1/api-keys/{id}
{
"data": {
"id": "4d6f8b10-2e31-4c9c-9a43-d8e3fcb11a9c",
"name": "ci-prod",
"kid": "a1b2c3d4",
"token": "kk_a1b2c3d4_zNfA...",
"role": "service-account",
"scopes": ["certificates:read", "certificates:write"],
"expires_at": "2026-10-01T00:00:00Z",
"created_at": "2026-04-07T10:00:00Z"
}
}
Status codes
201created400invalid role/scope/expiry401unauthenticated403forbidden (e.g., non-admin attempting elevated role)
5) DELETE /api/v1/api-keys/{id}
Revoke API key.
- Auth required: yes
- Rate limit: 60 req/min per principal
Response
204 No Content
Status codes
204revoked401unauthenticated403forbidden404not found
RBAC Enforcement Matrix (MVP, DEC-001-aligned)
Legend: ✅ allowed, ❌ denied. For API-key auth path, final decision is role_allow && scope_allow.
| Endpoint group | pki-admin | pki-operator | pki-viewer | pki-auditor | discovery-operator | service-account |
|---|---|---|---|---|---|---|
POST /api/v1/auth/login |
✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
POST /api/v1/auth/refresh |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
GET /api/v1/authz-check |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
GET /api/v1/protected/* |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
GET /api/v1/cas* |
✅ | ✅ | ✅ | ✅ | ✅ | scope-limited |
POST/PATCH/DELETE /api/v1/cas* |
✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
GET /api/v1/templates* |
✅ | ✅ | ✅ | ✅ | ✅ | scope-limited |
POST/PUT/PATCH/DELETE /api/v1/templates* |
✅ | ✅ | ❌ | ❌ | ❌ | scope-limited |
GET /api/v1/certificates* |
✅ | ✅ | ✅ | ✅ | ✅ | scope-limited |
POST /api/v1/certificates issue/import/renew/revoke |
✅ | ✅ | ❌ | ❌ | ❌ | scope-limited |
GET /api/v1/audit |
✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
GET /api/v1/api-keys (own) |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
GET /api/v1/api-keys?user_id=* (all) |
✅ | ❌ | ❌ | ✅ (read-only all) | ❌ | ❌ |
POST /api/v1/api-keys |
✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
DELETE /api/v1/api-keys/{id} own |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Approvals and the approver role (v1 decision, 2026-10-18)
Two separate queues, two separate rules:
| Queue | Who may list and decide |
|---|---|
Certificate issuance requests (/api/v1/approvals, inbox type certificate_approval) |
pki-admin always; any other role named in the template's approval_roles (for example approver, pki-operator) on requests for that template only. The write gate still needs the action.approve permission, which approver and pki-operator hold. |
Key and CA pending actions (/api/v1/pending-actions, inbox type pending_action: key delete/export/rotate, CA import/trust-anchor/rotate, audit archive and the rest of dual control) |
pki-admin and pki-operator only. approver gets 403 and does not see other people's actions in the inbox. |
approver is therefore a certificate-requests role. It holds no key or CA authority.
Rules that hold on both queues: proposer is not approver (the raiser, or a key minted by the same human, is
refused with 403); the bootstrap token never approves; a request outside the caller's tenant answers 403
(certificate) or 404 (action) under MULTI_TENANCY; every approve, reject and refusal writes an audit row
(approval.approve, approval.reject, action.approve, action.reject, outcome denied for refusals).
GET /api/v1/approvals and the inbox list a non-admin only what they raised plus what their role may decide,
so the UI shows approvers exactly the items they can act on. A role named in approval_roles that lacks
action.approve (for example pki-viewer) can see those requests but is refused at the write gate.
Scope catalog (MVP)
cas:read,cas:writetemplates:read,templates:writecertificates:read,certificates:writeaudit:readapi-keys:read,api-keys:writeprotected:read
Enforcement examples:
pki-admin+scopes=["certificates:read"]=> cannot issue/revoke certs.pki-viewer+scopes=["cas:write"]=> still cannot mutate CAs (role denies).
Fallback-Compatible Strategy for Existing Bearer Modes
- Do not change existing mode semantics for
AUTH_MODE=bootstrap|jwt|oidc. - Introduce API key verification as an additive path behind
APP_API_KEYS_ENABLED(defaultfalse). - Bearer router behavior:
- If token prefix is
kk_and API key mode enabled => API key verification. - Else => existing
AUTH_MODEverification path unchanged.
- If token prefix is
- Existing endpoints (
/api/v1/authz-check,/api/v1/protected/*) keep response shape and status semantics. - Rollout flag progression:
- Stage A: flag off in all envs (no behavior change)
- Stage B: on in dev/staging with observe-only audit
- Stage C: on in prod with deny enforcement and alerting
Safe Incremental Implementation Order
-
Wave 1 — Policy and auth-context foundation
- Add canonical role constants (DEC-001)
- Add scope evaluator (
role ∩ scopes) without wiring decisions yet - Add audit event taxonomy for auth/api-key decisions
- Ship check: no API behavior change; all current smoke passes
-
Wave 2 — Login endpoint (
POST /auth/login)- Local-user credential validation against existing users store
- Mint short-lived access token + refresh token
- Ship check: new endpoint smoke only; existing matrix unchanged
-
Wave 3 — Refresh endpoint (
POST /auth/refresh)- Token rotation + replay rejection
- DB-backed refresh token store (minimal dependency)
- Ship check: refresh replay negative test passes
-
Wave 4 — API key management endpoints (
/api-keys)- list/create/revoke + one-time token return
- verifier hashing uses HMAC-SHA-256 + pepper (DEC-003)
- Ship check: key lifecycle smoke passes
-
Wave 5 — API key bearer auth path (flag-gated)
kk_token detection and verify path in middleware- principal context includes role + scopes
- Ship check: existing jwt/oidc/bootstrap bearer tests still green
-
Wave 6 — RBAC enforcement rollout by endpoint groups
- Enforce matrix on low-risk reads first (
/protected,/api-keys) - Then high-impact writes (
/certificates,/cas,/templates) - Ship check: role matrix smoke + regression smoke pass before each expansion
- Enforce matrix on low-risk reads first (
Smoke Test Plan (MVP)
Run via existing harness entrypoint:
KRYPTKEEPER_SMOKE_MODE=local scripts/test/run.sh --suite smoke
Add WS-02 smoke assertions:
-
POST /api/v1/auth/login- valid creds =>
200, hasaccess_token+refresh_token - bad creds =>
401
- valid creds =>
-
POST /api/v1/auth/refresh- valid refresh =>
200new access token - reused refresh token =>
401
- valid refresh =>
-
POST /api/v1/api-keys- valid bearer + role =>
201, token returned once - invalid scope =>
400
- valid bearer + role =>
-
GET /api/v1/api-keys- returns paginated
data+meta - non-admin
user_idoverride =>403
- returns paginated
-
API-key auth path on existing protected endpoint
GET /api/v1/protected/whoamiwith validkk_...=>200- same key without required scope =>
403
-
Backward-compat matrix (must remain green)
- bootstrap bearer on
/api/v1/authz-check=> unchanged behavior - jwt bearer on
/api/v1/authz-check+/protected/*=> unchanged - oidc bearer on
/api/v1/authz-check+/protected/*=> unchanged
- bootstrap bearer on
Confidence Scores
| Subtask | Confidence (1-10) | Notes |
|---|---|---|
| [1] Constraints + DEC alignment | 9 | Decisions mapped directly from approved record |
| [2] Resource model + flow | 8 | Fits current bootstrap architecture with additive path |
| [3] Endpoint contracts | 8 | Concrete request/response/status definitions included |
| [4] RBAC matrix | 8 | Canonical roles + scope-intersection semantics captured |
| [5] Rollout + compatibility + smoke plan | 9 | Incremental, flag-gated, regression-safe strategy |