Rust backend for the Keylime Monitoring Dashboard -- a web-based security operations platform providing centralized monitoring, management, and compliance capabilities for Keylime remote attestation infrastructure.
cargo build # dev build
cargo build --release # release buildcargo test # run all unit tests
cargo test <test_name> # run a single testIntegration tests use Mockoon to simulate Keylime Verifier and Registrar APIs. The mock data lives in test-data/.
Automated (recommended):
bash tests/mockoon_tests.shThis starts both mock servers, runs the tests, and cleans up automatically.
Manual step-by-step:
# 1. Install mockoon-cli (if not already installed)
npm install -g @mockoon/cli
# 2. Start the Verifier mock (port 3000) and Registrar mock (port 3001)
mockoon-cli start --data test-data/verifier.json --port 3000 &
mockoon-cli start --data test-data/registrar.json --port 3001 &
# 3. Run the integration tests
MOCKOON_VERIFIER=1 MOCKOON_REGISTRAR=1 cargo test --features mockoon test_mockoon -- --nocapture
# 4. Stop the mock servers
pkill -f mockoon-cliYou can also run Verifier or Registrar tests independently:
# Verifier tests only
MOCKOON_VERIFIER=1 cargo test --features mockoon test_mockoon_verifier -- --nocapture
# Registrar tests only
MOCKOON_REGISTRAR=1 cargo test --features mockoon test_mockoon_registrar -- --nocaptureUsing the Mockoon desktop app:
- Open Mockoon and import the mock files via File > Open environment:
test-data/verifier.json(runs on port 3000)test-data/registrar.json(runs on port 3001)
- Click the Start button (green play icon) for each environment
- Run the tests from a terminal:
MOCKOON_VERIFIER=1 MOCKOON_REGISTRAR=1 cargo test --features mockoon test_mockoon -- --nocapture - The Mockoon GUI will show each request in its log panel, letting you inspect request/response details, headers, and timing in real time
Manual testing with curl:
Start both Mockoon mocks and the backend, then use curl to test the API:
# Terminal 1: start the Verifier mock
mockoon-cli start --data test-data/verifier.json --port 3000
# Terminal 2: start the Registrar mock
mockoon-cli start --data test-data/registrar.json --port 3001
# Terminal 3: start the backend (defaults to localhost:3000/3001)
RUST_LOG=info cargo run
# Terminal 4: query the API
# List all agents
curl http://localhost:8080/api/agents | jq
# Get a specific agent (Pull mode, GET_QUOTE state)
curl http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000 | jq
# Get a failed agent (Pull mode, FAILED state)
curl http://localhost:8080/api/agents/a1b2c3d4-0000-1111-2222-333344445555 | jq
# Get a push-mode agent (Push mode, PASS state)
curl http://localhost:8080/api/agents/f7e6d5c4-b3a2-9180-7654-321098765432 | jq
# Get a failed push-mode agent (Push mode, FAIL state)
curl http://localhost:8080/api/agents/b2c3d4e5-a1b0-8765-4321-fedcba987654 | jq
# Fleet KPIs
curl http://localhost:8080/api/kpis | jq
# Search agents by UUID or IP
curl "http://localhost:8080/api/agents/search?q=10.0.1" | jq
# List all policies
curl http://localhost:8080/api/policies | jq
# Get a specific policy
curl http://localhost:8080/api/policies/production-v1 | jq
# Agent state distribution
curl http://localhost:8080/api/attestations/state-machine | jq
# Backend connectivity status (Verifier + Registrar health)
curl http://localhost:8080/api/integrations/status | jq
# Agent detail tabs (timeline, PCR, IMA, boot log, certs)
curl http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/timeline | jq
curl http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/pcr | jq
curl http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/ima-log | jq
curl http://localhost:8080/api/agents/f7e6d5c4-b3a2-9180-7654-321098765432/boot-log | jq
curl http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/certificates | jq
# Raw agent data exposes TPM key material and is Admin only (SR-003):
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/raw | jq
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/raw/backend | jq
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/raw/registrar | jq
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/raw/verifier | jq
# Attestation analytics (supports ?range=1h|6h|24h|7d|30d)
curl "http://localhost:8080/api/attestations/summary?range=30d" | jq
curl "http://localhost:8080/api/attestations/timeline?range=24h" | jq
curl http://localhost:8080/api/attestations | jq
curl http://localhost:8080/api/attestations/failures | jq
# Verification pipeline for healthy vs failed agent
curl http://localhost:8080/api/attestations/pipeline/d432fbb3-d2f1-4a97-9ef7-75bd81c00000 | jq
curl http://localhost:8080/api/attestations/pipeline/a1b2c3d4-0000-1111-2222-333344445555 | jq
# Push/pull mode analytics
curl http://localhost:8080/api/attestations/push-mode | jq
curl http://localhost:8080/api/attestations/pull-mode | jq
# Policy assignment matrix and impact analysis
curl http://localhost:8080/api/policies/assignment-matrix | jq
curl -X POST http://localhost:8080/api/policies/production-v1/impact | jq
# Certificates
curl http://localhost:8080/api/certificates | jq
curl http://localhost:8080/api/certificates/expiry | jq
# Performance
curl http://localhost:8080/api/performance/verifiers | jq
curl http://localhost:8080/api/performance/database | jq
curl http://localhost:8080/api/performance/api-response-times | jq
curl http://localhost:8080/api/performance/config | jq
curl http://localhost:8080/api/performance/capacity | jq
# Compliance
curl http://localhost:8080/api/compliance/frameworks | jq
curl http://localhost:8080/api/compliance/reports/nist-sp-800-155 | jq
# Integrations (durable, revocation, SIEM, SSH)
curl http://localhost:8080/api/integrations/durable | jq
curl http://localhost:8080/api/integrations/revocation-channels | jq
curl http://localhost:8080/api/integrations/siem | jq
# SSH reachability probe (requires Operator+ role, SSH must be enabled in config)
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/integrations/ssh-check/verifier | jq
# curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/integrations/ssh-check/registrar | jq
# Agent actions (reactivate, stop -- Operator+): authenticated examples
# use TOKEN from the auth flow above
# curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/actions/reactivate | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents/d432fbb3-d2f1-4a97-9ef7-75bd81c00000/actions/stop | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
# -d '{"agent_ids":["d432fbb3-d2f1-4a97-9ef7-75bd81c00000"],"action":"reactivate"}' \
# http://localhost:8080/api/agents/bulk | jq
# Alerts (list/read is available to everyone incl. anonymous viewers;
# lifecycle actions are Operator+ and need the bearer token)
curl http://localhost:8080/api/alerts | jq
curl "http://localhost:8080/api/alerts?severity=critical" | jq
curl http://localhost:8080/api/alerts/summary | jq
curl http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000001 | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000001/acknowledge | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
# -d '{"assigned_to":"analyst@example.com"}' \
# http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000002/investigate | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
# -d '{"resolution":"Root cause identified"}' \
# http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000005/resolve | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000003/dismiss | jq
# curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/alerts/a0000001-0000-4000-8000-000000000001/escalate | jq
curl http://localhost:8080/api/alerts/notifications | jq # stub
# curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ # Admin only (stub)
# -d '{"attestation_success_rate":0.95,"cert_expiry_days":30}' \
# http://localhost:8080/api/alerts/thresholds | jq
# Certificate details (by agent ID and cert type: ek, ak, mtls)
AGENT_ID=$(curl -sf http://localhost:8080/api/certificates | jq -r '.data[0].agent_id')
curl http://localhost:8080/api/certificates/$AGENT_ID/ek | jq
curl "http://localhost:8080/api/certificates/$AGENT_ID/ek?format=pem" # PEM export (Admin only)
curl http://localhost:8080/api/certificates/expiry | jq # expiry summary
# Audit log (filterable list, hash-chain verification, CSV/JSON export)
curl http://localhost:8080/api/audit-log | jq
curl "http://localhost:8080/api/audit-log?action=config_change&page=1&page_size=25" | jq
curl http://localhost:8080/api/audit-log/verify | jq # 409 + broken entry id on tamper
# Exports are Operator+ (SR-003):
# curl -H "Authorization: Bearer $TOKEN" "http://localhost:8080/api/audit-log/export?format=csv" -o audit-log.csv
# curl -H "Authorization: Bearer $TOKEN" "http://localhost:8080/api/audit-log/export?format=json" | jq
# Settings (reads for everyone; updates are Operator+)
curl http://localhost:8080/api/settings/keylime | jq
# curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
# -d '{"verifier_url":"http://localhost:3000","registrar_url":"http://localhost:3001"}' \
# http://localhost:8080/api/settings/keylime | jq
curl http://localhost:8080/api/settings/certificates | jq
# curl -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{}' \
# http://localhost:8080/api/settings/certificates | jq
# Attestation incidents (stubs -- not yet implemented)
curl http://localhost:8080/api/attestations/incidents | jq
curl http://localhost:8080/api/attestations/incidents/00000000-0000-4000-8000-000000000001 | jq
curl -X POST http://localhost:8080/api/attestations/incidents/00000000-0000-4000-8000-000000000001/rollback | jq
# Policy management (stubs -- not yet implemented)
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"test-policy","kind":"ima","content":"..."}' \
http://localhost:8080/api/policies | jq
curl -X PUT -H "Content-Type: application/json" \
-d '{"content":"..."}' \
http://localhost:8080/api/policies/production-v1 | jq
curl -X DELETE http://localhost:8080/api/policies/production-v1 | jq
curl http://localhost:8080/api/policies/production-v1/versions | jq
curl http://localhost:8080/api/policies/production-v1/diff | jq
curl -X POST http://localhost:8080/api/policies/production-v1/rollback/1 | jq
curl -X POST http://localhost:8080/api/policies/changes/change-001/approve | jq
# Compliance export (stub)
curl -X POST "http://localhost:8080/api/compliance/reports/nist-sp-800-155/export?format=pdf" | jq
# Authentication (OIDC authorization-code flow, SR-001)
# 1. Start the login flow: returns the provider authorization URL
curl -X POST http://localhost:8080/api/auth/login | jq
# -> {"data": {"redirect_url": "https://sso.example.com/auth?...&state=..."}}
# 2. The browser authenticates at the provider and returns to the SPA
# /auth/callback?code=...&state=..., which POSTs both values:
curl -X POST -H "Content-Type: application/json" \
-d '{"code":"auth-code","state":"csrf-state"}' \
http://localhost:8080/api/auth/callback | jq
# -> {"data": {"access_token": "<JWT>", "expires_in": 900}}
# 3. Call the API with the bearer token
TOKEN="<access_token>"
curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/agents | jq
# 4. Refresh rotates the session and returns a new 15-minute token (SR-010)
curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/auth/refresh | jq
# 5. Logout revokes the session server-side and is idempotent (SR-011)
curl -X POST -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/auth/logout | jq
# WebSocket (real-time events -- use websocat or similar tool)
# websocat ws://localhost:8080/ws/eventsThe backend reads KEYLIME_VERIFIER_URL and KEYLIME_REGISTRAR_URL environment variables (defaulting to http://localhost:3000 and http://localhost:3001).
Authentication uses OIDC (SR-001) with a three-tier RBAC model (SR-003):
Viewer (read-only), Operator (manage agents, alerts, exports,
settings), and Admin (everything, including policy management and TPM
key material). Roles are mapped server-side from the validated ID token
(SR-002): a user who authenticated with an MFA claim (acr = "1" by
default) gets Admin; without MFA they get the read-only Viewer
role. The Operator role is reserved and not assigned during bootstrap.
1. POST /api/auth/login -> { redirect_url } (PKCE S256 + CSRF state)
2. Browser authenticates at the IdP (+ MFA for Admin)
3. SPA returns to /auth/callback?code=...&state=...
4. POST /api/auth/callback -> { access_token, expires_in }
(validates the single-use state, exchanges the code, verifies the ID
token signature via JWKS/RS256 plus iss/aud/exp/nonce, maps the role,
creates the session, mints a 15-minute JWT)
5. Requests carry Authorization: Bearer <JWT>
6. POST /api/auth/refresh -> new token; the previous session is
revoked so stolen tokens die on refresh (SR-010)
7. POST /api/auth/logout -> revokes the session; idempotent (SR-011)
By default (ANONYMOUS_VIEWER=true, intended for internal deployments)
any unauthenticated request gets the read-only Viewer role — network
reachability is the trust boundary. Privileged operations always require
authentication (401). Deployments exposed beyond a trusted network must
set ANONYMOUS_VIEWER=false, which requires authentication on every
request.
| Operation | Viewer | Operator | Admin |
|---|---|---|---|
| View agent fleet, attestation analytics, policies, audit log | Yes | Yes | Yes |
| Export reports (CSV/PDF) | No | Yes | Yes |
| Acknowledge/manage alerts | No | Yes | Yes |
| Reactivate/stop agents, bulk actions | No | Yes | Yes |
| Update settings, SSH probes | No | Yes | Yes |
| Create/edit/delete/rollback/approve policies | No | No | Yes |
| Configure alert thresholds | No | No | Yes |
| View/export TPM key material (raw agent data, PEM/DER) | No | No | Yes |
Denied privileged attempts by an authenticated user return 403 and are recorded in the audit log with the caller's identity; anonymous callers get 401.
| Variable | Default | Description |
|---|---|---|
JWT_SECRET |
— (required in release) | HMAC secret for session JWTs. In dev builds an ephemeral random secret is generated with a warning when unset. |
OIDC_ISSUER_URL |
unset | The only required IdP setting. IdP issuer, e.g. https://sso.redhat.com/auth/realms/redhat-external. Discovery happens at startup; when unset, login returns 503 and only anonymous viewer access is available. |
OIDC_CLIENT_ID |
keylime-dashboard |
Client id sent in every authorization request. The IdP must have a client registered under this name; set it if yours is registered differently. |
OIDC_CLIENT_SECRET |
unset (optional) | Omit for a public client: the code exchange is protected by PKCE S256 (RFC 7636) and the ID-token verifier only accepts asymmetric algorithms, so no shared secret is needed. Set it for a confidential client. |
OIDC_REDIRECT_URI |
http://localhost:5173/auth/callback |
SPA callback route the IdP sends the user back to. Must be registered on the IdP client; set it when the frontend is served from another origin. |
ANONYMOUS_VIEWER |
true |
Grant unauthenticated requests the read-only Viewer role (SR-001). |
ROLE_MAPPING |
bootstrap |
bootstrap (MFA → Admin) or groups (not yet implemented; grants Viewer only) |
OIDC_MFA_CLAIM |
acr |
ID-token claim that signals completed MFA (SR-002) |
OIDC_MFA_VALUES |
1 |
Comma-separated accepted MFA claim values |
Issuer-only setup — every other IdP setting has a default; users authenticate on the provider's own login page and the backend never sees their credentials:
JWT_SECRET="$(openssl rand -hex 32)" \
OIDC_ISSUER_URL="https://sso.redhat.com/auth/realms/redhat-external" \
cargo runRegister the client once in the IdP realm (Keycloak: Clients → Create):
client id keylime-dashboard (or set OIDC_CLIENT_ID to whatever is
registered), public access type, redirect URI matching
OIDC_REDIRECT_URI (http://localhost:5173/auth/callback for local
dev), PKCE enabled. The client_id and redirect URI are registration
facts, not secrets — the IdP rejects authorization requests for unknown
clients and refuses to redirect to unregistered URIs.
Example with a confidential client (Red Hat SSO):
JWT_SECRET="$(openssl rand -hex 32)" \
OIDC_ISSUER_URL="https://sso.redhat.com/auth/realms/redhat-external" \
OIDC_CLIENT_ID="keylime-dashboard" \
OIDC_CLIENT_SECRET="..." \
OIDC_REDIRECT_URI="https://dashboard.example.com/auth/callback" \
cargo runTo exercise the full login flow without a corporate identity provider, run a Keycloak container and register the dashboard client in it once. The backend side is identical for any Keycloak-compatible provider — only the issuer URL changes.
1. Start Keycloak (stands in for e.g. sso.redhat.com):
docker run --name keycloak-demo -d -p 8081:8080 \
-e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:26.0 start-dev2. One-time setup — realm, public client, and a test user. The same
steps also work through the admin console at http://localhost:8081
(admin/admin): Clients → Create with the values below.
KCADM="docker exec keycloak-demo /opt/keycloak/bin/kcadm.sh"
$KCADM config credentials --server http://localhost:8080 \
--realm master --user admin --password admin
$KCADM create realms -s realm=demo -s enabled=true
# Requests arrive through the container port mapping and look external;
# without this Keycloak rejects them with "HTTPS required".
$KCADM update realms/demo -s sslRequired=none
$KCADM create clients -r demo -s clientId=keylime-dashboard \
-s publicClient=true -s enabled=true \
-s 'redirectUris=["http://localhost:5173/auth/callback"]'
$KCADM create users -r demo -s username=demo -s enabled=true
USER_ID=$($KCADM get users -r demo -q username=demo | jq -r '.[0].id')
# Complete the profile so Keycloak's "Verify Profile" required action
# does not interrupt the first login.
$KCADM update "users/$USER_ID" -r demo -s email=demo@keylime.dev \
-s emailVerified=true -s firstName=Demo -s lastName=User \
-s 'requiredActions=[]'
$KCADM set-password -r demo --username demo -p 'demo1234!'3. Point the backend at it — the issuer is the only required
variable; client id, secret, and redirect URI pick up their defaults
(keylime-dashboard, public client with PKCE S256,
http://localhost:5173/auth/callback):
JWT_SECRET="$(openssl rand -hex 32)" \
OIDC_ISSUER_URL=http://localhost:8081/realms/demo \
DATABASE_URL=sqlite://./keylime.db \
RUST_LOG=info \
cargo run4. Verify the flow:
# Login returns Keycloak's authorization URL
curl -s -X POST http://localhost:8080/api/auth/login | jq -r '.data.redirect_url'Then open the frontend (http://localhost:5173), click Sign in, and
enter demo / demo1234! on Keycloak's login page — the backend never
sees the password. If the frontend runs on another port, update the
client's redirectUris and OIDC_REDIRECT_URI to match.
Role mapping note: vanilla Keycloak emits acr=1 for a plain
password login, which the default MFA configuration
(OIDC_MFA_CLAIM=acr, OIDC_MFA_VALUES=1) maps to Admin — usually
fine for local development. To require a second factor for Admin,
configure OTP on the realm and set OIDC_MFA_VALUES=2 to match
Keycloak's two-factor authentication level.
Every login request carries prompt=login, so the IdP re-authenticates
the user even when an SSO session cookie is present. Without it
Keycloak silently resumes the session and issues the ID token with
acr=0, which the role mapping (correctly) treats as Viewer — the
dashboard's own logout never ends the IdP session.
Switching to a real provider later is a one-variable change — register the client there (see Configuration above), then set e.g.:
OIDC_ISSUER_URL=https://sso.redhat.com/auth/realms/redhat-externalStop the demo IdP with docker rm -f keycloak-demo.
JWTs carry { sub, role, iat, exp, session_id, tenant_id } with a
15-minute lifetime (SR-010). tenant_id is the single default tenant
until multi-tenancy lands (Phase 3).
The backend supports SQLite as a lightweight database for development and testing, controlled by the DATABASE_URL environment variable. When unset, in-memory repositories are used (no database).
# In-memory (ephemeral, data lost on restart)
DATABASE_URL=sqlite::memory: cargo run
# File-based (persists across restarts, auto-created)
DATABASE_URL=sqlite://./keylime-dev.db cargo runSQLite stores alerts, policies, policy changes, audit entries, attestation results, and correlated incidents. The schema is auto-created on startup (CREATE TABLE IF NOT EXISTS).
When mock data seeding is enabled via the settings file (seed_mock_data = true), the alerts table is populated with sample data on first run.
For a complete guide including schema details, type conventions, inspection commands, and limitations vs production Postgres, see docs/TESTING_WITH_SQLITE.md.
The mock data defines a fleet of 7 agents in different states:
| Agent UUID | Mode | State | Description |
|---|---|---|---|
d432fbb3-d2f1-4a97-9ef7-75bd81c00000 |
Pull | GET_QUOTE | Healthy agent, IMA policy production-v1 |
a1b2c3d4-0000-1111-2222-333344445555 |
Pull | FAILED | Failed agent, IMA policy production-v1, regcount=3 |
f7e6d5c4-b3a2-9180-7654-321098765432 |
Push | PASS | Healthy push-mode agent, IMA staging-v2 + MB measured-boot-v1, attestation_count=42 |
b2c3d4e5-a1b0-8765-4321-fedcba987654 |
Push | FAIL | Failed push-mode agent, IMA production-v1, attestation timeout + 3 consecutive failures |
c5d6e7f8-a9b0-4321-8765-abcdef012345 |
Push | PASS | Healthy push-mode agent, IMA policy production-v1, attestation_count=78 |
e6f7a8b9-c0d1-2345-6789-aabbccddeeff |
Push | PASS | Null ip/port push agent (registrar fallback), IMA production-v1, attestation_count=5 |
d1e2f3a4-b5c6-7890-1234-567890abcdef |
Push | TIMEOUT | Push-mode agent that stopped attesting, IMA production-v1, last attestation far in past |
Policies are served from two Keylime API endpoints: IMA policies from GET /v2/allowlists/ (production-v1, staging-v2) and measured boot policies from GET /v2/mbpolicies/ (measured-boot-v1).
Since there is no attestation history table yet, the /api/attestations/summary endpoint derives event-level stats from agent states: push-mode agents contribute their attestation_count and consecutive_attestation_failures, while pull-mode agents count as a single event each. The /api/attestations/timeline endpoint distributes these totals across hourly buckets with deterministic variation so the chart looks natural.
cargo clippy -- -D warnings # lint (treat warnings as errors)
cargo fmt # format code
cargo fmt -- --check # check formatting without modifyingApache-2.0