Authentication & Authorization
Storsko uses a two-layer authentication model. The root API key authenticates operators and administrators who manage the Storsko instance. Agent JWTs authenticate individual agents at runtime. In the commercial platform, Keycloak SSO adds a third layer for human users accessing the dashboard and APIs.
Authentication & Authorization
Storsko uses a two-layer authentication model. The root API key authenticates operators and administrators who manage the Storsko instance. Agent JWTs authenticate individual agents at runtime. In the commercial platform, Keycloak SSO adds a third layer for human users accessing the dashboard and APIs.
OSS Authentication
Root API Key
When you start Storsko for the first time via make setup, a root API key is generated automatically and printed to stdout. This key is the master credential for your OSS deployment.
Key format:
Example:
The 64-character hex suffix is generated from a cryptographically secure random source. The key is stored in PostgreSQL as a SHA-256 hash — the plaintext is never persisted. This means if you lose the key, you must rotate it via the CLI.
::alert{type="warning" title="The root API key is displayed only once at setup time. Store it in a secrets manager (HashiCorp Vault, AWS Secrets Manager, 1Password) immediately. There is no "show me the key again" command."}
::
How the key is stored:
Storsko hashes the incoming key on every request and compares it to the stored hash — the plaintext never touches the database.
Generating / Rotating the Root API Key
The rotate command atomically replaces the stored hash. Any service using the old key will receive 401 Unauthorized immediately after rotation.
Using the Root API Key
Pass the key in the Authorization header as a Bearer token:
Agent JWTs
Agents do not use the root API key. Instead, each agent receives a short-lived JWT signed with HS256 when it registers or authenticates. This scopes the agent to its own capabilities and prevents agents from performing administrative operations.
JWT Generation
When an agent registers via POST /api/v1/agents, the API server issues a JWT:
JWT Payload Structure
| Field | Type | Description |
|---|---|---|
sub | string | Agent UUID (same as agent_id) |
agent_id | string | Agent UUID |
org_id | string | Owning organization UUID |
capabilities | string[] | Array of capability strings granted to this agent |
iat | number | Issued-at timestamp (Unix seconds) |
exp | number | Expiry timestamp (Unix seconds) |
Example decoded payload:
Using the Agent JWT
Token Refresh
Agent JWTs expire after 1 hour by default. Agents should refresh their token before expiry:
The refresh endpoint validates that the agent is still active and its capabilities haven't changed. If the agent has been deactivated, the refresh fails with 403 Forbidden.
Commercial Authentication (Keycloak SSO)
The commercial Storsko platform replaces the simple root-key model with Keycloak for human user authentication. Agent JWTs continue to work as described above.
Keycloak Integration
Storsko's commercial platform ships a pre-configured Keycloak realm (storsko) that handles:
- Username/password authentication
- OAuth 2.0 / OIDC flows
- Social login (Google, GitHub — see
storsko/social-login.md) - Multi-factor authentication
- Session management
Commercial JWT Claims
The commercial JWT extends the OIDC standard claims with Storsko-specific fields:
| Claim | Type | Description |
|---|---|---|
sub | string | Keycloak user UUID |
user_id | string | Storsko internal user UUID |
email | string | User email address |
tenant_id | string | Organization / tenant UUID |
tier | string | Subscription tier: personal, teams, enterprise |
role | string | User role: owner, admin, member, viewer |
has_subscription | boolean | Whether the tenant has an active Stripe subscription |
managed | boolean | Whether this is a Storsko-managed cloud deployment |
iat | number | Issued-at |
exp | number | Expiry |
Example decoded commercial JWT:
Subscription Tiers
| Tier | Description |
|---|---|
personal | Single-user, OSS-equivalent feature set |
teams | Multi-user, team management, shared capability grants |
enterprise | Full feature set: multi-tenancy, SSO, SLA, audit export |
OIDC Login Flow
Authorization Middleware
The packages/api-server applies authorization at two levels: route-level guards and capability-level checks in the execution adapter.
Route Guards
Every Fastify route is protected by one of three guard types:
Capability-Level Authorization
When an agent attempts to execute a capability, the execution adapter (packages/execution-adapter) validates the capability against the agent's JWT claims before any execution takes place:
If the capability is not in the JWT, the request is rejected immediately with 403 Forbidden — no HITL, no audit entry for the attempt (though failed auth attempts are logged separately).
Code Examples
TypeScript SDK — Root Key Authentication
TypeScript SDK — Agent Authentication
curl — Verify Authentication
Security Best Practices
Key Rotation
Rotate the root API key regularly, especially after team member changes:
Automate key rotation in your CI/CD pipeline. Store keys in your secrets manager and update them on a quarterly schedule or after any security incident.
Minimal Scope
Grant agents only the capabilities they need. An agent that only needs to search the web should not have finance.transfer in its JWT:
JWT Expiry
Keep agent JWT TTLs short. The default is 1 hour. For highly sensitive agents, reduce this to 15 minutes and implement automatic refresh logic.
Environment Variables
Never hardcode credentials. Use environment variables and a secrets manager:
Never commit `.env` files or API keys to version control. Add `.env` to your `.gitignore`. Scan your git history for accidental credential commits using tools like `git-secrets` or `trufflehog`.
Network Security
In production, place Storsko behind a reverse proxy (nginx, Caddy, AWS ALB) and:
- Enable TLS/HTTPS — never send API keys over plain HTTP
- Restrict the API port to your internal network or VPN
- Use IP allowlisting for root API key endpoints if possible
Related Pages
- Capabilities — what agents are authorized to do
- Agents — agent registration and lifecycle
- Audit Log — tracking all authenticated actions
- Compliance — GDPR and EU AI Act requirements