Repository navigation
fix(authz): authorize host unblock inside the unblock transaction - #441
Merged
Merged
Conversation
POST /api/v1/hosts/{id}/unblock authorized the caller's CA ownership from a
snapshot, then called UnblockHost, which re-read only the host row. That left
the same window GHSA-qhq5-2cq9-gwgc closed for host delete: an owner disabled
between the check and the mutation still reauthorized a blocked host for
enrollment, and for a finalized imported host that resumes its current
identity.
Add SQLiteStore.UnblockHostForOperator, which loads the host through
loadHostForOperator -- active operator status plus CA ownership, admin as an
explicit exception -- inside the transaction that clears enrollment tokens,
retires certificates, and moves the host to pending. Reject importing hosts
there as well. UnblockHost keeps its behavior for trusted, operator-less
callers and now delegates to the same transactional helper.
The API handler calls the scoped method and maps its errors through the
existing host-operation handler, so a stale request now answers 403 with the
host still blocked.
Regression tests name SEC-TENANT-001 and fail when the in-transaction
ownership check is removed: a paused bearer-authenticated unblock, and
store-level owner, admin, foreign, disabled, and importing cases. Document
unblock in the invariant enforcement and narrowing of the threat-model TOCTOU
row.
Refs #440
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/v1/hosts/{id}/unblockauthorized the caller and mutated in separate steps:handleUnblockHostcalledGetHost, thencanAccessHost, thenstore.UnblockHost, and the store transaction re-read only the host row.A non-admin CA owner whose request was authorized just before an administrator disabled that operator still committed the unblock. That is the same CWE-367 window GHSA-qhq5-2cq9-gwgc fixed for host delete in 0.23.8, where
UnblockHostwas left as the documented follow-up.Impact is lower than delete: an unblock cannot remove a host or blocklist a certificate. It does reauthorize a blocked host for enrollment, and for a finalized imported host resuming its current identity means its existing certificate and management signing key become usable again.
Closes #440.
Code pointers
internal/store/sqlite_host_operator.go: newUnblockHostForOperatorrunsloadHostForOperator(active operator status, CA ownership, admin as the explicit exception) inside the unblock transaction, and refuses importing hosts.internal/store/sqlite.go:UnblockHostkeeps its behavior for trusted operator-less callers and now delegates tounblockHostWithLoader, the transactional helper shared with the scoped method.internal/store/store.go: interface entry.internal/api/hosts.go:handleUnblockHostcalls the scoped method and reuseswriteHostOperationError(403denied,404missing,409importing), matchinghandleDeleteHostandhandleBlockHost.docs/security/invariants.md,docs/security/threat-model.md: unblock added to theSEC-TENANT-001enforcement, and the TOCTOU residual-risk row narrowed to the routes that still re-check before the write.There is no Web UI unblock route, so the API is the only adapter.
Tests
Both were verified to fail when the in-transaction ownership check is removed from
UnblockHostForOperator.internal/api/unblock_host_after_disable_test.go:TestUnblockHost_SEC_TENANT_001_RejectsOwnerDisabledBeforeMutationpauses a bearer-authenticatedPOST /unblockat the mutation boundary, disables the owner, and requires403with the host still blocked and nohost.unblockaudit row. Thefreshsubtest is the negative control.internal/store/sqlite_host_operator_test.go:TestUnblockHostForOperatorUsesCurrentHostScopecovers owner, admin, foreign, unknown, empty and disabled operators without changing a blocked host;TestUnblockHostForOperatorRefusesImportingHostcovers the import guard.TestOperatorHostRoutesDenyForeignScope(POST /unblock→ 403, host unchanged) still passes.Verification
No failures.
gofmt -lis clean.No migration, no configuration change, no behavior change for callers that pass the check.