docs(operations): document token bootstrapping and core update policy in cutover runbook (#23)
Core Architecture & Invariant CI / validate (pull_request) Failing after 1m2s
Core Architecture & Invariant CI / validate (pull_request) Failing after 1m2s
This commit was merged in pull request #27.
This commit is contained in:
1 parent
4622392ca5
commit
1fea9024f1
1 file changed
+96
-18
+96
-18
@@ -145,9 +145,8 @@ appctl restart docs
|
|||||||
appctl restart traefik
|
appctl restart traefik
|
||||||
appctl restart authelia
|
appctl restart authelia
|
||||||
|
|
||||||
# Sequential stack update (clean working tree check -> git pull -> compose pull -> up -> sync)
|
# Sequential stack update for independent Sites workloads (clean tree check -> git pull -> compose pull -> up -> sync)
|
||||||
appctl update docs
|
appctl update docs
|
||||||
appctl update core
|
|
||||||
|
|
||||||
# Stream live container logs
|
# Stream live container logs
|
||||||
appctl logs docs
|
appctl logs docs
|
||||||
@@ -157,6 +156,37 @@ appctl logs -f stalwart
|
|||||||
appctl config docs
|
appctl config docs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Workload vs. Core Update Policy
|
||||||
|
|
||||||
|
Homelab enforces a strict architectural boundary between independent application workloads (`~/Sites/<app>`) and Homelab Core (`~/Core`):
|
||||||
|
|
||||||
|
#### 1. Independent Sites Workloads (`~/Sites/<app>`)
|
||||||
|
- **Automated Lifecycle**: Workloads declare their lifecycle via `app.yaml` manifests and Compose definitions.
|
||||||
|
- **Update Command**: `appctl update <workload>` performs pre-flight verification, branch matching, `git pull --ff-only`, container image pull, stack reload, and dashboard synchronization.
|
||||||
|
- **GitOps Webhook Dispatch**: Workloads registered in `config/deployments.yaml` can be triggered automatically via authenticated GitOps webhooks on Gitea push events.
|
||||||
|
- **Daemon Permissions**: `homelab-appctl.service` holds read-write permissions over `~/Sites` to manage files, compose configurations, and workload state.
|
||||||
|
|
||||||
|
#### 2. Homelab Core Platform Stack (`~/Core`)
|
||||||
|
- **Host Foundation & Invariant Boundary**: Core defines NixOS host definitions, platform secrets, edge ingress, and security sandboxes.
|
||||||
|
- **No Untrusted Webhooks**: Core does **not** register for webhook dispatch in `config/deployments.yaml`. External push events can never trigger an automated deployment or rebuild of Core.
|
||||||
|
- **Read-Only Sandbox**: Under NixOS systemd sandboxing (`ProtectHome = "read-only"`), `homelab-appctl.service` has strictly read-only access to `/home/operator/Core`. The daemon cannot mutate the Core Git repository or run `git pull` on Core.
|
||||||
|
- **Operator-Driven Update Workflow**: Core updates must be executed explicitly by the operator:
|
||||||
|
1. Review and pull repository changes:
|
||||||
|
```bash
|
||||||
|
cd ~/Core && git pull --ff-only
|
||||||
|
```
|
||||||
|
2. If NixOS modules or secrets changed, evaluate and activate the new system generation:
|
||||||
|
```bash
|
||||||
|
sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure
|
||||||
|
```
|
||||||
|
3. If Compose definitions changed, restart the platform stack:
|
||||||
|
```bash
|
||||||
|
docker compose up -d --remove-orphans
|
||||||
|
# or via systemd:
|
||||||
|
sudo systemctl restart homeserver-core
|
||||||
|
```
|
||||||
|
4. Individual platform services can be restarted via appctl using an authenticated admin token (`appctl restart traefik`, `appctl restart authelia`).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 4. User Identity & Access Management (LLDAP & Authelia)
|
## 4. User Identity & Access Management (LLDAP & Authelia)
|
||||||
@@ -437,7 +467,51 @@ Activate the declarative configuration under the `operator` profile:
|
|||||||
chmod 600 /home/operator/Core/nixos/instance.nix
|
chmod 600 /home/operator/Core/nixos/instance.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Rebuild NixOS host configuration**:
|
2. **Bootstrap appctl control plane tokens (CR-SO-08)**:
|
||||||
|
The `homelab-appctl.service` control plane daemon enforces 3-role RBAC (`homelab-admin`, `homelab-operator`, `homelab-viewer`) authenticated via SHA-256 Bearer tokens stored in `/run/secrets/appctl/tokens.json`.
|
||||||
|
|
||||||
|
Generate the operator administrator token and local CLI credentials:
|
||||||
|
```bash
|
||||||
|
sudo -u operator python3 /home/operator/Core/scripts/bootstrap_token.py
|
||||||
|
```
|
||||||
|
This command:
|
||||||
|
- Creates `~/.config/homelab/token` (mode `0600`) owned by `operator:homelab-operators` containing the raw Bearer token used automatically by the `appctl` CLI.
|
||||||
|
- Outputs the JSON token descriptor containing the SHA-256 digest:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"token_id": "operator-admin",
|
||||||
|
"identity": "operator",
|
||||||
|
"role": "homelab-admin",
|
||||||
|
"sha256": "<64-character-sha256-digest>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> **Unprovisioned Token Behavior & RBAC Fallback**:
|
||||||
|
> If tokens are not provisioned in `/run/secrets/appctl/tokens.json`, local UDS connections (`/run/homelab/appctl.sock`) fall back to Linux `SO_PEERCRED` socket credentials, granting callers in `homelab-operators` the read-only `homelab-viewer` role.
|
||||||
|
> Under `homelab-viewer`, safe queries succeed (`appctl list`, `appctl status`, `appctl health`).
|
||||||
|
> However, **all mutating and privileged operations** (`appctl up`, `appctl down`, `appctl restart`, `appctl update`, `appctl deploy`, `appctl config`, `appctl info`) **strictly require** a valid Bearer token with `homelab-operator` or `homelab-admin` role. If tokens are not enrolled in SOPS, attempting mutating actions fails with HTTP 403 `ERR_PERMISSION_DENIED`.
|
||||||
|
|
||||||
|
Enroll the token descriptor into SOPS secrets:
|
||||||
|
```bash
|
||||||
|
sops /home/operator/Core/nixos/secrets.yaml
|
||||||
|
```
|
||||||
|
Under `appctl.tokens_json`, insert the descriptor into the JSON array:
|
||||||
|
```yaml
|
||||||
|
appctl:
|
||||||
|
tokens_json: |
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"token_id": "operator-admin",
|
||||||
|
"identity": "operator",
|
||||||
|
"role": "homelab-admin",
|
||||||
|
"sha256": "<paste-sha256-digest-here>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
*(Optional: If GitOps webhook dispatch is enabled, generate and enroll a `gitops-webhook` token with `homelab-operator` role using `python3 scripts/bootstrap_token.py --identity gitops --role homelab-operator --token-id gitops-webhook --print-json`).*
|
||||||
|
|
||||||
|
3. **Rebuild NixOS host configuration**:
|
||||||
Execute the rebuild from the new canonical Core path using `--impure` and the `path:` scheme to import the untracked instance profile:
|
Execute the rebuild from the new canonical Core path using `--impure` and the `path:` scheme to import the untracked instance profile:
|
||||||
```bash
|
```bash
|
||||||
cd /home/operator/Core
|
cd /home/operator/Core
|
||||||
@@ -445,10 +519,10 @@ Activate the declarative configuration under the `operator` profile:
|
|||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> The `path:` scheme instructs Nix to evaluate directly from the filesystem without filtering by the Git index, ensuring untracked/gitignored `nixos/instance.nix` is evaluated. (If using `/etc/nixos/homelab-instance.nix`, bare `--flake .#server --impure` works directly).
|
> The `path:` scheme instructs Nix to evaluate directly from the filesystem without filtering by the Git index, ensuring untracked/gitignored `nixos/instance.nix` is evaluated. (If using `/etc/nixos/homelab-instance.nix`, bare `--flake .#server --impure` works directly). Rebuilding also decrypts and projects `/run/secrets/appctl/tokens.json` via `sops-nix`.
|
||||||
|
|
||||||
3. **Restart platform services**:
|
4. **Restart platform services**:
|
||||||
Restart the Core Compose stack and control plane services to consume updated paths:
|
Restart the Core Compose stack and control plane services to consume updated paths and secrets:
|
||||||
```bash
|
```bash
|
||||||
sudo systemctl restart homeserver-core
|
sudo systemctl restart homeserver-core
|
||||||
sudo systemctl restart homelab-appctl
|
sudo systemctl restart homelab-appctl
|
||||||
@@ -467,22 +541,26 @@ Validate system health and operational readiness under the `operator` identity:
|
|||||||
sudo -u operator git -C /home/operator/Sites/<any-workload> status
|
sudo -u operator git -C /home/operator/Sites/<any-workload> status
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Verify appctl control plane status**:
|
2. **Verify SOPS secrets and tokens projection**:
|
||||||
Execute CLI inspection using both UDS peercred authentication and token authentication:
|
Ensure `/run/secrets/appctl/tokens.json` is readable by `homelab-appctl` (mode `0400`, owned by `homelab-appctl:homelab-operators`) and contains valid descriptors:
|
||||||
```bash
|
|
||||||
# Peercred UDS inspection
|
|
||||||
sudo -u operator appctl list --core
|
|
||||||
|
|
||||||
# Workload health check
|
|
||||||
sudo -u operator appctl status
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Verify SOPS secrets and tokens**:
|
|
||||||
Ensure `/run/secrets/appctl/tokens.json` is readable by `homelab-appctl` and valid tokens exist for operator administration:
|
|
||||||
```bash
|
```bash
|
||||||
sudo ls -l /run/secrets/appctl/tokens.json
|
sudo ls -l /run/secrets/appctl/tokens.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
3. **Verify appctl control plane status & RBAC authentication**:
|
||||||
|
Execute CLI inspection using both UDS peercred authentication (read-only viewer fallback) and authenticated admin token operations:
|
||||||
|
```bash
|
||||||
|
# 1. Peercred UDS inspection (demonstrates viewer fallback for read-only actions)
|
||||||
|
sudo -u operator appctl list --core
|
||||||
|
sudo -u operator appctl status
|
||||||
|
sudo -u operator appctl health
|
||||||
|
|
||||||
|
# 2. Authenticated operator admin verification (requires homelab-admin Bearer token)
|
||||||
|
sudo -u operator appctl info docs
|
||||||
|
sudo -u operator appctl config docs
|
||||||
|
```
|
||||||
|
Confirm that `info` and `config` return resolved configuration without `ERR_PERMISSION_DENIED`, verifying that `~/.config/homelab/token` matches the provisioned SHA-256 digest in `/run/secrets/appctl/tokens.json`.
|
||||||
|
|
||||||
4. **Verify container reachability & proxy routing**:
|
4. **Verify container reachability & proxy routing**:
|
||||||
Check that external endpoints and internal reverse proxies resolve:
|
Check that external endpoints and internal reverse proxies resolve:
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
Reference in new issue
Block a user