|
1 | 1 | = http-capability-gateway |
2 | | -Jonathan Jewell <jonathan@formdb.org> |
3 | | -:toc: |
| 2 | +:toc: preamble |
4 | 3 | :icons: font |
5 | | -:sectnums: |
6 | 4 |
|
7 | | -== Overview |
8 | 5 |
|
9 | | -http-capability-gateway is a lightweight, policy-driven HTTP governance layer |
10 | | -that enforces a declarative, auditable model of HTTP verb exposure in front of |
11 | | -existing services. |
12 | | - |
13 | | -This project introduces a minimal viable implementation of a new category: |
14 | | -a capability gateway for HTTP. It does not replace nginx or Apache. Instead, |
15 | | -it governs what they are allowed to do. |
16 | | - |
17 | | -The gateway loads a Verb Governance Spec (DSL v1), validates it, compiles it |
18 | | -into fast enforcement rules, and applies those rules to real HTTP traffic. |
19 | | -Every decision is logged in structured form for audit and introspection. |
20 | | - |
21 | | -== Why This Exists |
22 | | - |
23 | | -Modern systems expose HTTP methods inconsistently and often accidentally. |
24 | | -DELETE, PUT, PATCH, OPTIONS, and even HEAD can leak capabilities or create |
25 | | -attack surface when left unmanaged. |
26 | | - |
27 | | -Traditional reverse proxies do not provide: |
28 | | - |
29 | | -* per-verb governance |
30 | | -* narrative or provenance |
31 | | -* reversible policy artefacts |
32 | | -* trust-aware verb exposure |
33 | | -* structured constraints |
34 | | -* intentional stealthing or deception |
35 | | - |
36 | | -http-capability-gateway introduces a principled, schema-driven approach to |
37 | | -HTTP method governance without disrupting existing infrastructure. |
38 | | - |
39 | | -== MVP Scope |
40 | | - |
41 | | -The MVP focuses on the smallest coherent loop: |
42 | | - |
43 | | -1. Load a Verb Governance Spec from disk |
44 | | -2. Validate it against a top-level schema |
45 | | -3. Compile it into fast, matchable rules |
46 | | -4. Enforce those rules on real HTTP traffic |
47 | | -5. Emit structured logs for every decision |
48 | | - |
49 | | -No trust engine, no dynamic scoring, no control plane, no FormBD integration. |
50 | | -Those will grow around this core in later phases. |
51 | | - |
52 | | -== Verb Governance Spec (DSL v1) |
53 | | - |
54 | | -The DSL defines: |
55 | | - |
56 | | -* global verb rules |
57 | | -* route-specific overrides |
58 | | -* stealth profiles |
59 | | -* narrative metadata |
60 | | - |
61 | | -Example: |
62 | | - |
63 | | -[source,yaml] |
64 | | ----- |
65 | | -service: |
66 | | - name: ledger-api |
67 | | - version: 1 |
68 | | - environment: dev |
69 | | -
|
70 | | -verbs: |
71 | | - GET: { exposure: public } |
72 | | - POST: { exposure: authenticated } |
73 | | - DELETE: { exposure: internal } |
74 | | -
|
75 | | -routes: |
76 | | - - path: /accounts |
77 | | - verbs: |
78 | | - DELETE: |
79 | | - exposure: internal |
80 | | - narrative: "Account deletion requires internal trust." |
81 | | -
|
82 | | -stealth: |
83 | | - profiles: |
84 | | - limited: |
85 | | - unauthenticated: 405 |
86 | | - untrusted: 404 |
87 | | -
|
88 | | -narrative: |
89 | | - purpose: "Define safe verb exposure for ledger operations." |
90 | | ----- |
91 | | - |
92 | | -== Architecture (MVP) |
93 | | - |
94 | | -[source,ascii] |
95 | | ----- |
96 | | -Policy File (DSL) |
97 | | - | |
98 | | - v |
99 | | -Policy Loader → Validator → Compiler |
100 | | - | |
101 | | - v |
102 | | -Gateway (Elixir) |
103 | | - | |
104 | | - v |
105 | | -HTTP Traffic → Enforcement → JSON Logs |
106 | | ----- |
107 | | - |
108 | | -== Running the Gateway |
109 | | - |
110 | | -* Install Elixir |
111 | | -* Clone the repository |
112 | | -* Provide a policy file under `config/policy.yaml` |
113 | | -* Start the gateway: |
114 | | - |
115 | | -[source,bash] |
116 | | ----- |
117 | | -mix run --no-halt |
118 | | ----- |
119 | | - |
120 | | -== Performance Optimisations (v1.0.0) |
121 | | - |
122 | | -=== Tiered ETS Lookup |
123 | | - |
124 | | -Policy lookups use a three-tier strategy that eliminates full-table scans: |
125 | | - |
126 | | -* **Tier 1 — Exact Path (O(1))**: Literal route patterns (no regex metacharacters) are stored with `{:exact, path, verb}` ETS keys. A direct hash lookup resolves 90%+ of requests instantly. |
127 | | -* **Tier 2 — Regex Routes (O(r))**: Patterns containing regex metacharacters are tested only against other regex routes, not the entire table. |
128 | | -* **Tier 3 — Global Rules (O(1))**: If no route matches, a final `{:global, verb}` lookup catches global verb defaults. |
129 | | - |
130 | | -For a 1000-route policy, this reduces from ~1000 regex evaluations per request to 1 hash lookup (typical case) or ~50 regex evaluations (edge case). |
131 | | - |
132 | | -=== Security Headers |
133 | | - |
134 | | -All responses (including health/metrics endpoints) include OWASP-recommended security headers: |
135 | | - |
136 | | -* `X-Content-Type-Options: nosniff` — prevent MIME-type sniffing |
137 | | -* `X-Frame-Options: DENY` — prevent clickjacking |
138 | | -* `Referrer-Policy: strict-origin-when-cross-origin` — limit referrer leakage |
139 | | -* `Cache-Control: no-store, no-cache, must-revalidate` — prevent caching of policy decisions |
140 | | -* `Connection: close` — prevent connection reuse across trust boundaries |
141 | | - |
142 | | -== Roadmap |
143 | | - |
144 | | -=== Phase 2 |
145 | | -* Rate limits |
146 | | -* Expanded stealth profiles |
147 | | -* Hot policy reloads |
148 | | - |
149 | | -=== Phase 3 |
150 | | -* Control plane |
151 | | -* FormBD integration for provenance |
152 | | -* Distributed gateways |
153 | | - |
154 | | -=== Phase 4 |
155 | | -* V-based data plane |
156 | | -* Agent introspection |
157 | | -* Constraint engine |
158 | | -* FQLdt proofs |
159 | | - |
160 | | -== Philosophy |
161 | | - |
162 | | -This project treats governance as a first-class engineering concern. |
163 | | -Policies are artefacts. Artefacts are reversible. Decisions have provenance. |
164 | | -HTTP verbs become capabilities, not accidents. |
165 | | - |
166 | | -== License |
167 | | - |
168 | | -PMPL-1.0-or-later (Palimpsest License) |
0 commit comments