summaryrefslogtreecommitdiff
path: root/docs/handbook/ofborg/configuration.md
blob: 143ac75f8e6091ad78a5bb4f44ee4fe320d18a5d (plain)
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
# Tickborg — Configuration Reference

## Overview

Tickborg is configured via a single JSON file, typically located at
`config.json` or specified via the `CONFIG_PATH` environment variable.
The file maps to the top-level `Config` struct in `tickborg/src/config.rs`.

---

## Loading Configuration

```rust
// config.rs
pub fn load() -> Config {
    let config_path = env::var("CONFIG_PATH")
        .unwrap_or_else(|_| "config.json".to_owned());

    let config_str = std::fs::read_to_string(&config_path)
        .unwrap_or_else(|e| panic!("Failed to read config file {config_path}: {e}"));

    serde_json::from_str(&config_str)
        .unwrap_or_else(|e| panic!("Failed to parse config file {config_path}: {e}"))
}
```

---

## Top-Level `Config`

```rust
#[derive(Deserialize, Debug)]
pub struct Config {
    pub identity: String,
    pub rabbitmq: RabbitMqConfig,
    pub github_app: Option<GithubAppConfig>,

    // Per-service configs — only the relevant one needs to be present
    pub github_webhook: Option<GithubWebhookConfig>,
    pub log_api: Option<LogApiConfig>,
    pub evaluation_filter: Option<EvaluationFilterConfig>,
    pub mass_rebuilder: Option<MassRebuilderConfig>,
    pub builder: Option<BuilderConfig>,
    pub github_comment_filter: Option<GithubCommentFilterConfig>,
    pub github_comment_poster: Option<GithubCommentPosterConfig>,
    pub log_message_collector: Option<LogMessageCollectorConfig>,
    pub push_filter: Option<PushFilterConfig>,
    pub stats: Option<StatsConfig>,
}
```

### `identity`

A unique string identifying this instance. Used as:
- AMQP consumer tags (`evaluation-filter-{identity}`)
- Exclusive queue names (`build-inputs-{identity}`)
- GitHub Check Run external ID

```json
{
  "identity": "prod-worker-01"
}
```

---

## `RabbitMqConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct RabbitMqConfig {
    pub ssl: bool,
    pub host: String,
    pub vhost: Option<String>,
    pub username: String,
    pub password_file: PathBuf,
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `ssl` | bool | yes | Use `amqps://` instead of `amqp://` |
| `host` | string | yes | RabbitMQ hostname (may include port) |
| `vhost` | string | no | Virtual host (default: `/`) |
| `username` | string | yes | AMQP username |
| `password_file` | path | yes | File containing the password (not the password itself) |

```json
{
  "rabbitmq": {
    "ssl": true,
    "host": "rabbitmq.example.com",
    "vhost": "tickborg",
    "username": "tickborg",
    "password_file": "/run/secrets/rabbitmq-password"
  }
}
```

> **Security**: The password is read from a file rather than stored directly
> in the config, allowing secure credential injection via systemd credentials,
> Docker secrets, or similar mechanisms.

---

## `GithubAppConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct GithubAppConfig {
    pub app_id: u64,
    pub private_key_file: PathBuf,
    pub owner: String,
    pub repo: String,
    pub installation_id: Option<u64>,
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `app_id` | u64 | yes | GitHub App ID |
| `private_key_file` | path | yes | PEM-encoded RSA private key |
| `owner` | string | yes | Repository owner |
| `repo` | string | yes | Repository name |
| `installation_id` | u64 | no | Installation ID (auto-detected if omitted) |

```json
{
  "github_app": {
    "app_id": 12345,
    "private_key_file": "/run/secrets/github-app-key.pem",
    "owner": "project-tick",
    "repo": "Project-Tick",
    "installation_id": 67890
  }
}
```

---

## Service-Specific Configs

### `GithubWebhookConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct GithubWebhookConfig {
    pub bind_address: Option<String>,
    pub port: u16,
    pub webhook_secret: String,
}
```

```json
{
  "github_webhook": {
    "bind_address": "0.0.0.0",
    "port": 8080,
    "webhook_secret": "your-webhook-secret-here"
  }
}
```

### `LogApiConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct LogApiConfig {
    pub bind_address: Option<String>,
    pub port: u16,
    pub log_storage_path: PathBuf,
}
```

```json
{
  "log_api": {
    "port": 8081,
    "log_storage_path": "/var/log/tickborg/builds"
  }
}
```

### `EvaluationFilterConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct EvaluationFilterConfig {
    pub repos: Vec<String>,
}
```

```json
{
  "evaluation_filter": {
    "repos": [
      "project-tick/Project-Tick"
    ]
  }
}
```

### `MassRebuilderConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct MassRebuilderConfig {
    pub checkout: CheckoutConfig,
}
```

```json
{
  "mass_rebuilder": {
    "checkout": {
      "root": "/var/cache/tickborg/checkout"
    }
  }
}
```

### `BuilderConfig` / `RunnerConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct BuilderConfig {
    pub runner: RunnerConfig,
    pub checkout: CheckoutConfig,
    pub build: BuildConfig,
}

