Compare commits
5
Commits
main
...
01396bdcce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01396bdcce | ||
|
|
312815525c | ||
|
|
d37c93cdd8 | ||
|
|
288e89edeb | ||
|
|
85f3c1fa41 |
No files matched your search
@@ -0,0 +1,168 @@
|
|||||||
|
---
|
||||||
|
type: knowledge
|
||||||
|
status: stable
|
||||||
|
topics:
|
||||||
|
- engineering-practices
|
||||||
|
- troubleshooting
|
||||||
|
- scientific-method
|
||||||
|
- incident-investigation
|
||||||
|
- observability
|
||||||
|
tags:
|
||||||
|
- methods
|
||||||
|
- operations
|
||||||
|
- postmortem
|
||||||
|
- root-cause-analysis
|
||||||
|
---
|
||||||
|
|
||||||
|
# Scientific Incident Investigation & Epistemic Journaling
|
||||||
|
|
||||||
|
This document establishes the canonical engineering methodology for investigating complex system failures and authoring durable, reproducible incident journals.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Epistemological Foundation: Investigation as Science
|
||||||
|
|
||||||
|
In complex distributed systems, post-incident documentation often suffers from two opposing failure modes:
|
||||||
|
1. **The Superficial Summary**: Merely recording the declarative fix without explaining how the failure was diagnosed, which teaches the reader almost nothing about system behavior.
|
||||||
|
2. **The Fictionalized Postmortem (Hindsight Bias)**: Reconstructing the investigation as a neat, linear narrative that pretends the root cause was obvious from the beginning.
|
||||||
|
|
||||||
|
The **Epistemic Investigation Method** treats system troubleshooting as an empirical scientific inquiry. Its goal is to preserve and communicate the **reasoning process** used to narrow down an unfamiliar failure, transforming an operational outage into durable engineering intuition.
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 1. Raw Observations │
|
||||||
|
│ (Terminal dumps, logs, error codes) │
|
||||||
|
└────────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 2. Diagnostic Inquiries │
|
||||||
|
│ (What questions narrow down the failure space?) │
|
||||||
|
└────────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 3. Hypothesis Formulation │
|
||||||
|
│ (What causal models could produce these symptoms?) │
|
||||||
|
└────────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 4. Discriminating Tests │
|
||||||
|
│ (Commands designed to falsify specific hypotheses) │
|
||||||
|
└────────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 5. Root Cause Demonstration │
|
||||||
|
│ (Connecting proven evidence to mechanism) │
|
||||||
|
└────────────────────────────┬────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────────────────────────────────┐
|
||||||
|
│ 6. Generalization & Transferable Rules │
|
||||||
|
│ (Abstracting architectural and diagnostic heuristics)│
|
||||||
|
└─────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Core Epistemic Principles
|
||||||
|
|
||||||
|
### A. Observation vs. Inference
|
||||||
|
A fundamental discipline of scientific investigation is strictly separating raw evidence from deductive interpretations:
|
||||||
|
|
||||||
|
* **Observation (Machine Output)**: What the system literally produced (e.g. `webhook logged: Signature mismatch`, `status code 403`, `db column secret was ""`).
|
||||||
|
* **Inference (Mental Model)**: What the operator deduced from the observation (e.g. *"The verification digest calculated locally differed from the signature sent by Gitea"*).
|
||||||
|
* **Hypothesis (Causal Candidate)**: A plausible mechanism explaining the inference (e.g. *"The intermediate webhook daemon modified the body bytes during parameter extraction"*).
|
||||||
|
|
||||||
|
### B. Discriminating Tests & Command Rationale
|
||||||
|
Never present terminal commands as unexplained recipes. Every diagnostic step must answer:
|
||||||
|
1. **Target Layer**: What component or boundary does this command inspect?
|
||||||
|
2. **Rationale**: Why is this inspection relevant to the active hypothesis?
|
||||||
|
3. **Falsification Criteria**: What specific observation would **support** the hypothesis, and what would **refute** it?
|
||||||
|
|
||||||
|
### C. Anti-Hindsight Bias (Chronological Integrity)
|
||||||
|
Investigations in real systems rarely proceed in a straight line. They branch, hit dead ends, revisit earlier questions, or discover new phenomena midway through.
|
||||||
|
* Preserve the transitions where evidence shifted attention.
|
||||||
|
* If a crucial causal insight was discovered only retrospectively after fixing the issue, **explicitly label it as retrospective analysis**. Do not present it as if it guided the initial investigation.
|
||||||
|
|
||||||
|
### D. Transferable Diagnostic Knowledge vs. Literal Replication
|
||||||
|
While exact commands are useful for auditability, the primary value of an incident journal is **transferable diagnostic intuition**:
|
||||||
|
* *Literal Replication*: "Run `docker exec gitea sqlite3 ...`"
|
||||||
|
* *Transferable Heuristic*: "When an authenticated webhook fails at the receiver, verify configuration and secret synchronization at both protocol endpoints before diagnosing payload corruption."
|
||||||
|
|
||||||
|
### E. Proportionality
|
||||||
|
Scale investigative depth to the actual learning value of the incident:
|
||||||
|
* For a simple typosquat or routine restart, keep the entry concise and focused.
|
||||||
|
* For subtle protocol discrepancies, serialization bugs, race conditions, or cryptographic failures, provide full deep-dive rigor.
|
||||||
|
* Never manufacture artificial hypotheses or boilerplate purely to satisfy a template.
|
||||||
|
|
||||||
|
### F. Source Attribution for Protocol Contracts
|
||||||
|
Never rely on remembered behavior for protocol specifications, container entrypoints, or framework internals. Explicitly cite the canonical source (e.g. *"According to Gitea's webhook implementation..."*, *"Per RFC 2104 (HMAC)..."*).
|
||||||
|
|
||||||
|
### G. Safe Credential Verification Without Secret Leakage
|
||||||
|
When verifying whether two endpoints possess matching credentials, never log raw or truncated secrets. Instead, document cryptographic proof (e.g., comparing SHA-256 digests of the credentials in memory) or safe boolean assertions.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Modular Investigation Structure
|
||||||
|
|
||||||
|
When authoring an incident journal (`Brain/records/journal/YYYY-MM-DD-<slug>.md`), apply the following modular sections as appropriate:
|
||||||
|
|
||||||
|
### 1. System Context & Fundamentals
|
||||||
|
* Establish the specific role of the affected subsystem.
|
||||||
|
* Diagram component boundaries, data flow, and security/protocol contracts with source citations.
|
||||||
|
* Reference canonical documentation (avoid copying static architectural overviews).
|
||||||
|
|
||||||
|
### 2. Problem & Observations
|
||||||
|
* State expected behavior vs. actual behavior.
|
||||||
|
* Provide verbatim error snippets, exit statuses, and terminal states.
|
||||||
|
* Clearly isolate raw facts before offering any interpretations.
|
||||||
|
|
||||||
|
### 3. Diagnostic Inquiries
|
||||||
|
* Formulate the evolving questions that organize the investigation.
|
||||||
|
|
||||||
|
### 4. Investigation & Hypothesis Testing
|
||||||
|
* Walk through each meaningful investigative inquiry:
|
||||||
|
* **Rationale**: Why this path was explored.
|
||||||
|
* **Inspection**: The commands or queries executed.
|
||||||
|
* **Prediction**: What results were expected under candidate hypotheses.
|
||||||
|
* **Observed Evidence**: What the system actually returned.
|
||||||
|
* **Outcome**: Whether the working hypothesis was supported, refuted, or refined.
|
||||||
|
|
||||||
|
### 5. Findings & Root Cause Analysis
|
||||||
|
* Synthesize the validated evidence.
|
||||||
|
* Detail the exact physical or logical causal chain (e.g. how data structures, memory, networks, or serializers behaved under the hood).
|
||||||
|
* Explicitly distinguish between evidence proven during triage and insights discovered via retrospective analysis.
|
||||||
|
|
||||||
|
### 6. Declarative Remediation & Local Validation
|
||||||
|
* Present the minimal declarative configuration change.
|
||||||
|
* Document local verification commands (unit tests, flake checks, compose validations).
|
||||||
|
|
||||||
|
### 7. Deployment & Recovery Runbook
|
||||||
|
* Document production deployment steps.
|
||||||
|
* If deployment requires privileged operations (such as `sudo nixos-rebuild switch`), explicitly label the operational privileges and provide the operator runbook.
|
||||||
|
* Provide concrete post-deployment verification proving that the service recovered under real operating conditions.
|
||||||
|
|
||||||
|
### 8. Discussion & Generalization
|
||||||
|
* **Architectural Takeaways**: Design flaws or implicit assumptions exposed by the incident.
|
||||||
|
* **Transferable Diagnostic Rules**: General heuristics that apply to future troubleshooting across other domains (avoiding overgeneralization).
|
||||||
|
* **Preventative Measures**: Systemic hardening or monitoring improvements.
|
||||||
|
|
||||||
|
### 9. References
|
||||||
|
* Code pointers, forge commit links, external RFCs, and upstream issue trackers.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Epistemic & Evidence Self-Audit Checklist
|
||||||
|
|
||||||
|
Before finalizing an incident journal, execute the following 7-point audit:
|
||||||
|
|
||||||
|
1. **Epistemic Classification**: Is every substantive statement clearly categorized as an *observation*, *inference*, *hypothesis*, or *conclusion*?
|
||||||
|
2. **Evidence Demonstration**: Does the journal *demonstrate* the causal mechanism with concrete evidence rather than merely asserting it?
|
||||||
|
3. **Auditability**: Is the supporting evidence actually shown in the record rather than assumed?
|
||||||
|
4. **Chronological Integrity**: Is historical investigation reasoning distinguished from retrospective reconstruction?
|
||||||
|
5. **Proportional Claims**: Does the conclusion claim only what the evidence strictly establishes without overreaching?
|
||||||
|
6. **Sound Generalization**: Are local lessons generalized safely (avoiding absolute claims like *"it is always X"* when other failure modes exist)?
|
||||||
|
7. **Transferability**: Could an unfamiliar engineer apply the diagnostic reasoning to a dissimilar problem without already knowing the solution?
|
||||||
@@ -172,3 +172,10 @@ Gitea maintains an automated push mirror to GitHub (`github.com/kiskaadee/second
|
|||||||
| **3. Server Pull** | `ssh server-remote "cd ~/Brain && git status"` | `Your branch is up to date with 'origin/main'.` |
|
| **3. Server Pull** | `ssh server-remote "cd ~/Brain && git status"` | `Your branch is up to date with 'origin/main'.` |
|
||||||
| **4. Live Web View** | Open `https://docs.roadtotech.me` | Edited content appears immediately |
|
| **4. Live Web View** | Open `https://docs.roadtotech.me` | Edited content appears immediately |
|
||||||
| **5. CI Status** | Repository $\rightarrow$ Actions tab in Gitea | Pipeline `Brain Structural Validation` green (✓) |
|
| **5. CI Status** | Repository $\rightarrow$ Actions tab in Gitea | Pipeline `Brain Structural Validation` green (✓) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏛️ Related References & Incident Post-Mortems
|
||||||
|
|
||||||
|
* [GitOps Dispatcher Webhook Signature Mismatch: Epistemic Root Cause Analysis](../../../records/journal/2026-09-21-gitops-webhook-payload-signature-mismatch.md) — Detailed investigation into `adnanh/webhook` payload serialization divergence and HMAC signature verification.
|
||||||
|
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
---
|
||||||
|
type: journal
|
||||||
|
project: homelab
|
||||||
|
date: 2026-09-21
|
||||||
|
tags:
|
||||||
|
- operations
|
||||||
|
- homelab
|
||||||
|
- troubleshooting
|
||||||
|
- gitops
|
||||||
|
- webhook
|
||||||
|
- cryptography
|
||||||
|
- gitea
|
||||||
|
- nixos
|
||||||
|
---
|
||||||
|
|
||||||
|
# GitOps Dispatcher Webhook Signature Mismatch: Epistemic Root Cause Analysis
|
||||||
|
|
||||||
|
## 1. System Context & Fundamentals
|
||||||
|
|
||||||
|
The homelab appliance operates a continuous deployment pipeline designed to automatically keep workload directories (in `~/Sites`) and data vaults (such as `~/Brain`) synchronized with their authoritative Git remotes on Gitea (`gitea.roadtotech.me`).
|
||||||
|
|
||||||
|
```
|
||||||
|
SERVER APPLIANCE (:9000)
|
||||||
|
┌────────────────────────────────────────────────────────┐
|
||||||
|
┌──────────────┐ │ ┌──────────────────┐ ┌─────────────────────────┐ │ ┌──────────────────┐
|
||||||
|
│ Gitea Push │──HTTP POST──►│ │ adnanh/webhook │──────►│ gitops_dispatcher.py │─┼──────►│ Target Worktree │
|
||||||
|
│ Webhook Event│ (signed) │ │ daemon (:9000) │ argv │ (HMAC verification) │ │ git │ (~/Brain) │
|
||||||
|
└──────────────┘ │ └──────────────────┘ └─────────────────────────┘ │ pull └──────────────────┘
|
||||||
|
└────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### Components & Protocol Contracts
|
||||||
|
1. **Gitea Webhook Service**: According to Gitea's webhook implementation (`modules/webhook/webhook.go`), when a repository webhook is configured with a shared secret, Gitea calculates an HMAC-SHA256 digest over the **exact raw HTTP request body bytes** prior to transmission and delivers the bare hexadecimal digest in the `X-Gitea-Signature` HTTP header.
|
||||||
|
2. **Webhook Daemon (`adnanh/webhook`)**: A lightweight Go daemon running on internal port 9000 (managed via NixOS systemd unit `homelab-gitops.service`). It listens for incoming HTTP requests, extracts parameters, and passes them as arguments to execution scripts.
|
||||||
|
3. **GitOps Dispatcher (`gitops_dispatcher.py`)**: A Python engine that validates the payload HMAC-SHA256 signature against `/run/secrets/gitops/webhook_secret` (projected via SOPS), admits the target repository, and spawns an asynchronous worker to perform `git pull --ff-only`.
|
||||||
|
|
||||||
|
### Cryptographic Security Contract
|
||||||
|
Per RFC 2104 (HMAC), HMAC-SHA256 verification relies strictly on **byte-for-byte equality**:
|
||||||
|
$$\text{Signature} = \text{HMAC-SHA256}(\text{Shared Secret}, \text{Payload Bytes})$$
|
||||||
|
If even a single byte, whitespace character, or key ordering differs between the payload signed by Gitea and the payload evaluated by the Python dispatcher, the computed digest diverges completely due to the avalanche effect.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Problem & Observations
|
||||||
|
|
||||||
|
During routine operations, pushes to the `second-brain` repository on Gitea failed to trigger automatic synchronization in the server's working tree (`~/Brain`).
|
||||||
|
|
||||||
|
### Raw Observations (Machine Outputs)
|
||||||
|
1. **Working Tree State**: Inspecting `~/Brain` on `server` revealed the working tree was not updating automatically:
|
||||||
|
```text
|
||||||
|
On branch main
|
||||||
|
Your branch is behind 'origin/main' by 4 commits, and can be fast-forwarded.
|
||||||
|
(use "git pull" to update your local branch)
|
||||||
|
```
|
||||||
|
2. **Initial Systemd Journal Trace**: Inspecting `homelab-gitops.service` logs revealed that the webhook daemon triggered the dispatcher script, but authentication failed closed:
|
||||||
|
```text
|
||||||
|
webhook[4494]: executing /home/kiskaadee/Core/scripts/gitops_dispatcher.py with arguments [..., "<json>", "", "push"]
|
||||||
|
webhook[4494]: [ERROR] [GitOps] Authentication failed: Missing signature header.
|
||||||
|
webhook[4494]: [ERROR] [GitOps] ❌ Webhook authentication failed. Rejecting request.
|
||||||
|
webhook[4494]: [webhook] error occurred: exit status 1
|
||||||
|
```
|
||||||
|
3. **Secondary Systemd Journal Trace (Post-Secret Configuration)**: After configuring the shared secret in Gitea repository settings and triggering a test delivery, the daemon received the signature header but failed cryptographic verification:
|
||||||
|
```text
|
||||||
|
webhook[4494]: executing /home/kiskaadee/Core/scripts/gitops_dispatcher.py with arguments [..., "<json>", "c98657cbabeb6d7cf54f4868163d082d2dcb622a489f16c2549cc81549b26b83", "push"]
|
||||||
|
webhook[4494]: [ERROR] [GitOps] Authentication failed: Signature mismatch.
|
||||||
|
webhook[4494]: [ERROR] [GitOps] ❌ Webhook authentication failed. Rejecting request.
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Diagnostic Inquiries & Investigation Progression
|
||||||
|
|
||||||
|
The investigation progressed through three distinct diagnostic inquiries as live evidence emerged:
|
||||||
|
|
||||||
|
### Phase 1: Investigating Missing Signature Header
|
||||||
|
|
||||||
|
* **Question**: Why was the second argument (the `X-Gitea-Signature` header) passed as an empty string `""` in the initial journal trace?
|
||||||
|
* **Inference**: In Gitea, if a webhook is created without a secret token, Gitea skips HMAC generation and omits the signature header entirely.
|
||||||
|
* **Test Command**: Query Gitea's SQLite database inside the `gitea` container:
|
||||||
|
```bash
|
||||||
|
ssh server-local "docker exec gitea sqlite3 /data/gitea/gitea.db 'SELECT id, repo_id, url, secret FROM webhook;'"
|
||||||
|
```
|
||||||
|
* **Observed Evidence**:
|
||||||
|
```text
|
||||||
|
1|6|http://192.168.1.36:9000/hooks/deploy||1|gitea
|
||||||
|
```
|
||||||
|
The `secret` column for webhook ID 1 (`second-brain`) was empty (`""`).
|
||||||
|
* **Intervention**: Entered the SOPS shared secret into Gitea repository webhook settings.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 2: Investigating Signature Mismatch with Matching Credentials
|
||||||
|
|
||||||
|
* **Question**: Once the secret was added and Gitea transmitted a signature (`c98657cb...`), why did `hmac.compare_digest` fail?
|
||||||
|
* **Working Hypothesis 1 (Credential Discrepancy)**: The secret stored in Gitea's database did not match the decrypted secret file on the server host.
|
||||||
|
* **Discriminating Test**: Compare the SHA-256 digests of the Gitea database secret and the host secret in memory without logging raw credentials:
|
||||||
|
```python
|
||||||
|
import hashlib
|
||||||
|
# Safely verify credential equality
|
||||||
|
db_secret_hash = hashlib.sha256(db_secret.encode("utf-8")).hexdigest()
|
||||||
|
host_secret_hash = hashlib.sha256(host_secret_bytes.strip()).hexdigest()
|
||||||
|
assert db_secret_hash == host_secret_hash
|
||||||
|
```
|
||||||
|
* **Observed Evidence**: The hashes matched identically, proving both endpoints possessed the exact same shared secret.
|
||||||
|
* **Status**: Credential discrepancy hypothesis **refuted**.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Phase 3: Isolating Payload Transformation Across the Daemon Boundary
|
||||||
|
|
||||||
|
* **Question**: If the credentials are equal and the algorithm is HMAC-SHA256, at what boundary did the input bytes diverge?
|
||||||
|
* **Working Hypothesis 2 (Daemon Parameter Re-serialization)**: The webhook daemon (`adnanh/webhook`) modified the payload bytes when extracting command-line arguments.
|
||||||
|
* **Inspection**: Inspected the webhook hook definition in `Core/nixos/modules/homeserver.nix`:
|
||||||
|
```nix
|
||||||
|
pass-arguments-to-command = [
|
||||||
|
{ source = "entire-payload"; }
|
||||||
|
{ source = "header"; name = "X-Gitea-Signature"; }
|
||||||
|
{ source = "header"; name = "X-Gitea-Event"; }
|
||||||
|
];
|
||||||
|
```
|
||||||
|
* **Empirical Demonstration in Python**:
|
||||||
|
Extracted the exact JSON string passed to the dispatcher in `sys.argv[1]` and tested HMAC verification against the received signature:
|
||||||
|
```python
|
||||||
|
import hashlib, hmac
|
||||||
|
|
||||||
|
secret = b"<shared_secret>"
|
||||||
|
# The payload string as passed to sys.argv[1] by adnanh/webhook:
|
||||||
|
received_payload = """{"after":"00000000...","before":"00000000...",...}"""
|
||||||
|
|
||||||
|
# 1. Digest calculated over dispatcher's input argument:
|
||||||
|
calculated_mac = hmac.new(secret, received_payload.encode("utf-8"), hashlib.sha256).hexdigest()
|
||||||
|
print("Calculated over argv[1]:", calculated_mac)
|
||||||
|
print("Received Gitea Sig: ", "c98657cbabeb6d7cf54f4868163d082d2dcb622a489f16c2549cc81549b26b83")
|
||||||
|
# Result: 6882b1c8... != c98657cb... (Mismatch)
|
||||||
|
```
|
||||||
|
* **Documentation Verification**: According to `adnanh/webhook` documentation, `source: "entire-payload"` unmarshals JSON into a Go data structure and re-marshals it using Go's standard `json.Marshal`, altering key order and whitespace. Conversely, `source: "raw-request-body"` captures the unmodified byte stream received over the network.
|
||||||
|
* **Status**: Payload transformation hypothesis **confirmed**.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Findings & Root Cause Analysis
|
||||||
|
|
||||||
|
### The Underlying Mechanism
|
||||||
|
1. **Gitea Signing Stage**: Gitea calculates the HMAC-SHA256 digest on the literal byte sequence of the HTTP request body before transmission over TCP.
|
||||||
|
2. **Intermediate Parsing Stage**: `adnanh/webhook` with `source: "entire-payload"` parses the HTTP body into a generic `map[string]interface{}` and re-serializes it when constructing `sys.argv`.
|
||||||
|
3. **Serialization Divergence**: Go's `json.Marshal` sorts dictionary keys lexicographically and strips formatting whitespace. Consequently:
|
||||||
|
$$\text{len}(\text{raw HTTP bytes}) \neq \text{len}(\text{re-marshaled bytes})$$
|
||||||
|
$$\text{SHA256}(\text{raw HTTP bytes}) \neq \text{SHA256}(\text{re-marshaled bytes})$$
|
||||||
|
4. **Verification Failure**: The dispatcher received the re-marshaled string, computed HMAC over its bytes, and rejected the signature due to the byte-level discrepancy.
|
||||||
|
5. **Remediation Mechanism**: Declaring `source: "raw-request-body"` instructs `adnanh/webhook` to pass the unmodified raw byte buffer directly into the process argument.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Declarative Remediation & Local Validation
|
||||||
|
|
||||||
|
### Declarative NixOS Change
|
||||||
|
Modified [`Core/nixos/modules/homeserver.nix`](https://gitea.roadtotech.me/kiskaadee/homelab-core/src/branch/main/nixos/modules/homeserver.nix) to replace `entire-payload` with `raw-request-body`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
id = "deploy";
|
||||||
|
execute-command = "/home/kiskaadee/Core/scripts/gitops_dispatcher.py";
|
||||||
|
pass-arguments-to-command = [
|
||||||
|
- { source = "entire-payload"; }
|
||||||
|
+ { source = "raw-request-body"; }
|
||||||
|
{ source = "header"; name = "X-Gitea-Signature"; }
|
||||||
|
{ source = "header"; name = "X-Gitea-Event"; }
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
### Local Invariant Validation
|
||||||
|
Ran the repository pre-commit test suite and Nix flake evaluation:
|
||||||
|
```bash
|
||||||
|
./Core/scripts/test
|
||||||
|
```
|
||||||
|
*Output*: 35/35 pytest unit and security tests passed; flake derivation evaluated cleanly. Committed and pushed to `main` (`5f12e9e`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Deployment Procedure & Post-Fix Verification
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> **Privileged Operation Guardrail**: Applying host-level NixOS system configurations requires an operator with root/sudo privileges (`sudo nixos-rebuild switch`).
|
||||||
|
|
||||||
|
### Operator Rebuild Runbook
|
||||||
|
1. **SSH to the Server Appliance**:
|
||||||
|
```bash
|
||||||
|
ssh server-remote
|
||||||
|
```
|
||||||
|
2. **Pull and Switch NixOS Configuration**:
|
||||||
|
```bash
|
||||||
|
cd ~/Core && git pull origin main
|
||||||
|
sudo nixos-rebuild switch --flake ~/Core#server
|
||||||
|
```
|
||||||
|
3. **Trigger Test Delivery**:
|
||||||
|
In Gitea web UI, navigate to `https://gitea.roadtotech.me/kiskaadee/second-brain/settings/hooks` and click **Test Delivery**.
|
||||||
|
4. **Verify Dispatcher Journal**:
|
||||||
|
```bash
|
||||||
|
journalctl -u homelab-gitops -n 20 --no-pager
|
||||||
|
```
|
||||||
|
*Expected Result*: `✅ Webhook admission passed: Admitted for deployment on branch 'main'.`
|
||||||
|
5. **Verify Target Repository State**:
|
||||||
|
Inspect `~/Brain` on the server host to confirm the working tree is fast-forwarded to `origin/main`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Discussion & Transferable Lessons
|
||||||
|
|
||||||
|
### Transferable Diagnostic Heuristics
|
||||||
|
1. **Cryptographic Input Boundary Invariant**: When an intermediary process (proxy, API gateway, hook daemon) sits between a signing client and a verifying backend, the parameter extraction layer must preserve raw, unparsed byte streams. Never perform cryptographic signature validation on deserialized and re-serialized data.
|
||||||
|
2. **Systematic Signature Debugging**: When an HMAC verification fails despite identical secrets, follow this elimination sequence:
|
||||||
|
- *Step 1 (Credential Identity)*: Verify secret synchronization using safe cryptographic hash comparisons.
|
||||||
|
- *Step 2 (Algorithm & Encoding)*: Verify HMAC algorithm (SHA256 vs. SHA1), digest format (hex vs. Base64), and prefix handling (`sha256=` stripping).
|
||||||
|
- *Step 3 (Byte-Level Identity)*: Capture the raw byte stream at the signer and the verifier to identify serialization, encoding, or newline mutations.
|
||||||
|
|
||||||
|
### Retrospective Architectural Analysis
|
||||||
|
* **Why the defect was latent**: The dispatcher was initially tested with manual CLI invocations (`--repo second-brain --branch main`), which bypass the HTTP webhook signature verification gate. Live webhook integration was the only layer subject to `adnanh/webhook`'s argument serialization behavior.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. References
|
||||||
|
* [`Core/scripts/gitops_dispatcher.py`](https://gitea.roadtotech.me/kiskaadee/homelab-core/src/branch/main/scripts/gitops_dispatcher.py)
|
||||||
|
* [`Core/nixos/modules/homeserver.nix`](https://gitea.roadtotech.me/kiskaadee/homelab-core/src/branch/main/nixos/modules/homeserver.nix)
|
||||||
|
* [Brain GitOps & Auto-Sync Deployment Pipeline](../../projects/homelab/guides/brain-gitops-deployment-pipeline.md)
|
||||||
|
* [Scientific Incident Investigation & Epistemic Journaling](../../knowledge/methods/incident-investigation-and-journaling.md)
|
||||||
|
* [adnanh/webhook Hook Parameters Documentation](https://github.com/adnanh/webhook#hook-parameters)
|
||||||
|
* [RFC 2104: HMAC: Keyed-Hashing for Message Authentication](https://datatracker.ietf.org/doc/html/rfc2104)
|
||||||
Reference in new issue
Block a user