rustberg 0.0.5

A production-grade, cross-platform, single-binary Apache Iceberg REST Catalog
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
---
layout: default
title: Authorization
nav_order: 4
description: "Authorization with Cedar policies: RBAC, ABAC, tenant isolation"
permalink: /docs/authorization
---

# Authorization
{: .no_toc }

Fine-grained access control with Cedar policy engine.
{: .fs-6 .fw-300 }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

---

## Overview

Rustberg uses [Cedar](https://www.cedarpolicy.com/) for authorization:

- **RBAC** - Role-based access control
- **ABAC** - Attribute-based access control
- **Default Deny** - No access without explicit permission
- **Hot Reload** - Update policies without restart
- **Audit Trail** - Every decision is logged

---

## Cedar Basics

### Policy Structure

```cedar
permit(
    principal == User::"alice",
    action == Action::"read",
    resource == Table::"analytics.events"
);
```

### Key Concepts

| Concept | Description | Example |
|---------|-------------|---------|
| **Principal** | Who is requesting | `User::"alice"`, `Role::"data-reader"` |
| **Action** | What they want to do | `Action::"read"`, `Action::"write"` |
| **Resource** | What they want to access | `Table::"analytics.events"` |
| **Context** | Additional attributes | `context.ip_address` |

---

## Built-in Actions

| Action | Description | Applies To |
|--------|-------------|------------|
| `list` | List resources | Namespaces, Tables, Views |
| `read` | Read metadata | Namespaces, Tables, Views |
| `write` | Create/update | Namespaces, Tables, Views |
| `delete` | Delete resources | Namespaces, Tables, Views |
| `admin` | Administrative ops | All resources |

---

## Policy Examples

### Role-Based Access (RBAC)

```cedar
// Data readers can list and read all tables
permit(
    principal in Role::"data-reader",
    action in [Action::"list", Action::"read"],
    resource
);

// Data writers can also write
permit(
    principal in Role::"data-writer",
    action in [Action::"list", Action::"read", Action::"write"],
    resource
);

// Admins have full access
permit(
    principal in Role::"admin",
    action,
    resource
);
```

### Tenant Isolation

```cedar
// Users can only access resources in their tenant
permit(
    principal,
    action,
    resource
) when {
    principal.tenant_id == resource.tenant_id
};
```

### Namespace-Level Access

```cedar
// Analytics team can access analytics namespace
permit(
    principal in Team::"analytics",
    action,
    resource
) when {
    resource.namespace == "analytics"
};

// Data science team can read all, write to ml namespace
permit(
    principal in Team::"data-science",
    action in [Action::"list", Action::"read"],
    resource
);

permit(
    principal in Team::"data-science",
    action == Action::"write",
    resource
) when {
    resource.namespace == "ml"
};
```

### IP-Based Restrictions

```cedar
// Only allow writes from internal network
permit(
    principal,
    action == Action::"write",
    resource
) when {
    context.ip_address like "10.0.*"
};
```

### Time-Based Access

```cedar
// Allow read access during business hours only
permit(
    principal in Role::"contractor",
    action == Action::"read",
    resource
) when {
    context.hour >= 9 && context.hour < 17
};
```

---

## Configuration

### Policy File

Create a Cedar policy file:

```cedar
// policies/catalog.cedar

// Default deny (implicit, but explicit is clearer)
forbid(principal, action, resource);

// Tenant isolation (required for multi-tenant)
permit(
    principal,
    action,
    resource
) when {
    principal.tenant_id == resource.tenant_id
};

// Role-based permissions
permit(
    principal in Role::"admin",
    action,
    resource
);

permit(
    principal in Role::"data-reader",
    action in [Action::"list", Action::"read"],
    resource
);

permit(
    principal in Role::"data-writer",
    action in [Action::"list", Action::"read", Action::"write"],
    resource
);
```

### TOML Configuration

```toml
[authorization]
engine = "cedar"
policy_file = "/etc/rustberg/policies/catalog.cedar"
hot_reload = true
hot_reload_interval_secs = 30
```

### Programmatic

```rust
use rustberg::auth::CedarAuthorizer;

let authorizer = CedarAuthorizer::from_file("policies/catalog.cedar")?;

// Or from string
let policy = r#"
permit(
    principal in Role::"admin",
    action,
    resource
);
"#;
let authorizer = CedarAuthorizer::from_policy_string(policy)?;
```

---

## Entity Types

### Principal Types

```cedar
// User (from API key or JWT)
User::"alice@example.com"

// Role (assigned via API key or JWT claim)
Role::"data-reader"

// Team (from JWT claim or mapping)
Team::"analytics"

// Service (machine identity)
Service::"spark-etl"
```

### Resource Types

```cedar
// Namespace
Namespace::"analytics"

// Table (namespace.table format)
Table::"analytics.events"

// View
View::"analytics.daily_summary"

// Snapshot
Snapshot::"analytics.events:1234567890"
```

---

## Principal Attributes

Available attributes on the principal:

| Attribute | Type | Description |
|-----------|------|-------------|
| `tenant_id` | String | Tenant identifier |
| `roles` | Set | Assigned roles |
| `email` | String | User email (JWT) |
| `groups` | Set | Group memberships |

### Example

```cedar
permit(
    principal,
    action,
    resource
) when {
    principal.tenant_id == "acme-corp" &&
    "admin" in principal.roles
};
```

---

## Resource Attributes

Available attributes on resources:

| Attribute | Type | Description |
|-----------|------|-------------|
| `tenant_id` | String | Owning tenant |
| `namespace` | String | Parent namespace |
| `created_by` | String | Creator principal |
| `tags` | Set | Custom tags |

### Example

```cedar
// Only creators can delete their tables
permit(
    principal,
    action == Action::"delete",
    resource
) when {
    principal == resource.created_by
};
```

---

## Context Attributes

Request context available in policies:

| Attribute | Type | Description |
|-----------|------|-------------|
| `ip_address` | String | Client IP |
| `user_agent` | String | HTTP User-Agent |
| `request_id` | String | Unique request ID |
| `timestamp` | Long | Request time (epoch) |
| `hour` | Long | Hour of day (0-23) |

---

## Hot Reloading

Policies can be updated without restart:

```toml
[authorization]
hot_reload = true
hot_reload_interval_secs = 30
```

When enabled:
1. Rustberg watches the policy file
2. On change, policies are recompiled
3. New policies take effect immediately
4. Invalid policies are rejected (old policies continue)

### Manual Reload

```bash
# Send SIGHUP to reload policies
kill -HUP $(pgrep rustberg)
```

---

## Audit Logging

Every authorization decision is logged:

### Permit

```json
{
  "timestamp": "2026-01-24T12:00:00Z",
  "event": "authz_permit",
  "principal": "alice@example.com",
  "action": "read",
  "resource": "Table::analytics.events",
  "policy": "data-reader-access",
  "duration_us": 45
}
```

### Deny

```json
{
  "timestamp": "2026-01-24T12:00:01Z",
  "event": "authz_deny",
  "principal": "bob@example.com",
  "action": "delete",
  "resource": "Table::analytics.events",
  "reason": "no matching permit policy",
  "duration_us": 23
}
```

---

## Best Practices

### 1. Start with Deny-All

```cedar
// Explicit deny-all (good for documentation)
forbid(principal, action, resource)
unless {
    // Explicit permits below will override
    false
};
```

### 2. Enforce Tenant Isolation

```cedar
// ALWAYS include tenant check
permit(principal, action, resource)
when {
    principal.tenant_id == resource.tenant_id
};
```

### 3. Use Roles, Not Users

```cedar
// ❌ Bad: User-specific policy
permit(principal == User::"alice", action, resource);

// ✅ Good: Role-based policy
permit(principal in Role::"admin", action, resource);
```

### 4. Principle of Least Privilege

```cedar
// ❌ Bad: Broad permissions
permit(principal in Role::"user", action, resource);

// ✅ Good: Specific permissions
permit(
    principal in Role::"user",
    action in [Action::"list", Action::"read"],
    resource
);
```

### 5. Log and Monitor

- Enable audit logging
- Alert on unusual deny patterns
- Review policies regularly

---

## Troubleshooting

### "403 Forbidden" Errors

1. Check the audit log for the deny reason
2. Verify the principal has correct roles
3. Ensure tenant_id matches
4. Test the policy in isolation:

```bash
# Use Cedar CLI to test policies
cedar evaluate \
  --policies policies/catalog.cedar \
  --principal 'User::"alice"' \
  --action 'Action::"read"' \
  --resource 'Table::"analytics.events"'
```

### Policy Syntax Errors

```bash
# Validate policy syntax
cedar validate --policies policies/catalog.cedar
```

### Performance Issues

Cedar policies are compiled and cached. If you have thousands of policies:

1. Consolidate similar policies
2. Use attribute-based rules instead of explicit lists
3. Consider policy sharding by tenant

---

## Next Steps

- [Authentication Guide]/rustberg/docs/authentication - How principals are identified
- [API Reference]/rustberg/docs/api - Endpoint permissions
- [Security Model]/rustberg/docs/security - Defense in depth