mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 18:51:32 +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.
227 lines
8.6 KiB
Go
227 lines
8.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/certctl-io/certctl/internal/trustanchor"
|
|
)
|
|
|
|
// EST RFC 7030 hardening master bundle Phase 7.1.
|
|
//
|
|
// estCounterTab is the in-memory equivalent of a Prometheus
|
|
// `certctl_est_enrollments_total{status="..."}` metric. We don't take a
|
|
// Prometheus dependency here (the project doesn't expose /metrics today;
|
|
// that's a separate decision). The admin GUI's "EST Profiles" tab calls
|
|
// the GET /api/v1/admin/est/profiles endpoint, which calls
|
|
// ESTService.Stats() to render the counter snapshot.
|
|
//
|
|
// Concurrency: every field is read/written via sync/atomic so the
|
|
// service hot path stays lock-free.
|
|
|
|
// Counter labels — keep in sync with snapshot() + the admin GUI's
|
|
// counter-grid renderer. New labels MUST be added in three places:
|
|
// constants below, snapshot()'s map, and inc()'s switch.
|
|
const (
|
|
estCounterSuccessSimpleEnroll = "success_simpleenroll"
|
|
estCounterSuccessSimpleReEnroll = "success_simplereenroll"
|
|
estCounterSuccessServerKeygen = "success_serverkeygen"
|
|
estCounterAuthFailedBasic = "auth_failed_basic"
|
|
estCounterAuthFailedMTLS = "auth_failed_mtls"
|
|
estCounterAuthFailedChannelBind = "auth_failed_channel_binding"
|
|
estCounterCSRInvalid = "csr_invalid"
|
|
estCounterCSRPolicyViolation = "csr_policy_violation"
|
|
estCounterCSRSignatureMismatch = "csr_signature_mismatch"
|
|
estCounterRateLimited = "rate_limited"
|
|
estCounterIssuerError = "issuer_error"
|
|
estCounterInternalError = "internal_error"
|
|
)
|
|
|
|
type estCounterTab struct {
|
|
successSimpleEnroll atomic.Uint64
|
|
successSimpleReEnroll atomic.Uint64
|
|
successServerKeygen atomic.Uint64
|
|
authFailedBasic atomic.Uint64
|
|
authFailedMTLS atomic.Uint64
|
|
authFailedChannelBind atomic.Uint64
|
|
csrInvalid atomic.Uint64
|
|
csrPolicyViolation atomic.Uint64
|
|
csrSignatureMismatch atomic.Uint64
|
|
rateLimited atomic.Uint64
|
|
issuerError atomic.Uint64
|
|
internalError atomic.Uint64
|
|
}
|
|
|
|
// snapshot returns a zero-allocation copy of the current counter values
|
|
// keyed by the same label strings inc() accepts.
|
|
func (c *estCounterTab) snapshot() map[string]uint64 {
|
|
if c == nil {
|
|
return map[string]uint64{}
|
|
}
|
|
return map[string]uint64{
|
|
estCounterSuccessSimpleEnroll: c.successSimpleEnroll.Load(),
|
|
estCounterSuccessSimpleReEnroll: c.successSimpleReEnroll.Load(),
|
|
estCounterSuccessServerKeygen: c.successServerKeygen.Load(),
|
|
estCounterAuthFailedBasic: c.authFailedBasic.Load(),
|
|
estCounterAuthFailedMTLS: c.authFailedMTLS.Load(),
|
|
estCounterAuthFailedChannelBind: c.authFailedChannelBind.Load(),
|
|
estCounterCSRInvalid: c.csrInvalid.Load(),
|
|
estCounterCSRPolicyViolation: c.csrPolicyViolation.Load(),
|
|
estCounterCSRSignatureMismatch: c.csrSignatureMismatch.Load(),
|
|
estCounterRateLimited: c.rateLimited.Load(),
|
|
estCounterIssuerError: c.issuerError.Load(),
|
|
estCounterInternalError: c.internalError.Load(),
|
|
}
|
|
}
|
|
|
|
// inc advances the counter matching the given label. Unknown labels
|
|
// fall through to internal_error so an enum drift doesn't silently
|
|
// lose counts.
|
|
func (c *estCounterTab) inc(label string) {
|
|
if c == nil {
|
|
return
|
|
}
|
|
switch label {
|
|
case estCounterSuccessSimpleEnroll:
|
|
c.successSimpleEnroll.Add(1)
|
|
case estCounterSuccessSimpleReEnroll:
|
|
c.successSimpleReEnroll.Add(1)
|
|
case estCounterSuccessServerKeygen:
|
|
c.successServerKeygen.Add(1)
|
|
case estCounterAuthFailedBasic:
|
|
c.authFailedBasic.Add(1)
|
|
case estCounterAuthFailedMTLS:
|
|
c.authFailedMTLS.Add(1)
|
|
case estCounterAuthFailedChannelBind:
|
|
c.authFailedChannelBind.Add(1)
|
|
case estCounterCSRInvalid:
|
|
c.csrInvalid.Add(1)
|
|
case estCounterCSRPolicyViolation:
|
|
c.csrPolicyViolation.Add(1)
|
|
case estCounterCSRSignatureMismatch:
|
|
c.csrSignatureMismatch.Add(1)
|
|
case estCounterRateLimited:
|
|
c.rateLimited.Add(1)
|
|
case estCounterIssuerError:
|
|
c.issuerError.Add(1)
|
|
default:
|
|
c.internalError.Add(1)
|
|
}
|
|
}
|
|
|
|
// ESTStatsSnapshot is the per-profile observability view the admin
|
|
// GET endpoint renders. Mirrors IntuneStatsSnapshot's shape so the GUI
|
|
// can re-use the same counter-grid component.
|
|
//
|
|
// EST RFC 7030 hardening master bundle Phase 7.1.
|
|
type ESTStatsSnapshot struct {
|
|
PathID string `json:"path_id"`
|
|
IssuerID string `json:"issuer_id"`
|
|
ProfileID string `json:"profile_id,omitempty"`
|
|
Counters map[string]uint64 `json:"counters"`
|
|
MTLSEnabled bool `json:"mtls_enabled"`
|
|
BasicConfigured bool `json:"basic_auth_configured"`
|
|
ServerKeygen bool `json:"server_keygen_enabled"`
|
|
TrustAnchors []ESTTrustAnchorInfo `json:"trust_anchors,omitempty"`
|
|
TrustAnchorPath string `json:"trust_anchor_path,omitempty"`
|
|
Now time.Time `json:"now"`
|
|
}
|
|
|
|
// ESTTrustAnchorInfo is the per-cert public summary of one trust anchor
|
|
// in the holder's pool. Same shape as IntuneTrustAnchorInfo.
|
|
type ESTTrustAnchorInfo struct {
|
|
Subject string `json:"subject"`
|
|
NotBefore time.Time `json:"not_before"`
|
|
NotAfter time.Time `json:"not_after"`
|
|
DaysToExpiry int `json:"days_to_expiry"`
|
|
Expired bool `json:"expired"`
|
|
}
|
|
|
|
// Stats returns the per-profile observability snapshot. Safe for
|
|
// concurrent callers — every counter access is atomic + the trust-
|
|
// anchor walk is a per-snapshot copy.
|
|
func (s *ESTService) Stats(now time.Time) ESTStatsSnapshot {
|
|
out := ESTStatsSnapshot{
|
|
PathID: s.estPathIDForLog,
|
|
IssuerID: s.issuerID,
|
|
ProfileID: s.profileID,
|
|
Counters: s.counters.snapshot(),
|
|
MTLSEnabled: s.estMTLSConfigured,
|
|
BasicConfigured: s.estBasicConfigured,
|
|
ServerKeygen: s.estServerKeygenEnabled,
|
|
Now: now,
|
|
}
|
|
if s.estTrustAnchor != nil {
|
|
out.TrustAnchorPath = s.estTrustAnchor.Path()
|
|
for _, c := range s.estTrustAnchor.Get() {
|
|
daysToExpiry := int(c.NotAfter.Sub(now).Hours() / 24)
|
|
out.TrustAnchors = append(out.TrustAnchors, ESTTrustAnchorInfo{
|
|
Subject: c.Subject.CommonName,
|
|
NotBefore: c.NotBefore,
|
|
NotAfter: c.NotAfter,
|
|
DaysToExpiry: daysToExpiry,
|
|
Expired: now.After(c.NotAfter),
|
|
})
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// ReloadTrust forces a SIGHUP-equivalent reload of the per-profile
|
|
// EST mTLS trust anchor pool. Returns nil on success; the configured
|
|
// holder error otherwise (typically a parse error from a half-rotated
|
|
// bundle file). Mirror of SCEPService.ReloadIntuneTrust.
|
|
//
|
|
// Returns ErrESTMTLSDisabled when the profile doesn't have an mTLS
|
|
// trust anchor configured (admin handler maps to HTTP 409).
|
|
//
|
|
// Phase 11.3: emits AuditActionESTTrustAnchorReloaded on successful
|
|
// reload so operators have a typed grep target for "who rotated the
|
|
// trust bundle for which profile + when". The caller-supplied ctx is
|
|
// forwarded into RecordEvent so the audit row carries the same
|
|
// request-scoped trace identifiers as the rest of the admin pipeline,
|
|
// and so the contextcheck linter doesn't flag the admin handler for
|
|
// silently dropping its r.Context() at the service boundary.
|
|
func (s *ESTService) ReloadTrust(ctx context.Context) error {
|
|
if s.estTrustAnchor == nil {
|
|
return ErrESTMTLSDisabled
|
|
}
|
|
if err := s.estTrustAnchor.Reload(); err != nil {
|
|
return err
|
|
}
|
|
if s.auditService != nil {
|
|
details := map[string]interface{}{
|
|
"path_id": s.estPathIDForLog,
|
|
"trust_anchor_path": s.estTrustAnchor.Path(),
|
|
"protocol": "EST",
|
|
}
|
|
_ = s.auditService.RecordEvent(ctx, "est-admin", "system",
|
|
AuditActionESTTrustAnchorReloaded, "trust_anchor", s.estPathIDForLog, details)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ErrESTMTLSDisabled signals the admin handler that an EST profile
|
|
// doesn't have mTLS configured. Maps to HTTP 409 Conflict.
|
|
var ErrESTMTLSDisabled = newESTAdminError("EST profile mTLS not enabled — no trust anchor to reload")
|
|
|
|
func newESTAdminError(msg string) error { return &estAdminError{msg: msg} }
|
|
|
|
type estAdminError struct{ msg string }
|
|
|
|
func (e *estAdminError) Error() string { return e.msg }
|
|
|
|
// SetESTAdminMetadata records the per-profile observability hints the
|
|
// AdminEST handler needs to render the Profiles tab. cmd/server/main.go
|
|
// invokes this once at startup with the data already in scope from the
|
|
// per-profile loop. Idempotent. Consolidated into one setter so the
|
|
// public surface stays narrow + every metadata field moves together.
|
|
func (s *ESTService) SetESTAdminMetadata(pathID string, mtlsEnabled, basicConfigured, serverKeygenEnabled bool, trustAnchor *trustanchor.Holder) {
|
|
s.estPathIDForLog = pathID
|
|
s.estMTLSConfigured = mtlsEnabled
|
|
s.estBasicConfigured = basicConfigured
|
|
s.estServerKeygenEnabled = serverKeygenEnabled
|
|
s.estTrustAnchor = trustAnchor
|
|
}
|