loki-mode 5.42.2 → 5.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,374 @@
1
+ # Authentication Guide
2
+
3
+ Authentication and access control for Loki Mode dashboard and API.
4
+
5
+ ## Overview
6
+
7
+ Loki Mode supports two authentication methods:
8
+
9
+ 1. **Token-based authentication** - API tokens with scopes and expiration
10
+ 2. **OIDC/SSO integration** (v5.36.0) - Google, Azure AD, Okta
11
+
12
+ Both methods can be enabled simultaneously and provide access to the dashboard API at `http://localhost:57374` (or `https://` with TLS enabled).
13
+
14
+ ## Token-Based Authentication
15
+
16
+ ### Enable Authentication
17
+
18
+ ```bash
19
+ export LOKI_ENTERPRISE_AUTH=true
20
+ loki start ./prd.md
21
+ ```
22
+
23
+ ### Generate Tokens
24
+
25
+ ```bash
26
+ # Basic token
27
+ loki enterprise token generate my-token
28
+
29
+ # With scopes and expiration
30
+ loki enterprise token generate ci-bot --scopes "read,write" --expires 30
31
+
32
+ # With role
33
+ loki enterprise token generate admin-bot --role admin --expires 90
34
+ ```
35
+
36
+ Output:
37
+
38
+ ```
39
+ Token generated successfully!
40
+
41
+ Name: ci-bot
42
+ ID: tok-abc123
43
+ Token: loki_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
44
+ Scopes: read, write
45
+ Expires: 2026-03-15
46
+
47
+ IMPORTANT: Save this token - it won't be shown again!
48
+ ```
49
+
50
+ ### Use Tokens with API
51
+
52
+ Include the token in the `Authorization` header:
53
+
54
+ ```bash
55
+ curl -H "Authorization: Bearer loki_xxx..." \
56
+ http://localhost:57374/api/status
57
+ ```
58
+
59
+ ### Manage Tokens
60
+
61
+ ```bash
62
+ # List active tokens
63
+ loki enterprise token list
64
+
65
+ # List all tokens (including revoked)
66
+ loki enterprise token list --all
67
+
68
+ # Revoke a token
69
+ loki enterprise token revoke ci-bot
70
+
71
+ # Revoke by token ID
72
+ loki enterprise token revoke tok-abc123
73
+ ```
74
+
75
+ ### Token Storage
76
+
77
+ Tokens are stored securely in `~/.loki/dashboard/tokens.json` with:
78
+
79
+ - SHA256 hashed token values (plaintext never stored)
80
+ - 0600 file permissions (read/write for owner only)
81
+ - Constant-time comparison to prevent timing attacks
82
+
83
+ ### Token Scopes
84
+
85
+ | Scope | Description | Included In |
86
+ |-------|-------------|-------------|
87
+ | `*` | All operations | Admin role |
88
+ | `control` | Start/stop sessions, modify tasks | Operator role, Admin role |
89
+ | `write` | Create/update tasks, modify state | Operator role, Admin role |
90
+ | `read` | View dashboard, logs, metrics | All roles |
91
+ | `audit` | View audit logs | Auditor role, Admin role |
92
+
93
+ Scope hierarchy:
94
+ - `*` includes all scopes
95
+ - `control` includes `write` and `read`
96
+ - `write` includes `read`
97
+
98
+ ### Roles (v5.37.0)
99
+
100
+ Predefined roles map to common access patterns:
101
+
102
+ | Role | Scopes | Description |
103
+ |------|--------|-------------|
104
+ | `admin` | `*` | Full access to all endpoints |
105
+ | `operator` | `control`, `read`, `write` | Start/stop sessions, manage tasks |
106
+ | `viewer` | `read` | Read-only dashboard access |
107
+ | `auditor` | `read`, `audit` | Read access plus audit log viewing |
108
+
109
+ Generate token with role:
110
+
111
+ ```bash
112
+ loki enterprise token generate viewer-bot --role viewer
113
+ ```
114
+
115
+ Generate token with custom scopes:
116
+
117
+ ```bash
118
+ loki enterprise token generate custom-bot --scopes "read,audit" --expires 30
119
+ ```
120
+
121
+ ## OIDC/SSO Authentication (v5.36.0)
122
+
123
+ Enterprise identity provider integration for centralized authentication.
124
+
125
+ ### Enable OIDC
126
+
127
+ Configure OIDC environment variables for your identity provider:
128
+
129
+ #### Google Workspace
130
+
131
+ ```bash
132
+ export LOKI_OIDC_ISSUER=https://accounts.google.com
133
+ export LOKI_OIDC_CLIENT_ID=your-client-id.apps.googleusercontent.com
134
+ ```
135
+
136
+ #### Azure AD
137
+
138
+ ```bash
139
+ export LOKI_OIDC_ISSUER=https://login.microsoftonline.com/{tenant}/v2.0
140
+ export LOKI_OIDC_CLIENT_ID=your-application-id
141
+ ```
142
+
143
+ #### Okta
144
+
145
+ ```bash
146
+ export LOKI_OIDC_ISSUER=https://your-org.okta.com
147
+ export LOKI_OIDC_CLIENT_ID=your-client-id
148
+ ```
149
+
150
+ ### Environment Variables
151
+
152
+ | Variable | Default | Description |
153
+ |----------|---------|-------------|
154
+ | `LOKI_OIDC_ISSUER` | - | OIDC issuer URL (required) |
155
+ | `LOKI_OIDC_CLIENT_ID` | - | OIDC client/application ID (required) |
156
+ | `LOKI_OIDC_AUDIENCE` | *(client_id)* | Expected JWT audience claim |
157
+ | `LOKI_OIDC_SCOPES` | `openid,email,profile` | OIDC scopes to request |
158
+
159
+ ### OIDC Flow
160
+
161
+ 1. User navigates to dashboard
162
+ 2. Redirect to identity provider login
163
+ 3. User authenticates with corporate credentials
164
+ 4. Provider redirects back with JWT
165
+ 5. Dashboard validates JWT and grants access
166
+
167
+ OIDC-authenticated users receive full access scopes by default. For fine-grained control, combine OIDC with token-based authorization.
168
+
169
+ ### Mixed Mode
170
+
171
+ OIDC and token auth can be active simultaneously:
172
+
173
+ - OIDC for human users (web dashboard)
174
+ - Tokens for automation (CI/CD, scripts, integrations)
175
+
176
+ ```bash
177
+ export LOKI_ENTERPRISE_AUTH=true
178
+ export LOKI_OIDC_ISSUER=https://accounts.google.com
179
+ export LOKI_OIDC_CLIENT_ID=your-client-id
180
+
181
+ loki start ./prd.md
182
+ ```
183
+
184
+ ## Configuration File
185
+
186
+ Persist authentication settings in `.loki/config.yaml`:
187
+
188
+ ```yaml
189
+ enterprise:
190
+ auth:
191
+ enabled: true
192
+ oidc:
193
+ issuer: https://accounts.google.com
194
+ client_id: your-client-id.apps.googleusercontent.com
195
+ audience: your-client-id.apps.googleusercontent.com
196
+ tokens:
197
+ default_expiration_days: 90
198
+ max_active_per_user: 10
199
+ ```
200
+
201
+ ## API Endpoints
202
+
203
+ ### Token Management
204
+
205
+ ```bash
206
+ # Create token
207
+ POST /api/enterprise/tokens
208
+ {
209
+ "name": "ci-bot",
210
+ "scopes": ["read", "write"],
211
+ "expires_days": 30
212
+ }
213
+
214
+ # List tokens
215
+ GET /api/enterprise/tokens
216
+
217
+ # Revoke token
218
+ DELETE /api/enterprise/tokens/{token_id}
219
+ ```
220
+
221
+ ### OIDC
222
+
223
+ ```bash
224
+ # Initiate OIDC login
225
+ GET /auth/oidc/login
226
+
227
+ # OIDC callback (handled automatically)
228
+ GET /auth/oidc/callback?code=...
229
+
230
+ # Logout
231
+ GET /auth/logout
232
+ ```
233
+
234
+ ## Security Best Practices
235
+
236
+ ### Token Management
237
+
238
+ 1. Generate separate tokens for each integration
239
+ 2. Use minimal scopes (principle of least privilege)
240
+ 3. Set expiration dates on all tokens
241
+ 4. Revoke unused tokens immediately
242
+ 5. Never commit tokens to version control
243
+ 6. Rotate tokens regularly (every 90 days recommended)
244
+ 7. Use environment variables or secret managers, not hardcoded values
245
+
246
+ ### OIDC
247
+
248
+ 1. Use HTTPS/TLS for all OIDC endpoints
249
+ 2. Validate JWT signatures
250
+ 3. Check token expiration
251
+ 4. Verify audience claim
252
+ 5. Use short-lived tokens (15 minutes recommended)
253
+ 6. Implement session timeout
254
+ 7. Log all authentication events
255
+
256
+ ### General
257
+
258
+ 1. Enable `LOKI_ENTERPRISE_AUTH` in production
259
+ 2. Enable `LOKI_TLS_ENABLED` for encrypted connections
260
+ 3. Use audit logging to track authentication events
261
+ 4. Monitor failed authentication attempts
262
+ 5. Implement rate limiting on auth endpoints
263
+ 6. Use strong entropy for token generation
264
+ 7. Store credentials in secure secrets management (AWS Secrets Manager, HashiCorp Vault)
265
+
266
+ ## Troubleshooting
267
+
268
+ ### Token Authentication Fails
269
+
270
+ ```bash
271
+ # Check token is not expired
272
+ loki enterprise token list
273
+
274
+ # Verify token format (should start with "loki_")
275
+ echo $LOKI_TOKEN
276
+
277
+ # Check permissions file exists
278
+ ls -la ~/.loki/dashboard/tokens.json
279
+
280
+ # Verify scopes
281
+ curl -H "Authorization: Bearer $LOKI_TOKEN" \
282
+ http://localhost:57374/api/status -v
283
+ ```
284
+
285
+ ### OIDC Login Fails
286
+
287
+ ```bash
288
+ # Verify issuer URL is reachable
289
+ curl https://accounts.google.com/.well-known/openid-configuration
290
+
291
+ # Check client ID is correct
292
+ echo $LOKI_OIDC_CLIENT_ID
293
+
294
+ # View authentication logs
295
+ loki enterprise audit tail --event auth.fail
296
+
297
+ # Check redirect URI is whitelisted in identity provider
298
+ # Should be: http://localhost:57374/auth/oidc/callback
299
+ ```
300
+
301
+ ### Permissions Denied
302
+
303
+ ```bash
304
+ # Check token scopes
305
+ loki enterprise token list
306
+
307
+ # Verify required scope for endpoint
308
+ # /api/status -> read
309
+ # /api/control/start -> control
310
+ # /api/tasks/create -> write
311
+
312
+ # Generate new token with correct scopes
313
+ loki enterprise token generate new-token --scopes "read,write,control"
314
+ ```
315
+
316
+ ## Examples
317
+
318
+ ### CI/CD Integration
319
+
320
+ ```yaml
321
+ # .github/workflows/loki.yml
322
+ name: Loki Mode
323
+ on: [push]
324
+ jobs:
325
+ deploy:
326
+ runs-on: ubuntu-latest
327
+ steps:
328
+ - uses: actions/checkout@v4
329
+ - name: Run Loki Mode
330
+ env:
331
+ LOKI_TOKEN: ${{ secrets.LOKI_TOKEN }}
332
+ run: |
333
+ curl -H "Authorization: Bearer $LOKI_TOKEN" \
334
+ -X POST \
335
+ -d '{"prd": "./prd.md"}' \
336
+ http://loki-server:57374/api/control/start
337
+ ```
338
+
339
+ ### Python Client
340
+
341
+ ```python
342
+ import requests
343
+
344
+ class LokiClient:
345
+ def __init__(self, base_url, token):
346
+ self.base_url = base_url
347
+ self.headers = {"Authorization": f"Bearer {token}"}
348
+
349
+ def get_status(self):
350
+ response = requests.get(
351
+ f"{self.base_url}/api/status",
352
+ headers=self.headers
353
+ )
354
+ return response.json()
355
+
356
+ def start_session(self, prd_file):
357
+ response = requests.post(
358
+ f"{self.base_url}/api/control/start",
359
+ json={"prd": prd_file},
360
+ headers=self.headers
361
+ )
362
+ return response.json()
363
+
364
+ client = LokiClient("http://localhost:57374", "loki_xxx...")
365
+ status = client.get_status()
366
+ print(status)
367
+ ```
368
+
369
+ ## See Also
370
+
371
+ - [Authorization Guide](authorization.md) - RBAC and permissions
372
+ - [Network Security](network-security.md) - TLS/HTTPS setup
373
+ - [Audit Logging](audit-logging.md) - Authentication event tracking
374
+ - [Enterprise Features](../wiki/Enterprise-Features.md) - Complete enterprise guide