#[derive(Deserialize, Debug)]
pub struct RunnerConfig {
    pub identity: Option<String>,
    pub architectures: Vec<String>,
}

#[derive(Deserialize, Debug)]
pub struct BuildConfig {
    pub timeout_seconds: u64,
    pub log_tail_lines: usize,
}

#[derive(Deserialize, Debug)]
pub struct CheckoutConfig {
    pub root: PathBuf,
}
```

```json
{
  "builder": {
    "runner": {
      "identity": "builder-x86_64-linux",
      "architectures": ["x86_64-linux"]
    },
    "checkout": {
      "root": "/var/cache/tickborg/checkout"
    },
    "build": {
      "timeout_seconds": 3600,
      "log_tail_lines": 100
    }
  }
}
```

### `GithubCommentFilterConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct GithubCommentFilterConfig {
    pub repos: Vec<String>,
    pub trusted_users: Option<Vec<String>>,
}
```

```json
{
  "github_comment_filter": {
    "repos": ["project-tick/Project-Tick"],
    "trusted_users": ["maintainer1", "maintainer2"]
  }
}
```

### `LogMessageCollectorConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct LogMessageCollectorConfig {
    pub log_storage_path: PathBuf,
}
```

```json
{
  "log_message_collector": {
    "log_storage_path": "/var/log/tickborg/builds"
  }
}
```

### `StatsConfig`

```rust
#[derive(Deserialize, Debug)]
pub struct StatsConfig {
    pub bind_address: Option<String>,
    pub port: u16,
}
```

```json
{
  "stats": {
    "port": 9090
  }
}
```

---

## Complete Example

Based on `example.config.json`:

```json
{
  "identity": "prod-01",
  "rabbitmq": {
    "ssl": false,
    "host": "localhost",
    "vhost": "tickborg",
    "username": "tickborg",
    "password_file": "/run/secrets/rabbitmq-password"
  },
  "github_app": {
    "app_id": 12345,
    "private_key_file": "/run/secrets/github-app-key.pem",
    "owner": "project-tick",
    "repo": "Project-Tick"
  },
  "github_webhook": {
    "port": 8080,
    "webhook_secret": "change-me"
  },
  "evaluation_filter": {
    "repos": ["project-tick/Project-Tick"]
  },
  "mass_rebuilder": {
    "checkout": {
      "root": "/var/cache/tickborg/checkout"
    }
  },
  "builder": {
    "runner": {
      "architectures": ["x86_64-linux"]
    },
    "checkout": {
      "root": "/var/cache/tickborg/checkout"
    },
    "build": {
      "timeout_seconds": 3600,
      "log_tail_lines": 100
    }
  },
  "github_comment_filter": {
    "repos": ["project-tick/Project-Tick"]
  },
  "log_message_collector": {
    "log_storage_path": "/var/log/tickborg/builds"
  },
  "log_api": {
    "port": 8081,
    "log_storage_path": "/var/log/tickborg/builds"
  },
  "stats": {
    "port": 9090
  }
}
```

---

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `CONFIG_PATH` | `config.json` | Path to the JSON config file |
| `RUST_LOG` | `info` | `tracing` filter directive |
| `RUST_LOG_JSON` | (unset) | Set to `1` for structured JSON log output |

### `RUST_LOG` Examples

```bash
# Default — info for everything
RUST_LOG=info

# Debug for tickborg, info for everything else
RUST_LOG=info,tickborg=debug

# Trace AMQP operations
RUST_LOG=info,tickborg=debug,lapin=trace

# Only errors
RUST_LOG=error
```

### Logging Initialization

```rust
// lib.rs
pub fn setup_log() {
    let json = std::env::var("RUST_LOG_JSON").is_ok();

    let subscriber = tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env());

    if json {
        subscriber.json().init();
    } else {
        subscriber.init();
    }
}
```

---

## ACL Configuration

The ACL (Access Control List) is derived from the configuration and controls:

- **Repository eligibility** — Which repos tickborg responds to
- **Architecture access** — Which platforms a user can build on
- **Unrestricted builds** — Whether a user can bypass project restrictions

```rust
// acl.rs
pub struct Acl {
    repos: Vec<String>,
    trusted_users: Vec<String>,
}

impl Acl {
    pub fn is_repo_eligible(&self, repo: &str) -> bool;
    pub fn build_job_architectures_for_user_repo(
        &self, user: &str, repo: &str
    ) -> Vec<System>;
    pub fn can_build_unrestricted(&self, user: &str, repo: &str) -> bool;
}
```

---

## Secrets Management

Files containing secrets should be readable only by the tickborg service user:

```bash
# RabbitMQ password
echo -n "secret-password" > /run/secrets/rabbitmq-password
chmod 600 /run/secrets/rabbitmq-password

# GitHub App private key
cp github-app.pem /run/secrets/github-app-key.pem
chmod 600 /run/secrets/github-app-key.pem
```

With NixOS and systemd `DynamicUser`, secrets can be placed in
`/run/credentials/tickborg-*` using systemd's `LoadCredential` or
`SetCredential` directives.