Skip to content

Commit 74b0938

Browse files
authored
Merge pull request #117 from smallstep/require-ca-bundle
Remove the requirement of an identity certificate
2 parents 83cf219 + 1b64cd3 commit 74b0938

File tree

7 files changed

+18
-67
lines changed

7 files changed

+18
-67
lines changed

api/v1beta1/stepclusterissuer_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ type StepClusterIssuerSpec struct {
4040
// CABundle is a base64 encoded TLS certificate used to verify connections
4141
// to the step certificates server. If not set the system root certificates
4242
// are used to validate the TLS connection.
43-
// +optional
44-
CABundle []byte `json:"caBundle,omitempty"`
43+
CABundle []byte `json:"caBundle"`
4544
}
4645

4746
// StepClusterIssuerStatus defines the observed state of StepClusterIssuer

api/v1beta1/stepissuer_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ type StepIssuerSpec struct {
4040
// CABundle is a base64 encoded TLS certificate used to verify connections
4141
// to the step certificates server. If not set the system root certificates
4242
// are used to validate the TLS connection.
43-
// +optional
44-
CABundle []byte `json:"caBundle,omitempty"`
43+
CABundle []byte `json:"caBundle"`
4544
}
4645

4746
// StepIssuerStatus defines the observed state of StepIssuer

config/crd/bases/certmanager.step.sm_stepclusterissuers.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ spec:
8181
description: URL is the base URL for the step certificates instance.
8282
type: string
8383
required:
84+
- caBundle
8485
- provisioner
8586
- url
8687
type: object

config/crd/bases/certmanager.step.sm_stepissuers.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ spec:
7676
description: URL is the base URL for the step certificates instance.
7777
type: string
7878
required:
79+
- caBundle
7980
- provisioner
8081
- url
8182
type: object

controllers/stepclusterissuer_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func (r *StepClusterIssuerReconciler) Reconcile(ctx context.Context, req ctrl.Re
8787
}
8888

