Commit 2c929c3
Closes #142.
## What
The federation wiring for #142 already landed on `main`. The one
remaining gap was a **CI-runnable** proof of the security-critical
ordering invariant: *an unauthorized caller must never reach federation
/ `apply_backend_auth`* (the confused-deputy guard). The only existing
guard,
`tests/test_federation.py::test_restricted_product_denied_to_anonymous`,
is env-gated and **skips in CI** without a live deployed proxy, so CI
never exercised the invariant.
This PR closes that gap by extracting the authorization → federation
decision out of `resolve_product` into a pure, wasm-free function and
unit-testing it in CI.
## How
- **New `authz::decide_backend_auth`** — a pure function that takes the
authorization outcome as plain values, gates the request, and *only on
success* calls `apply_backend_auth`. The confused-deputy guard is the
first line: `authentication: Option<&BackendAuth>` is `None` when the
upstream subject-scoped fetch denied the caller ⇒ `Err(AccessDenied)`
with no federation.
- **Consolidation, not addition** — the scattered write-gate previously
inlined in `resolve_product` (anon denied / read-only / non-signable /
`write`-permission) plus the trailing `apply_backend_auth` call are now
one tested function. `resolve_product` keeps the I/O (subject-scoped
Source API fetches) and routes its result through the pure fn. Net:
registry logic shrinks, the gate has a single source of truth.
- **CI unit tests** in `tests/authz.rs` (the crate is `cdylib` with
`[lib] test = false`; native tests only compile wasm-free modules —
`authz` is one, and already had a test binary). The module is pulled in
via `#[path]`, mirroring `tests/backend_auth.rs`; `backend_auth` is
included alongside it so the `crate::backend_auth` path resolves the
same way it does in the lib build.
New tests (`tests/authz.rs`):
- `unauthorized_outcome_never_federates` — `None` authentication (read
**and** write) ⇒ `AccessDenied` **and** `options` stays empty (no
`oidc_role_arn` / `skip_signature`).
- `authorized_read_unsigned_populates_options`,
`authorized_read_federated_populates_options` — authorized reads
populate options.
- `write_by_anonymous_denied`, `write_to_read_only_denied`,
`write_to_non_signable_denied`, `write_without_write_permission_denied`
— each write denial ⇒ `Err` and empty `options`.
- `authorized_write_populates_options` — authorized write
(case-insensitive `write` permission) populates options.
**Not test theater:** every denial asserts `options` is empty, and the
guard was verified non-vacuous — reverting the `None` guard to a default
makes `unauthorized_outcome_never_federates` fail.
## Acceptance criteria (#142)
- [x] Private S3 product served end-to-end via federated creds →
existing gated
`tests/test_federation.py::test_federated_object_is_served` (live-infra
integration test).
- [x] Public (no-auth) connections still use the anonymous path →
`tests/backend_auth.rs` (`unsigned_sets_skip_signature`) +
`authorized_read_unsigned_populates_options`.
- [x] **Test: an unauthorized caller never triggers `federate_*`** →
**NEW CI unit test** `unauthorized_outcome_never_federates` + the
structural data-dependency guarantee in `resolve_product` (the `?` on
the subject-scoped fetch short-circuits before federation).
- [x] Integration test against a private bucket → existing gated
`tests/test_federation.py::test_restricted_product_denied_to_anonymous`.
## Behavior change (called out, not silent)
Consolidating the gate means the permissions check no longer
short-circuits before the permissions API call. A write to a connection
that can't accept it (read-only / non-signable) now performs the
(cached) permissions fetch before denying, rather than skipping it.
**Same `403` result**, one extra cached API call on that specific deny
path — a rare write-to-misconfigured-connection corner, not the hot read
path.
Relatedly, `build_backend_options` now runs before the write gate, so a
write to a connection with an *unknown provider* surfaces `500` instead
of `403`. Such a connection is already broken for everyone (reads `500`
too), so this is consistent rather than a regression.
## Verification
- `cargo test` — 45 native tests pass (10 authz incl. 8 new, 10
backend_auth, 13 pagination, 12 routing).
- `cargo fmt --all -- --check` — clean.
- `cargo clippy --target wasm32-unknown-unknown -- -D warnings` — clean.
- `cargo check --target wasm32-unknown-unknown` — `resolve_product` and
the lib still compile for the worker target.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fa463c7 commit 2c929c3
3 files changed
Lines changed: 277 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
| |||
18 | 23 | | |
19 | 24 | | |
20 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
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 | 167 | | |
202 | 168 | | |
203 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
204 | 192 | | |
205 | | - | |
| 193 | + | |
| 194 | + | |
206 | 195 | | |
207 | 196 | | |
208 | 197 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
212 | 202 | | |
213 | 203 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
219 | 210 | | |
220 | | - | |
221 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
222 | 217 | | |
223 | 218 | | |
224 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| 11 | + | |
| 12 | + | |
7 | 13 | | |
8 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 | | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
28 | 37 | | |
29 | 38 | | |
30 | 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 | + | |
0 commit comments