rustberg 0.0.2

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
# Rustberg

<p align="center">
  <strong>A production-grade, cross-platform, single-binary Apache Iceberg REST Catalog server written in Rust.</strong>
</p>

<p align="center">
  <a href="https://hupe1980.github.io/rustberg">Documentation</a> β€’
  <a href="#quick-start">Quick Start</a> β€’
  <a href="#features">Features</a> β€’
  <a href="https://hupe1980.github.io/rustberg/docs/security">Security</a> β€’
  <a href="https://hupe1980.github.io/rustberg/docs/api">API</a>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/tests-460%20passing-brightgreen" alt="Tests">
  <img src="https://img.shields.io/badge/clippy-0%20warnings-brightgreen" alt="Clippy">
  <img src="https://img.shields.io/badge/memory-~9MB-blue" alt="Memory">
  <img src="https://img.shields.io/badge/binary-7.4MB-blue" alt="Binary Size">
  <img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License">
</p>

---

## Why Rustberg?

**Rustberg** is a production-grade Apache Iceberg REST Catalog designed for simplicity and performance:

### Core Capabilities

- πŸš€ **Instant Startup** β€” Sub-10ms cold start, ready immediately
- πŸ“¦ **Single Binary** β€” No JVM, no PostgreSQL, no external services required
- πŸ” **Security First** β€” TLS 1.3, API keys, JWT/OIDC, Cedar policies, AES-256-GCM encryption
- ☸️ **Kubernetes Native** β€” SlateDB on S3/GCS/Azure for horizontal scaling
- 🌍 **Cross-Platform** β€” Linux, macOS, Windows with first-class support
- πŸ“‹ **Full Iceberg REST API** β€” Tables, views, namespaces, transactions, credential vending

---

## Quick Start

### Option 1: Pre-built Binaries

```bash
# Linux (x86_64)
curl -L https://github.com/hupe1980/rustberg/releases/latest/download/rustberg-linux-x86_64 -o rustberg

# Linux (ARM64)
curl -L https://github.com/hupe1980/rustberg/releases/latest/download/rustberg-linux-aarch64 -o rustberg

# macOS (Apple Silicon)
curl -L https://github.com/hupe1980/rustberg/releases/latest/download/rustberg-darwin-aarch64 -o rustberg

# Make executable and run
chmod +x rustberg
./rustberg
```

### Option 2: Docker

```bash
# Start Rustberg
docker run -d -p 8181:8181 --name rustberg \
  -e RUSTBERG_INSECURE_HTTP=true \
  ghcr.io/hupe1980/rustberg:latest

# Verify it's running
curl http://localhost:8181/health

# Create a namespace
curl -X POST http://localhost:8181/v1/namespaces \
  -H "Content-Type: application/json" \
  -d '{"namespace": ["my_namespace"]}'
```

### Option 3: Helm Chart (Kubernetes)

```bash
# Clone repository
git clone https://github.com/hupe1980/rustberg
cd rustberg

# Install with Helm
helm install rustberg charts/rustberg \
  --set rustberg.storage.type=s3 \
  --set rustberg.storage.s3.bucket=my-catalog-bucket

# Or with custom values
helm install rustberg charts/rustberg -f my-values.yaml
```

### Option 4: Build from Source