8989
// Initialize and store the provisioner
90-
//nolint:contextcheck // legacy
9190
p, err := provisioners.NewFromStepClusterIssuer(iss, password)
9291
if err != nil {
9392
log.Error(err, "failed to initialize provisioner")
@@ -111,6 +110,8 @@ func validateStepClusterIssuerSpec(s api.StepClusterIssuerSpec) error {
111110
switch {
112111
case s.URL == "":
113112
return fmt.Errorf("spec.url cannot be empty")
113+
case len(s.CABundle) == 0:
114+
return fmt.Errorf("spec.caBundle cannot be empty")
114115
case s.Provisioner.Name == "":
115116
return fmt.Errorf("spec.provisioner.name cannot be empty")
116117
case s.Provisioner.KeyID == "":

controllers/stepissuer_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func (r *StepIssuerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8787
}
8888

8989
// Initialize and store the provisioner
90-
//nolint:contextcheck // legacy
9190
p, err := provisioners.NewFromStepIssuer(iss, password)
9291
if err != nil {
9392
log.Error(err, "failed to initialize provisioner")
@@ -111,6 +110,8 @@ func validateStepIssuerSpec(s api.StepIssuerSpec) error {
111110
switch {
112111
case s.URL == "":
113112
return fmt.Errorf("spec.url cannot be empty")
113+
case len(s.CABundle) == 0:
114+
return fmt.Errorf("spec.caBundle cannot be empty")
114115
case s.Provisioner.Name == "":
115116
return fmt.Errorf("spec.provisioner.name cannot be empty")
116117
case s.Provisioner.KeyID == "":

provisioners/step.go

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,47 @@ var collection = new(sync.Map)
2121
// requests using step certificates.
2222
type Step struct {
2323
name string
24+
caBundle []byte
2425
provisioner *ca.Provisioner
2526
}
2627

2728
// NewFromStepIssuer returns a new Step provisioner, configured with the information in the
2829
// given issuer.
2930
func NewFromStepIssuer(iss *api.StepIssuer, password []byte) (*Step, error) {
30-
var options []ca.ClientOption
31-
if len(iss.Spec.CABundle) > 0 {
32-
options = append(options, ca.WithCABundle(iss.Spec.CABundle))
31+
options := []ca.ClientOption{
32+
ca.WithCABundle(iss.Spec.CABundle),
3333
}
34+
3435
provisioner, err := ca.NewProvisioner(iss.Spec.Provisioner.Name, iss.Spec.Provisioner.KeyID, iss.Spec.URL, password, options...)
3536
if err != nil {
3637
return nil, err
3738
}
3839

3940
p := &Step{
4041
name: iss.Name + "." + iss.Namespace,
42+
caBundle: iss.Spec.CABundle,
4143
provisioner: provisioner,
4244
}
4345

44-
// Request identity certificate if required.
45-
if version, err := provisioner.Version(); err == nil {
46-
if version.RequireClientAuthentication {
47-
if err := p.createIdentityCertificate(); err != nil {
48-
return nil, err
49-
}
50-
}
51-
}
52-
5346
return p, nil
5447
}
5548

5649
func NewFromStepClusterIssuer(iss *api.StepClusterIssuer, password []byte) (*Step, error) {
57-
var options []ca.ClientOption
58-
if len(iss.Spec.CABundle) > 0 {
59-
options = append(options, ca.WithCABundle(iss.Spec.CABundle))
50+
options := []ca.ClientOption{
51+
ca.WithCABundle(iss.Spec.CABundle),
6052
}
53+
6154
provisioner, err := ca.NewProvisioner(iss.Spec.Provisioner.Name, iss.Spec.Provisioner.KeyID, iss.Spec.URL, password, options...)
6255
if err != nil {
6356
return nil, err
6457
}
6558

6659
p := &Step{
6760
name: iss.Name + "." + iss.Namespace,
61+
caBundle: iss.Spec.CABundle,
6862
provisioner: provisioner,
6963
}
7064

71-
// Request identity certificate if required.
72-
if version, err := provisioner.Version(); err == nil {
73-
if version.RequireClientAuthentication {
74-
if err := p.createIdentityCertificate(); err != nil {
75-
return nil, err
76-
}
77-
}
78-
}
79-
8065
return p, nil
8166
}
8267

@@ -95,45 +80,9 @@ func Store(namespacedName types.NamespacedName, provisioner *Step) {
9580
collection.Store(namespacedName, provisioner)
9681
}
9782

98-
func (s *Step) createIdentityCertificate() error {
99-
csr, pk, err := ca.CreateCertificateRequest(s.name)
100-
if err != nil {
101-
return err
102-
}
103-
token, err := s.provisioner.Token(s.name)
104-
if err != nil {
105-
return err
106-
}
107-
resp, err := s.provisioner.Sign(&capi.SignRequest{
108-
CsrPEM: *csr,
109-
OTT: token,
110-
})
111-
if err != nil {
112-
return err
113-
}
114-
tr, err := s.provisioner.Client.Transport(context.Background(), resp, pk)
115-
if err != nil {
116-
return err
117-
}
118-
s.provisioner.Client.SetTransport(tr)
119-
return nil
120-
}
121-
12283
// Sign sends the certificate requests to the Step CA and returns the signed
12384
// certificate.
12485
func (s *Step) Sign(_ context.Context, cr *certmanager.CertificateRequest) ([]byte, []byte, error) {
125-
// Get root certificate(s)
126-
roots, err := s.provisioner.Roots()
127-
if err != nil {
128-
return nil, nil, err
129-
}
130-
131-
// Encode root certificates
132-
caPem, err := encodeX509(roots.Certificates...)
133-
if err != nil {
134-
return nil, nil, err
135-
}
136-
13786
// decode and check certificate request
13887
csr, err := decodeCSR(cr.Spec.Request)
13988
if err != nil {
@@ -180,7 +129,7 @@ func (s *Step) Sign(_ context.Context, cr *certmanager.CertificateRequest) ([]by
180129
if err != nil {
181130
return nil, nil, err
182131
}
183-
return chainPem, caPem, nil
132+
return chainPem, s.caBundle, nil
184133
}
185134

186135
// decodeCSR decodes a certificate request in PEM format and returns the

0 commit comments

Comments
 (0)