Guidance for AI coding agents working in this repository. Claude Code loads it through the one-line @../AGENTS.md import in .claude/CLAUDE.md.
step-issuer is a cert-manager external issuer for Kubernetes. It watches
cert-manager CertificateRequest resources whose issuerRef.group is certmanager.step.sm and signs
them against a step-ca server using a JWK provisioner.
It defines two CRDs, StepIssuer (namespaced) and StepClusterIssuer (cluster-scoped), in API group
certmanager.step.sm/v1beta1. Built with kubebuilder v2 scaffolding on controller-runtime; the
step-ca client comes from github.com/smallstep/certificates/ca. Module: github.com/smallstep/step-issuer.
Binary name is manager; the container image is smallstep/step-issuer.
make build # make generate + CGO_ENABLED=0 go build -> bin/manager
make test # go test ./api/... ./controllers/... -coverprofile cover.out
make lint # golangci-lint (config fetched from smallstep/workflows) + govulncheck
make generate # controller-gen: deepcopy (api/) + CRDs/RBAC/webhook manifests (config/)
make manifests # CRD/RBAC/webhook manifests only
make run # make generate + go run ./main.go against current kubeconfig
make install # kubectl apply CRDs from config/crd/bases
make deploy # CRDs + kustomize build config/default | kubectl apply
make bootstrap # install golangci-lint, govulncheck, gotestsum
make clean # rm bin/managergo test -run TestResolveProvisionerPasswordFile ./controllers/ # single test
go build ./... && go vet ./... # quick check, no controller-genNotes:
make buildandmake rundepend ongenerate, which needscontroller-gen; if it is not onPATHthe Makefile runsgo install sigs.k8s.io/controller-tools/cmd/controller-gen(version pinned viatools.go/go.mod). Regeneration rewritesapi/v1beta1/zz_generated.deepcopy.goandconfig/crd/bases/*.yaml; checkgit statusbefore committing.make testcovers only./api/...and./controllers/.... CI runsgotestsum -- ./...(all packages, stable and oldstable Go),V=1 make build, golangci-lint, govulncheck, and CodeQL via the sharedsmallstep/workflowsgoCI.yml. Rungo test ./...locally to match CI.make fmtreferences an undefined$(SRC)variable and is a no-op; rungoimports -w .directly.- Every
makeinvocation prints./.version.sh: Command not found; the script does not exist in the repo. It is harmless (VERSIONfalls back togit describe), so ignore it. - No Docker, database, or cluster is needed for build or unit tests.
make run/install/deployneed a kubeconfig (the README describes a kind setup with cert-manager installed).
| Pattern | Generator |
|---|---|
api/v1beta1/zz_generated.deepcopy.go |
controller-gen object (directive in api/v1beta1/generate.go, header from hack/boilerplate.go.txt) |
config/crd/bases/certmanager.step.sm_*.yaml |
controller-gen crd from +kubebuilder: markers in api/v1beta1/*_types.go |
config/rbac/role.yaml |
controller-gen rbac:roleName=manager-role from +kubebuilder:rbac markers in controllers/ |
After changing a *_types.go file or an RBAC marker, run make generate and commit the results.
step-issuer/
├── main.go # flag parsing, scheme registration, manager + 3 reconcilers
├── api/v1beta1/ # CRD Go types (StepIssuer, StepClusterIssuer), scheme, deepcopy
├── controllers/
│ ├── stepissuer_controller.go # validates StepIssuer spec, resolves password, builds provisioner, sets Ready
│ ├── stepclusterissuer_controller.go # same for StepClusterIssuer
│ ├── certificaterequest_controller.go# signs cert-manager CertificateRequests via the cached provisioner
│ ├── password.go # provisioner password from Secret, env var, or file (exactly one)
│ ├── password_test.go # the only unit tests in the repo
│ └── step_status_*reconciler.go # Ready-condition helpers + event recording
├── provisioners/step.go # step-ca JWK provisioner wrapper; global sync.Map cache keyed by NamespacedName
├── config/ # kustomize tree: crd/, rbac/, manager/, webhook/, certmanager/, default/, samples/
├── docker/Dockerfile # multi-stage alpine build, runs `make bin/manager`
├── hack/boilerplate.go.txt # license header for generated code
├── PROJECT # kubebuilder project file (domain step.sm, group certmanager)
└── tools.go # pins controller-gen in go.mod
- A
StepIssuer/StepClusterIssueris created. Its reconciler validates the spec (url,caBundle,provisioner.name,provisioner.kid, and exactly one ofpasswordRef/passwordEnv/passwordFile), loads the password, callsca.NewProvisioner(which fetches and decrypts the JWK from step-ca), stores the provisioner inprovisioners.collection, and setsstatus.conditions[Ready]=True. - cert-manager creates a
CertificateRequest.CertificateRequestReconcilerignores it unlessissuerRef.groupiscertmanager.step.sm, waits for the Approved condition (unless-disable-approval-check), skips already-issued requests, then requires the referenced issuer to be Ready and present in the cache. Step.Signdecodes the CSR, builds a one-time token from CN + SANs, POSTs a sign request to step-ca withNotAfterfromspec.duration, and writes the leaf+intermediate chain tostatus.certificateand the issuercaBundletostatus.ca.
The provisioner cache is in-process only. After a controller restart, issuers must be re-reconciled
before any CertificateRequest can be signed; a request that arrives first fails with
"provisioner ... not found" and is retried.
- Logging:
logrvia controller-runtime's zap logger. Reconcilers carry aLog logr.Loggerfield; verbose diagnostics uselog.V(4). Zap flags (-zap-devel,-zap-log-level, ...) are bound inmain.go. - Errors:
fmt.Errorfwith%w. Reconcilers report failures by setting theReadycondition with a reason (Validation,NotFound,Error,Pending,Failed) and emitting a Kubernetes Event, then return the error so controller-runtime requeues. - Config: stdlib
flag, no env prefix. Flags:-metrics-bind-address(default0= disabled; manifests set:8080),-enable-leader-election,-leader-election-id(defaultstep-issuer-operator-lock),-disable-approval-check. - Testing: stdlib
testingonly, table-driven; no testify, envtest, or fake client in use. - RBAC is declared as
+kubebuilder:rbacmarkers on the reconcilers, not edited in YAML. - CRD compatibility:
StepIssuerandStepClusterIssuerspecs are duplicated rather than shared; changes to one usually need mirroring in the other (types, validation, controller, provisioner ctor). CRD_OPTIONS ?= "crd"in the Makefile (comment: CRDs work back to Kubernetes 1.11, no conversion webhook).
github.com/smallstep/certificatesprovides thecaclient package used to talk to step-ca. Use areplacedirective ingo.modto develop against a local checkout.github.com/cert-manager/cert-managerprovides theCertificateRequestAPI types andpkg/api/utilhelpers for conditions and approval.- Releases: pushing a
v*tag runs.github/workflows/release.yml, which creates a GitHub release and pushes multi-arch images tosmallstep/step-issuer(:<version>, plus:latestfor non-rc tags). The Helm chart lives insmallstep/helm-charts.