Requires **Rust 1.89+** ([install](https://rustup.rs/))

```bash
# Clone and build
git clone https://github.com/hupe1980/rustberg
cd rustberg
cargo build --release --all-features

# Generate TLS certificate (development)
./target/release/rustberg generate-cert

# Start server
./target/release/rustberg --tls-cert server.crt --tls-key server.key
```

---

## Features

### Core Iceberg API

- βœ… **Namespace CRUD** - Create, list, update, delete namespaces
- βœ… **Table CRUD** - Full table lifecycle management
- βœ… **Table Commits** - Optimistic concurrency with requirements
- βœ… **Register Table** - Import existing tables from metadata location
- βœ… **Multi-table Transactions** - Atomic commits across multiple tables
- βœ… **Metrics Reporting** - Client telemetry collection
- βœ… **Credential Vending** - AWS STS + GCS + Azure temporary credentials
- βœ… **Pagination** - Cursor-based with configurable page size
- βœ… **Idempotency** - Request deduplication via idempotency keys

### Security

- βœ… **API Key Authentication** - Argon2id hashed, constant-time validation
- βœ… **JWT/OIDC Authentication** - JWKS validation, configurable claims
- βœ… **Cedar Policy Authorization** - Fine-grained ABAC beyond simple RBAC
- βœ… **Multi-Tenancy** - Hard isolation between tenants
- βœ… **Rate Limiting** - Token bucket per IP/tenant
- βœ… **Encryption at Rest** - AES-256-GCM with envelope encryption + AWS KMS
- βœ… **TLS/HTTPS** - TLS 1.2/1.3 via rustls
- βœ… **Security Headers** - CSP, X-Frame-Options, X-Content-Type-Options
- βœ… **CORS Support** - Configurable cross-origin resource sharing
- βœ… **Audit Logging** - Structured JSON for SIEM

### Operations

- βœ… **Health Checks** - `/health` and `/ready` endpoints
- βœ… **Metrics** - Prometheus-compatible `/metrics` with 25+ counters
- βœ… **Request Tracing** - X-Request-Id propagation for distributed tracing
- βœ… **Response Compression** - Gzip/deflate/brotli automatic compression
- βœ… **Graceful Shutdown** - SIGTERM handling with connection drain
- βœ… **Backup/Restore** - CLI commands for disaster recovery
- βœ… **TOML Configuration** - File-based config with env override

---

## Security

### Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         SECURITY LAYERS                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  TLS 1.2/1.3 (rustls)                           Transport Security  β”‚
β”‚  β”œβ”€β”€ Rate Limiting (token bucket)               DoS Protection      β”‚
β”‚  β”œβ”€β”€ Request Size Limits (10MB)                 Resource Protection β”‚
β”‚  β”œβ”€β”€ Request Timeouts (30s)                     Hang Protection     β”‚
β”‚  β”œβ”€β”€ Security Headers (CSP, X-Frame-Options)    Browser Security    β”‚
β”‚  β”œβ”€β”€ X-Request-Id Tracing                       Distributed Tracing β”‚
β”‚  β”œβ”€β”€ CORS Middleware                            Cross-Origin Policy β”‚
β”‚  β”œβ”€β”€ API Key / JWT Authentication               Identity            β”‚
β”‚  β”œβ”€β”€ Cedar Policy Authorization                 Access Control      β”‚
β”‚  β”œβ”€β”€ Input Validation                           Injection Defense   β”‚
β”‚  β”œβ”€β”€ Audit Logging                              Forensics           β”‚
β”‚  └── AES-256-GCM Encryption                     Data at Rest        β”‚
β”‚      └── KMS (env/AWS/Vault) + Circuit Breaker  Key Management      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Authentication

```bash
# Generate an API key
rustberg generate-key --name admin --roles admin,writer

# Use the key
curl -H "X-API-Key: rb_abc123..." https://localhost:8000/v1/namespaces
```

### Authorization (Cedar Policies)

```cedar
// Allow readers to list namespaces
permit(
  principal,
  action == Action::"ListNamespaces",
  resource
) when {
  principal.roles.contains("reader")
};

// Deny cross-tenant access
forbid(
  principal,
  action,
  resource
) when {
  principal.tenant_id != resource.tenant_id
};
```

---

## API

### Endpoints

| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/health` | Liveness check |
| `GET` | `/ready` | Readiness check with dependencies |
| `GET` | `/metrics` | Prometheus metrics |
| `GET` | `/v1/config` | Catalog configuration |
| `GET` | `/v1/namespaces` | List namespaces |
| `POST` | `/v1/namespaces` | Create namespace |
| `GET` | `/v1/namespaces/{ns}` | Get namespace |
| `POST` | `/v1/namespaces/{ns}` | Update namespace |
| `DELETE` | `/v1/namespaces/{ns}` | Delete namespace |
| `GET` | `/v1/namespaces/{ns}/tables` | List tables |
| `POST` | `/v1/namespaces/{ns}/tables` | Create table |
| `POST` | `/v1/namespaces/{ns}/register` | Register existing table |
| `GET` | `/v1/namespaces/{ns}/tables/{table}` | Load table |
| `DELETE` | `/v1/namespaces/{ns}/tables/{table}` | Drop table |
| `POST` | `/v1/namespaces/{ns}/tables/{table}` | Commit table update |
| `HEAD` | `/v1/namespaces/{ns}/tables/{table}` | Check table exists |
| `POST` | `/v1/namespaces/{ns}/tables/{table}/metrics` | Report metrics |
| `POST` | `/v1/tables/rename` | Rename table |
| `POST` | `/v1/transactions/commit` | Multi-table transaction |

### Example: Create a Table

```bash
curl -X POST https://localhost:8000/v1/namespaces/my_ns/tables \
  -H "Content-Type: application/json" \
  -H "X-API-Key: rb_abc123..." \
  -d '{
    "name": "my_table",
    "schema": {
      "type": "struct",
      "fields": [
        {"id": 1, "name": "id", "type": "long", "required": true},
        {"id": 2, "name": "data", "type": "string", "required": false}
      ]
    }
  }'
```

---

## Configuration

### TOML Configuration File

```toml
# rustberg.toml

[server]
host = "0.0.0.0"
port = 8000

[server.auth]
api_key_enabled = true
jwt_enabled = false

[tls]
enabled = true
cert_path = "/etc/rustberg/tls/cert.pem"
key_path = "/etc/rustberg/tls/key.pem"

[storage]
# Single-node (local storage)
backend = "file:///var/lib/rustberg/data"

# K8s HA (S3-compatible)
# backend = "s3://rustberg-bucket/catalog?region=us-east-1"

[kms]
provider = "env"  # or "aws-kms", "vault"
cache_ttl_seconds = 300
circuit_breaker_enabled = true

[rate_limit]
enabled = true
requests_per_second = 100
burst_size = 200

[logging]
level = "info"
json_format = false
```

### Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `RUSTBERG_HOST` | `0.0.0.0` | Bind address |
| `RUSTBERG_PORT` | `8000` | Bind port |
| `RUSTBERG_WAREHOUSE` | - | Warehouse location |
| `RUSTBERG_TENANT_ID` | `default` | Default tenant |
| `RUSTBERG_NO_AUTH` | `false` | Disable authentication (dev only) |
| `RUSTBERG_TLS_CERT` | - | TLS certificate path |
| `RUSTBERG_TLS_KEY` | - | TLS key path |
| `RUSTBERG_INSECURE_HTTP` | `false` | Allow HTTP (dev only) |
| `RUSTBERG_MASTER_KEY` | - | Encryption master key (hex) |
| `RUST_LOG` | `info` | Log level |

---

## Deployment

### Production Checklist

- [ ] TLS enabled with valid certificates
- [ ] Authentication enabled (default - ensure `RUSTBERG_NO_AUTH` is NOT set)
- [ ] Master key stored securely (KMS recommended)
- [ ] Rate limiting configured appropriately
- [ ] Audit logging to persistent storage
- [ ] Health checks configured in orchestrator
- [ ] Backup schedule established

### Kubernetes

Rustberg supports both single-node (with PVC) and highly-available (with S3) deployments:

#### Single-Node (PVC Storage)

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rustberg
spec:
  replicas: 1  # Single node only with file:// storage
  template:
    spec:
      containers:
        - name: rustberg
          image: ghcr.io/hupe1980/rustberg:latest
          ports:
            - containerPort: 8000
          env:
            - name: STORAGE_BACKEND
              value: "file:///var/lib/rustberg/data"
            - name: RUSTBERG_MASTER_KEY
              valueFrom:
                secretKeyRef:
                  name: rustberg-secrets
                  key: master-key
          volumeMounts:
            - name: data
              mountPath: /var/lib/rustberg/data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: rustberg-data
```

#### High-Availability (S3/GCS/MinIO)

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rustberg
spec:
  replicas: 3  # Multiple replicas with shared S3 storage
  template:
    spec:
      containers:
        - name: rustberg
          image: ghcr.io/hupe1980/rustberg:latest
          ports:
            - containerPort: 8000
          env:
            - name: STORAGE_BACKEND
              value: "s3://rustberg-bucket/catalog?region=us-east-1"
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  name: rustberg-secrets
                  key: aws-access-key
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: rustberg-secrets
                  key: aws-secret-key
            - name: RUSTBERG_MASTER_KEY
              valueFrom:
                secretKeyRef:
                  name: rustberg-secrets
                  key: master-key
          livenessProbe:
            httpGet:
              path: /health
              port: 8000
            initialDelaySeconds: 5
          readinessProbe:
            httpGet:
              path: /ready
              port: 8000
            initialDelaySeconds: 5
```

### Backup & Restore

```bash
# Create backup
rustberg backup --output /backup/rustberg-$(date +%Y%m%d).tar.gz

# Validate backup
rustberg validate-backup --input /backup/rustberg-20260123.tar.gz

# Restore (stops server first!)
rustberg restore --input /backup/rustberg-20260123.tar.gz --force
```

---

## CLI Reference

```bash
# Start server
rustberg [OPTIONS]

# Generate API key
rustberg generate-key --name <NAME> --tenant <TENANT> --roles <ROLES>

# Generate TLS certificate (development)
rustberg generate-cert --common-name localhost --output-dir /tmp/tls

# Generate sample configuration file
rustberg generate-config --output config.toml

# Generate OpenAPI specification
rustberg open-api --format yaml --output openapi.yaml

# Backup catalog
rustberg backup --output <FILE> --data-dir <DIR>

# Restore catalog
rustberg restore --input <FILE> --data-dir <DIR> [--force]

# Validate backup
rustberg validate-backup --input <FILE>

# Show status
rustberg status --data-dir <DIR>

# Run performance benchmark
rustberg benchmark --iterations 10
```

---

## Engine Compatibility

| Engine | Read | Write | Notes |
|--------|------|-------|-------|
| PyIceberg | βœ… | βœ… | Full support |
| Trino | βœ… | βœ… | Full support |
| DuckDB | βœ… | - | Read-only |

---

## Development

```bash
# Run tests
cargo test --all-features

# Run with debug logging
RUST_LOG=debug cargo run --all-features -- --insecure-http

# Format code
cargo fmt

# Lint
cargo clippy --all-features
```

---

## License

Apache License 2.0