vault, digicert: migrate Token / APIKey to *secret.Ref (Bundle I Phase 3)

Closes Top-10 fix #2 of the 2026-05-03 issuer-coverage audit (see
cowork/issuer-coverage-audit-2026-05-03/RESULTS.md). Pre-fix,
vault.Config.Token and digicert.Config.APIKey were plain string
fields. Practical impact:

  1. GET /api/v1/issuers responses marshalled the credential into
     the JSON body. An acquirer's procurement engineer running
     'curl /api/v1/issuers | jq' saw the token / API key in plain
     text on screen.
  2. DEBUG-level HTTP request logging printed the credential
     header verbatim.
  3. A heap dump of the running server contained the credential
     as readable bytes for the lifetime of the process.

Bundle I from the 2026-05-01 audit closed this for AWSACMPCA,
EJBCA, GlobalSign, Sectigo (Phase 1+2). Vault and DigiCert were
left out. This commit ports the same migration onto them.

Mechanics:
  - Config.Token / Config.APIKey type changed from 'string' to
    '*secret.Ref'. UnmarshalJSON of a JSON string populates the
    Ref via NewRefFromString — operator config files are
    unchanged.
  - Every header-write call site routed through Ref.Use, with the
    byte buffer zeroed after the callback returns. Vault: 3 sites
    (IssueCertificate, RevokeCertificate, GetCACertPEM). DigiCert:
    5 sites (ValidateConfig, IssueCertificate, RevokeCertificate,
    pollOrderOnce, downloadCertificate).
  - ValidateConfig nil-checks switch from 'cfg.Token == ""' to
    'cfg.Token.IsEmpty()' (mirrors Sectigo's existing pattern).
  - Tests migrated: every Config{Token:"..."} →
    Config{Token: secret.NewRefFromString("...")}. The
    'json.Marshal(config) → ValidateConfig(rawConfig)' round-trip
    pattern in DigiCert's ValidateConfig_Success test is now
    broken by the redact-on-marshal contract — switched that one
    to construct the rawConfig as a JSON literal (mirrors
    Sectigo's existing test pattern).
  - Two new tests pin the redact-on-marshal contract:
      - TestVault_Config_TokenMarshalsAsRedacted (vault_redact_test.go)
      - TestDigiCert_Config_APIKeyMarshalsAsRedacted (digicert_redact_test.go)
    Both assert the marshaled JSON contains '"[redacted]"' and
    does NOT contain the plaintext bytes.

Operator-visible: GET /api/v1/issuers responses for type=vault
and type=digicert now show the credential as '[redacted]'.
Existing config files keep working — the Ref unmarshal accepts
strings.

CHANGELOG note: certctl/CHANGELOG.md is intentionally not
hand-edited; release notes are auto-generated from commit
messages between consecutive tags. This commit's message body is
the release-note artifact.

Verified locally:
  - gofmt clean across the repo.
  - go vet ./... clean across the repo.
  - go test -race -count=1 -short
    ./internal/connector/issuer/vault/...
    ./internal/connector/issuer/digicert/...
    ./internal/secret/...  green.

Audit reference: cowork/issuer-coverage-audit-2026-05-03/
RESULTS.md Top-10 fix #2.
This commit is contained in:
shankar0123
2026-05-03 20:49:23 +00:00
parent 81f6321326
commit d3bf2cc0cf
8 changed files with 191 additions and 48 deletions
@@ -19,6 +19,7 @@ import (
"github.com/shankar0123/certctl/internal/connector/issuer"
"github.com/shankar0123/certctl/internal/connector/issuer/digicert"
"github.com/shankar0123/certctl/internal/secret"
)
func TestDigiCertConnector(t *testing.T) {
@@ -41,15 +42,16 @@ func TestDigiCertConnector(t *testing.T) {
}))
defer srv.Close()
config := digicert.Config{
APIKey: "dc-test-api-key",
OrgID: "12345",
ProductType: "ssl_basic",
BaseURL: srv.URL,
}
// Build rawConfig as a JSON literal so the secrets round-trip
// intact via UnmarshalJSON (json.Marshal redacts *secret.Ref →
// "[redacted]" by design; it MUST NOT be used to construct a
// rawConfig that ValidateConfig will then header-write back).
rawConfig := []byte(fmt.Sprintf(
`{"api_key":"dc-test-api-key","org_id":"12345","product_type":"ssl_basic","base_url":%q}`,
srv.URL,
))
connector := digicert.New(nil, logger)
rawConfig, _ := json.Marshal(config)
err := connector.ValidateConfig(ctx, rawConfig)
if err != nil {
t.Fatalf("ValidateConfig failed: %v", err)
@@ -74,7 +76,7 @@ func TestDigiCertConnector(t *testing.T) {
t.Run("ValidateConfig_MissingOrgID", func(t *testing.T) {
config := digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
}
connector := digicert.New(nil, logger)
@@ -100,7 +102,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := digicert.Config{
APIKey: "dc-bad-key",
APIKey: secret.NewRefFromString("dc-bad-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -136,7 +138,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
ProductType: "ssl_basic",
BaseURL: srv.URL,
@@ -180,7 +182,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
ProductType: "ssl_ev_basic",
BaseURL: srv.URL,
@@ -217,7 +219,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
ProductType: "ssl_basic",
BaseURL: srv.URL,
@@ -255,7 +257,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -289,7 +291,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
PollMaxWaitSeconds: 1, // keep async-pending tests fast
@@ -321,7 +323,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -350,7 +352,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
ProductType: "ssl_basic",
BaseURL: srv.URL,
@@ -388,7 +390,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -414,7 +416,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -446,7 +448,7 @@ func TestDigiCertConnector(t *testing.T) {
defer srv.Close()
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: srv.URL,
}
@@ -463,7 +465,7 @@ func TestDigiCertConnector(t *testing.T) {
t.Run("GetRenewalInfo_ReturnsNil", func(t *testing.T) {
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
BaseURL: "https://api.digicert.com",
}
@@ -480,7 +482,7 @@ func TestDigiCertConnector(t *testing.T) {
t.Run("DefaultProductType", func(t *testing.T) {
config := &digicert.Config{
APIKey: "dc-test-key",
APIKey: secret.NewRefFromString("dc-test-key"),
OrgID: "12345",
// ProductType intentionally left empty
}