Skip to content

fix(authz): authorize host unblock inside the unblock transaction - #441

Merged
juev merged 1 commit into
mainfrom
fix/host-unblock-authz
Dec 2, 2026
Merged

juev merged 1 commit into
mainfrom
fix/host-unblock-authz

Conversation

@juev

@juev juev commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

POST /api/v1/hosts/{id}/unblock authorized the caller and mutated in separate steps: handleUnblockHost called GetHost, then canAccessHost, then store.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 UnblockHost was 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: new UnblockHostForOperator runs loadHostForOperator (active operator status, CA ownership, admin as the explicit exception) inside the unblock transaction, and refuses importing hosts.
  • internal/store/sqlite.go: UnblockHost keeps its behavior for trusted operator-less callers and now delegates to unblockHostWithLoader, the transactional helper shared with the scoped method.
  • internal/store/store.go: interface entry.
  • internal/api/hosts.go: handleUnblockHost calls the scoped method and reuses writeHostOperationError (403 denied, 404 missing, 409 importing), matching handleDeleteHost and handleBlockHost.
  • docs/security/invariants.md, docs/security/threat-model.md: unblock added to the SEC-TENANT-001 enforcement, 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_RejectsOwnerDisabledBeforeMutation pauses a bearer-authenticated POST /unblock at the mutation boundary, disables the owner, and requires 403 with the host still blocked and no host.unblock audit row. The fresh subtest is the negative control.
  • internal/store/sqlite_host_operator_test.go: TestUnblockHostForOperatorUsesCurrentHostScope covers owner, admin, foreign, unknown, empty and disabled operators without changing a blocked host; TestUnblockHostForOperatorRefusesImportingHost covers the import guard.
  • Existing TestOperatorHostRoutesDenyForeignScope (POST /unblock → 403, host unchanged) still passes.

Verification

make ci   # vet, build, go test -race ./... (40 packages), golangci-lint 0 issues,
          # gosec clean, govulncheck "No vulnerabilities found"

No failures. gofmt -l is clean.

No migration, no configuration change, no behavior change for callers that pass the check.

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
@juev
juev merged commit 67c4e7e into main Dec 2, 2026
12 checks passed
@juev
juev deleted the fix/host-unblock-authz branch December 2, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unblock host authorization is checked before the mutation, not inside it

1 participant