mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 20:11:31 +00:00
8b75e0311b
Mechanical sed across the main go.mod's module declaration, the f5-mock-icontrol
sub-module's go.mod, every Go file's import path (361 files), and a rebuild of
the checked-in f5-mock-icontrol binary so its embedded build-info reflects the
new module path. No behavior change.
Choice B from cowork/transfer-certctl-to-org.md, executed 2026-05-04. Choice A
(keep module path declared as github.com/shankar0123/certctl regardless of
repo URL) shipped on the day of the org transfer (2026-05-03) since we had no
external Go consumers; this commit closes that deferral.
Backward-compat: GitHub HTTP redirects continue to forward
github.com/shankar0123/certctl → github.com/certctl-io/certctl at the URL
level, but Go's module proxy uses the path declared in go.mod as the
canonical name. Pre-fix, anyone trying `go get github.com/certctl-io/certctl/...`
hit a "module path mismatch" error because go.mod said
github.com/shankar0123/certctl and the URL they fetched it from said
certctl-io/certctl. Post-fix, the canonical name and the URL agree, so
go get / go install / external Go consumers / Go-tooling integrations
work cleanly via either the new path (preferred) or the old path (which
redirects and Go follows the redirect for source fetch).
Anyone still importing the old path inside their own code keeps working
provided they update their go.mod's `require` line to match — the module
path declared in their consumer's go.sum / go.mod is the authoritative
import name, so a mass sed across their import statements is the migration
on the consumer side. No external consumers exist today.
Diff shape:
361 *.go files — import path replacement only
2 go.mod — module declaration replacement only
1 binary — deploy/test/f5-mock-icontrol/f5-mock-icontrol rebuilt
so embedded build-info reflects the new path (8618965 vs
8618933 bytes; 32-byte diff is the build-info change)
Total: 364 files, 730 insertions / 730 deletions, net-zero size, pure
mechanical substitution.
Verification:
gofmt: 17 files needed re-alignment after sed (the new path is one char
shorter than the old, so column-aligned import groups drifted). Applied
`gofmt -w` to fix.
go mod tidy: clean exit on both modules.
go vet ./...: clean exit.
go build ./...: clean exit.
go test -short -count=1 on representative packages: all green
(internal/domain, internal/validation, internal/crypto, internal/crypto/signer,
cmd/agent). Test output now reads `ok github.com/certctl-io/certctl/...`
confirming the module path resolves correctly.
binary: f5-mock-icontrol rebuilt; `strings | grep shankar0123` returns
nothing; `strings | grep certctl-io/certctl` shows the new module path
embedded in build-info.
Files intentionally NOT touched in this commit:
README.md / CHANGELOG.md / docs/ / etc. — already swept to certctl-io
URLs in commit 0729ee4 (the post-transfer URL refresh). This commit is
purely the Go-tooling layer.
Scarf pixels (`shankar0123.docker.scarf.sh/...`) — Scarf-account
namespace, not a Go import or GitHub repo URL. Stays.
This is a non-blocking, non-customer-impacting change. Operators pulling
container images, running `make verify`, hitting the API, or installing the
agent see no functional difference. Only Go-tooling consumers (none today)
are affected, and they're enabled — not broken — by this commit.
176 lines
6.3 KiB
Go
176 lines
6.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/certctl-io/certctl/internal/api/middleware"
|
|
"github.com/certctl-io/certctl/internal/domain"
|
|
)
|
|
|
|
// BulkRevocationService defines the service interface for bulk certificate revocation.
|
|
type BulkRevocationService interface {
|
|
BulkRevoke(ctx context.Context, criteria domain.BulkRevocationCriteria, reason string, actor string) (*domain.BulkRevocationResult, error)
|
|
}
|
|
|
|
// BulkRevocationHandler handles HTTP requests for bulk revocation operations.
|
|
type BulkRevocationHandler struct {
|
|
svc BulkRevocationService
|
|
}
|
|
|
|
// NewBulkRevocationHandler creates a new BulkRevocationHandler.
|
|
func NewBulkRevocationHandler(svc BulkRevocationService) BulkRevocationHandler {
|
|
return BulkRevocationHandler{svc: svc}
|
|
}
|
|
|
|
// bulkRevokeRequest represents the JSON request body for bulk revocation.
|
|
type bulkRevokeRequest struct {
|
|
Reason string `json:"reason"`
|
|
ProfileID string `json:"profile_id,omitempty"`
|
|
OwnerID string `json:"owner_id,omitempty"`
|
|
AgentID string `json:"agent_id,omitempty"`
|
|
IssuerID string `json:"issuer_id,omitempty"`
|
|
TeamID string `json:"team_id,omitempty"`
|
|
CertificateIDs []string `json:"certificate_ids,omitempty"`
|
|
}
|
|
|
|
// BulkRevoke handles bulk certificate revocation.
|
|
// POST /api/v1/certificates/bulk-revoke
|
|
//
|
|
// M-003: admin-only. Bulk revocation is a fleet-scale destructive operation —
|
|
// a non-admin caller must not be able to invalidate certificates across
|
|
// profiles/owners/agents. The gate is enforced here (before body parsing) so a
|
|
// non-admin never sees its request criteria evaluated.
|
|
func (h BulkRevocationHandler) BulkRevoke(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
Error(w, http.StatusMethodNotAllowed, "Method not allowed")
|
|
return
|
|
}
|
|
|
|
requestID := middleware.GetRequestID(r.Context())
|
|
|
|
// M-003: admin-only gate. Non-admin callers are rejected before any
|
|
// criteria/body processing to avoid leaking validation behavior to
|
|
// unauthorized actors.
|
|
if !middleware.IsAdmin(r.Context()) {
|
|
ErrorWithRequestID(w, http.StatusForbidden,
|
|
"Bulk revocation requires admin privileges",
|
|
requestID)
|
|
return
|
|
}
|
|
|
|
var req bulkRevokeRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid request body", requestID)
|
|
return
|
|
}
|
|
|
|
// Validate reason is present
|
|
if req.Reason == "" {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Revocation reason is required", requestID)
|
|
return
|
|
}
|
|
|
|
// Validate reason is a valid RFC 5280 code
|
|
if !domain.IsValidRevocationReason(req.Reason) {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid revocation reason: "+req.Reason, requestID)
|
|
return
|
|
}
|
|
|
|
criteria := domain.BulkRevocationCriteria{
|
|
ProfileID: req.ProfileID,
|
|
OwnerID: req.OwnerID,
|
|
AgentID: req.AgentID,
|
|
IssuerID: req.IssuerID,
|
|
TeamID: req.TeamID,
|
|
CertificateIDs: req.CertificateIDs,
|
|
}
|
|
|
|
// Safety guard: at least one criterion required
|
|
if criteria.IsEmpty() {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "At least one filter criterion is required (profile_id, owner_id, agent_id, issuer_id, team_id, or certificate_ids)", requestID)
|
|
return
|
|
}
|
|
|
|
// Extract actor from auth context (M-002: named-key identity → audit trail)
|
|
actor := resolveActor(r.Context())
|
|
|
|
result, err := h.svc.BulkRevoke(r.Context(), criteria, req.Reason, actor)
|
|
if err != nil {
|
|
ErrorWithRequestID(w, http.StatusInternalServerError, "Bulk revocation failed: "+err.Error(), requestID)
|
|
return
|
|
}
|
|
|
|
JSON(w, http.StatusOK, result)
|
|
}
|
|
|
|
// BulkRevokeEST handles EST-source-scoped bulk certificate revocation.
|
|
// POST /api/v1/est/certificates/bulk-revoke
|
|
//
|
|
// EST RFC 7030 hardening master bundle Phase 11.2.
|
|
//
|
|
// Identical to BulkRevoke above but the Source criterion is pinned to
|
|
// CertificateSourceEST so the operation only affects certs the EST
|
|
// service stamped at issuance time. Operators who want to revoke
|
|
// "every cert this device family ever issued through EST" hit this
|
|
// endpoint with a profile_id / owner_id / etc. criterion + the
|
|
// handler narrows the result set to EST-only.
|
|
//
|
|
// Same M-008 admin-gate as the generic BulkRevoke. Audit action
|
|
// emitted by the service is `est_bulk_revoke` (typed code from Phase
|
|
// 11.3) so operators grep on the action string distinguishes
|
|
// EST-bulk-revoke from the generic bulk-revoke.
|
|
func (h BulkRevocationHandler) BulkRevokeEST(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost {
|
|
Error(w, http.StatusMethodNotAllowed, "Method not allowed")
|
|
return
|
|
}
|
|
requestID := middleware.GetRequestID(r.Context())
|
|
if !middleware.IsAdmin(r.Context()) {
|
|
ErrorWithRequestID(w, http.StatusForbidden,
|
|
"EST bulk revocation requires admin privileges", requestID)
|
|
return
|
|
}
|
|
var req bulkRevokeRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid request body", requestID)
|
|
return
|
|
}
|
|
if req.Reason == "" {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Revocation reason is required", requestID)
|
|
return
|
|
}
|
|
if !domain.IsValidRevocationReason(req.Reason) {
|
|
ErrorWithRequestID(w, http.StatusBadRequest, "Invalid revocation reason: "+req.Reason, requestID)
|
|
return
|
|
}
|
|
criteria := domain.BulkRevocationCriteria{
|
|
ProfileID: req.ProfileID,
|
|
OwnerID: req.OwnerID,
|
|
AgentID: req.AgentID,
|
|
IssuerID: req.IssuerID,
|
|
TeamID: req.TeamID,
|
|
CertificateIDs: req.CertificateIDs,
|
|
// Pin Source to EST — operators MUST also supply at least one
|
|
// narrower criterion (criteria.IsEmpty intentionally excludes
|
|
// Source so a Source-only request is still rejected as too
|
|
// broad). This protects against "revoke every EST cert in the
|
|
// fleet" via a malformed body.
|
|
Source: domain.CertificateSourceEST,
|
|
}
|
|
if criteria.IsEmpty() {
|
|
ErrorWithRequestID(w, http.StatusBadRequest,
|
|
"At least one narrower criterion is required (profile_id, owner_id, agent_id, issuer_id, team_id, or certificate_ids); EST bulk-revoke is implicitly Source-scoped to EST",
|
|
requestID)
|
|
return
|
|
}
|
|
actor := resolveActor(r.Context())
|
|
result, err := h.svc.BulkRevoke(r.Context(), criteria, req.Reason, actor)
|
|
if err != nil {
|
|
ErrorWithRequestID(w, http.StatusInternalServerError, "EST bulk revocation failed: "+err.Error(), requestID)
|
|
return
|
|
}
|
|
JSON(w, http.StatusOK, result)
|
|
}
|