Files
certctl/internal/connector/issuer/acme/dns.go
T
shankar0123 5dc698307b chore: rename Go module path to github.com/certctl-io/certctl
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 bc6039a (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.
2026-05-04 00:30:29 +00:00

161 lines
5.3 KiB
Go

package acme
import (
"context"
"fmt"
"log/slog"
"os/exec"
"time"
"github.com/certctl-io/certctl/internal/validation"
)
// DNSSolver defines the interface for DNS-01 challenge provisioning.
// Implementations create and clean up DNS TXT records for ACME validation.
type DNSSolver interface {
// Present creates a DNS TXT record for the given domain with the given value.
// The FQDN will be _acme-challenge.<domain>.
Present(ctx context.Context, domain, token, keyAuth string) error
// CleanUp removes the DNS TXT record created by Present.
CleanUp(ctx context.Context, domain, token, keyAuth string) error
}
// ScriptDNSSolver implements DNSSolver by executing external scripts.
// This provides maximum flexibility: users supply their own scripts for
// whatever DNS provider they use (Cloudflare, Route53, Azure DNS, etc.).
//
// The scripts receive these environment variables:
//
// CERTCTL_DNS_DOMAIN — the domain being validated (e.g., "example.com")
// CERTCTL_DNS_FQDN — the full record name (e.g., "_acme-challenge.example.com")
// CERTCTL_DNS_VALUE — the TXT record value (key authorization digest)
// CERTCTL_DNS_TOKEN — the ACME challenge token
//
// The present script must create the TXT record and exit 0.
// The cleanup script must remove the TXT record and exit 0.
type ScriptDNSSolver struct {
PresentScript string // Path to script that creates the TXT record
CleanUpScript string // Path to script that removes the TXT record
Timeout time.Duration
Logger *slog.Logger
}
// NewScriptDNSSolver creates a script-based DNS solver.
func NewScriptDNSSolver(presentScript, cleanUpScript string, logger *slog.Logger) *ScriptDNSSolver {
return &ScriptDNSSolver{
PresentScript: presentScript,
CleanUpScript: cleanUpScript,
Timeout: 120 * time.Second,
Logger: logger,
}
}
// Present executes the present script to create a DNS TXT record.
func (s *ScriptDNSSolver) Present(ctx context.Context, domain, token, keyAuth string) error {
if s.PresentScript == "" {
return fmt.Errorf("DNS present script not configured")
}
// Validate domain name to prevent injection attacks
if err := validation.ValidateDomainName(domain); err != nil {
return fmt.Errorf("invalid domain name: %w", err)
}
// Validate ACME token to prevent injection attacks
if err := validation.ValidateACMEToken(token); err != nil {
return fmt.Errorf("invalid ACME token: %w", err)
}
fqdn := "_acme-challenge." + domain
s.Logger.Info("creating DNS TXT record via script",
"domain", domain,
"fqdn", fqdn,
"script", s.PresentScript)
return s.runScript(ctx, s.PresentScript, domain, fqdn, token, keyAuth)
}
// CleanUp executes the cleanup script to remove a DNS TXT record.
func (s *ScriptDNSSolver) CleanUp(ctx context.Context, domain, token, keyAuth string) error {
if s.CleanUpScript == "" {
s.Logger.Warn("DNS cleanup script not configured, skipping cleanup", "domain", domain)
return nil
}
// Validate domain name to prevent injection attacks
if err := validation.ValidateDomainName(domain); err != nil {
return fmt.Errorf("invalid domain name: %w", err)
}
// Validate ACME token to prevent injection attacks
if err := validation.ValidateACMEToken(token); err != nil {
return fmt.Errorf("invalid ACME token: %w", err)
}
fqdn := "_acme-challenge." + domain
s.Logger.Info("removing DNS TXT record via script",
"domain", domain,
"fqdn", fqdn,
"script", s.CleanUpScript)
return s.runScript(ctx, s.CleanUpScript, domain, fqdn, token, keyAuth)
}
// PresentPersist creates a persistent DNS TXT record at _validation-persist.<domain>.
// Used by dns-persist-01 (draft-ietf-acme-dns-persist). Unlike Present (which targets
// _acme-challenge), this targets _validation-persist and the record is intended to be permanent.
func (s *ScriptDNSSolver) PresentPersist(ctx context.Context, domain, token, recordValue string) error {
if s.PresentScript == "" {
return fmt.Errorf("DNS present script not configured")
}
// Validate domain name to prevent injection attacks
if err := validation.ValidateDomainName(domain); err != nil {
return fmt.Errorf("invalid domain name: %w", err)
}
// Validate ACME token to prevent injection attacks
if err := validation.ValidateACMEToken(token); err != nil {
return fmt.Errorf("invalid ACME token: %w", err)
}
fqdn := "_validation-persist." + domain
s.Logger.Info("creating persistent DNS TXT record via script",
"domain", domain,
"fqdn", fqdn,
"script", s.PresentScript)
return s.runScript(ctx, s.PresentScript, domain, fqdn, token, recordValue)
}
// runScript executes a DNS hook script with the appropriate environment variables.
func (s *ScriptDNSSolver) runScript(ctx context.Context, script, domain, fqdn, token, keyAuth string) error {
timeout := s.Timeout
if timeout == 0 {
timeout = 120 * time.Second
}
execCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
cmd := exec.CommandContext(execCtx, script)
cmd.Env = append(cmd.Environ(),
"CERTCTL_DNS_DOMAIN="+domain,
"CERTCTL_DNS_FQDN="+fqdn,
"CERTCTL_DNS_VALUE="+keyAuth,
"CERTCTL_DNS_TOKEN="+token,
)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("DNS script %s failed: %w (output: %s)", script, err, string(output))
}
s.Logger.Debug("DNS script completed", "script", script, "output", string(output))
return nil
}