mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-11 20:08:54 +00:00
5dc698307b
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.
329 lines
10 KiB
Go
329 lines
10 KiB
Go
package acme_test
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
acmeissuer "github.com/certctl-io/certctl/internal/connector/issuer/acme"
|
|
)
|
|
|
|
func TestScriptDNSSolver(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
t.Run("Present_Success", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "dns-record.txt")
|
|
|
|
// Create a script that writes the DNS record to a file
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
script := `#!/bin/sh
|
|
echo "DOMAIN=$CERTCTL_DNS_DOMAIN FQDN=$CERTCTL_DNS_FQDN VALUE=$CERTCTL_DNS_VALUE TOKEN=$CERTCTL_DNS_TOKEN" > ` + outputFile + `
|
|
`
|
|
if err := os.WriteFile(scriptPath, []byte(script), 0755); err != nil {
|
|
t.Fatalf("Failed to create script: %v", err)
|
|
}
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.Present(ctx, "example.com", "test-token", "test-key-auth")
|
|
if err != nil {
|
|
t.Fatalf("Present failed: %v", err)
|
|
}
|
|
|
|
// Verify the script was executed with correct env vars
|
|
output, err := os.ReadFile(outputFile)
|
|
if err != nil {
|
|
t.Fatalf("Failed to read output file: %v", err)
|
|
}
|
|
|
|
expected := "DOMAIN=example.com FQDN=_acme-challenge.example.com VALUE=test-key-auth TOKEN=test-token\n"
|
|
if string(output) != expected {
|
|
t.Errorf("Script output mismatch:\ngot: %q\nwant: %q", string(output), expected)
|
|
}
|
|
})
|
|
|
|
t.Run("Present_ScriptFailure", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "fail.sh")
|
|
script := `#!/bin/sh
|
|
echo "error: something went wrong" >&2
|
|
exit 1
|
|
`
|
|
os.WriteFile(scriptPath, []byte(script), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.Present(ctx, "example.com", "token", "keyauth")
|
|
if err == nil {
|
|
t.Fatal("Expected error from failing script")
|
|
}
|
|
t.Logf("Correctly got error: %v", err)
|
|
})
|
|
|
|
t.Run("Present_NoScript", func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver("", "", logger)
|
|
err := solver.Present(ctx, "example.com", "token", "keyauth")
|
|
if err == nil {
|
|
t.Fatal("Expected error when no script is configured")
|
|
}
|
|
})
|
|
|
|
t.Run("CleanUp_Success", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "cleanup.txt")
|
|
|
|
scriptPath := filepath.Join(tmpDir, "cleanup.sh")
|
|
script := `#!/bin/sh
|
|
echo "cleaned $CERTCTL_DNS_FQDN" > ` + outputFile + `
|
|
`
|
|
os.WriteFile(scriptPath, []byte(script), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver("", scriptPath, logger)
|
|
err := solver.CleanUp(ctx, "example.com", "token", "keyauth")
|
|
if err != nil {
|
|
t.Fatalf("CleanUp failed: %v", err)
|
|
}
|
|
|
|
output, _ := os.ReadFile(outputFile)
|
|
expected := "cleaned _acme-challenge.example.com\n"
|
|
if string(output) != expected {
|
|
t.Errorf("Cleanup output mismatch: got %q, want %q", string(output), expected)
|
|
}
|
|
})
|
|
|
|
t.Run("CleanUp_NoScript_Noop", func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver("", "", logger)
|
|
// Should not error — cleanup without a script is a no-op
|
|
err := solver.CleanUp(ctx, "example.com", "token", "keyauth")
|
|
if err != nil {
|
|
t.Fatalf("CleanUp without script should not error: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("Present_NonexistentScript", func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver("/nonexistent/script.sh", "", logger)
|
|
err := solver.Present(ctx, "example.com", "token", "keyauth")
|
|
if err == nil {
|
|
t.Fatal("Expected error for nonexistent script")
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestScriptDNSSolver_PresentPersist(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
t.Run("PresentPersist_Success", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "persist-record.txt")
|
|
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
script := `#!/bin/sh
|
|
echo "DOMAIN=$CERTCTL_DNS_DOMAIN FQDN=$CERTCTL_DNS_FQDN VALUE=$CERTCTL_DNS_VALUE TOKEN=$CERTCTL_DNS_TOKEN" > ` + outputFile + `
|
|
`
|
|
if err := os.WriteFile(scriptPath, []byte(script), 0755); err != nil {
|
|
t.Fatalf("Failed to create script: %v", err)
|
|
}
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.PresentPersist(ctx, "example.com", "test-token", "letsencrypt.org; accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/123")
|
|
if err != nil {
|
|
t.Fatalf("PresentPersist failed: %v", err)
|
|
}
|
|
|
|
output, err := os.ReadFile(outputFile)
|
|
if err != nil {
|
|
t.Fatalf("Failed to read output file: %v", err)
|
|
}
|
|
|
|
// Verify _validation-persist prefix (not _acme-challenge)
|
|
expected := "DOMAIN=example.com FQDN=_validation-persist.example.com VALUE=letsencrypt.org; accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/123 TOKEN=test-token\n"
|
|
if string(output) != expected {
|
|
t.Errorf("Script output mismatch:\ngot: %q\nwant: %q", string(output), expected)
|
|
}
|
|
})
|
|
|
|
t.Run("PresentPersist_NoScript", func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver("", "", logger)
|
|
err := solver.PresentPersist(ctx, "example.com", "token", "letsencrypt.org; accounturi=https://example.com/acct/1")
|
|
if err == nil {
|
|
t.Fatal("Expected error when no script is configured")
|
|
}
|
|
})
|
|
|
|
t.Run("PresentPersist_ScriptFailure", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "fail.sh")
|
|
script := `#!/bin/sh
|
|
echo "error: DNS API failure" >&2
|
|
exit 1
|
|
`
|
|
os.WriteFile(scriptPath, []byte(script), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.PresentPersist(ctx, "example.com", "token", "letsencrypt.org; accounturi=https://example.com/acct/1")
|
|
if err == nil {
|
|
t.Fatal("Expected error from failing script")
|
|
}
|
|
})
|
|
|
|
t.Run("PresentPersist_WildcardDomain", func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
outputFile := filepath.Join(tmpDir, "persist-wildcard.txt")
|
|
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
script := `#!/bin/sh
|
|
echo "FQDN=$CERTCTL_DNS_FQDN" > ` + outputFile + `
|
|
`
|
|
os.WriteFile(scriptPath, []byte(script), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
// For *.example.com, the persist record should be at _validation-persist.example.com
|
|
err := solver.PresentPersist(ctx, "example.com", "token", "letsencrypt.org; accounturi=https://example.com/acct/1")
|
|
if err != nil {
|
|
t.Fatalf("PresentPersist failed for wildcard base domain: %v", err)
|
|
}
|
|
|
|
output, _ := os.ReadFile(outputFile)
|
|
expected := "FQDN=_validation-persist.example.com\n"
|
|
if string(output) != expected {
|
|
t.Errorf("FQDN mismatch: got %q, want %q", string(output), expected)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Security tests for DNS injection prevention
|
|
|
|
func TestScriptDNSSolver_Present_RejectInvalidDomain(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
os.WriteFile(scriptPath, []byte("#!/bin/sh\nexit 0"), 0755)
|
|
|
|
tests := []struct {
|
|
name string
|
|
domain string
|
|
}{
|
|
{
|
|
name: "domain with command injection semicolon",
|
|
domain: "example.com; rm -rf /",
|
|
},
|
|
{
|
|
name: "domain with backtick injection",
|
|
domain: "example.com`whoami`",
|
|
},
|
|
{
|
|
name: "domain with command substitution",
|
|
domain: "example.com$(whoami)",
|
|
},
|
|
{
|
|
name: "domain with pipe injection",
|
|
domain: "example.com | cat /etc/passwd",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.Present(ctx, tt.domain, "test-token", "test-key-auth")
|
|
if err == nil {
|
|
t.Fatalf("expected error for invalid domain: %s", tt.domain)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestScriptDNSSolver_Present_RejectInvalidToken(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
os.WriteFile(scriptPath, []byte("#!/bin/sh\nexit 0"), 0755)
|
|
|
|
tests := []struct {
|
|
name string
|
|
token string
|
|
}{
|
|
{
|
|
name: "token with command injection",
|
|
token: "token$(whoami)",
|
|
},
|
|
{
|
|
name: "token with backtick injection",
|
|
token: "token`id`",
|
|
},
|
|
{
|
|
name: "token with semicolon",
|
|
token: "token;malicious",
|
|
},
|
|
{
|
|
name: "token with pipe",
|
|
token: "token|cat",
|
|
},
|
|
{
|
|
name: "token with space",
|
|
token: "token value",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.Present(ctx, "example.com", tt.token, "test-key-auth")
|
|
if err == nil {
|
|
t.Fatalf("expected error for invalid token: %s", tt.token)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestScriptDNSSolver_CleanUp_RejectInvalidDomain(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "cleanup.sh")
|
|
os.WriteFile(scriptPath, []byte("#!/bin/sh\nexit 0"), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver("", scriptPath, logger)
|
|
err := solver.CleanUp(ctx, "example.com; rm -rf /", "test-token", "test-key-auth")
|
|
if err == nil {
|
|
t.Fatal("expected error for command injection in domain")
|
|
}
|
|
}
|
|
|
|
func TestScriptDNSSolver_PresentPersist_RejectInvalidDomain(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
os.WriteFile(scriptPath, []byte("#!/bin/sh\nexit 0"), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.PresentPersist(ctx, "example.com`whoami`", "test-token", "letsencrypt.org; accounturi=https://example.com/acct/1")
|
|
if err == nil {
|
|
t.Fatal("expected error for command injection in domain")
|
|
}
|
|
}
|
|
|
|
func TestScriptDNSSolver_PresentPersist_RejectInvalidToken(t *testing.T) {
|
|
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
scriptPath := filepath.Join(tmpDir, "present.sh")
|
|
os.WriteFile(scriptPath, []byte("#!/bin/sh\nexit 0"), 0755)
|
|
|
|
solver := acmeissuer.NewScriptDNSSolver(scriptPath, "", logger)
|
|
err := solver.PresentPersist(ctx, "example.com", "token$(whoami)", "letsencrypt.org; accounturi=https://example.com/acct/1")
|
|
if err == nil {
|
|
t.Fatal("expected error for command injection in token")
|
|
}
|
|
}
|