Skip to content

Commit 297c6d7

Browse files
Merge pull request cert-manager#125 from SgtCoDFish/allsigners
Remove issuerRef from approver
2 parents c5f8bac + b3c447b commit 297c6d7

File tree

6 files changed

+73
-40
lines changed

6 files changed

+73
-40
lines changed

deploy/charts/csi-driver-spiffe/templates/deployment.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ spec:
3434
- --csi-driver-name={{ .Values.app.name }}
3535

3636
- --certificate-request-duration={{ .Values.app.certificateRequestDuration }}
37-
- --issuer-name={{ .Values.app.issuer.name }}
38-
- --issuer-kind={{ .Values.app.issuer.kind }}
39-
- --issuer-group={{ .Values.app.issuer.group }}
4037
- --trust-domain={{ .Values.app.trustDomain }}
4138

4239
- --leader-election-namespace=$(POD_NAMESPACE)

internal/approver/app/app.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func NewCommand(ctx context.Context) *cobra.Command {
8686
})
8787

8888
if err := controller.AddApprover(ctx, opts.Logr, controller.Options{
89-
IssuerRef: opts.CertManager.IssuerRef,
9089
Evaluator: evaluator,
9190
Manager: mgr,
9291
}); err != nil {

internal/approver/app/options/options.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package options
1919
import (
2020
"time"
2121

22-
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
2322
"github.com/spf13/pflag"
2423

2524
"github.com/cert-manager/csi-driver-spiffe/internal/flags"
@@ -57,17 +56,12 @@ type OptionsController struct {
5756

5857
// OptionsCertManager are options specific to cert-manager and the evaluator.
5958
type OptionsCertManager struct {
60-
// TrustDomain is the Trust Domain the evaluator will enforce requests request
61-
// for.
59+
// TrustDomain is the Trust Domain the evaluator will enforce requests request for.
6260
TrustDomain string
6361

6462
// CertificateRequestDuration is the duration the evaluator will enforce
6563
// CertificateRequest request for.
6664
CertificateRequestDuration time.Duration
67-
68-
// IssuerRef is the issuer reference that will be used to match on created
69-
// CertificateRequests.
70-
IssuerRef cmmeta.ObjectReference
7165
}
7266

7367
func New() *Options {
@@ -85,12 +79,27 @@ func (o *Options) addCertManagerFlags(fs *pflag.FlagSet) {
8579
fs.DurationVar(&o.CertManager.CertificateRequestDuration, "certificate-request-duration", time.Hour,
8680
"The duration which is enforced for requests to have.")
8781

88-
fs.StringVar(&o.CertManager.IssuerRef.Name, "issuer-name", "my-spiffe-ca",
89-
"Name of issuer which is matched against to evaluate on.")
90-
fs.StringVar(&o.CertManager.IssuerRef.Kind, "issuer-kind", "ClusterIssuer",
91-
"Kind of issuer which is matched against to evaluate on.")
92-
fs.StringVar(&o.CertManager.IssuerRef.Group, "issuer-group", "cert-manager.io",
93-
"Group of issuer which is matched against to evaluate on.")
82+
// allow issuer-* args to still be passed to avoid a backwards incompatible change
83+
var dummyIssuerRefName, dummyIssuerRefKind, dummyIssuerRefGroup string
84+
85+
fs.StringVar(&dummyIssuerRefName, "issuer-name", "", "Deprecated; value is ignored")
86+
fs.StringVar(&dummyIssuerRefKind, "issuer-kind", "", "Deprecated; value is ignored")
87+
fs.StringVar(&dummyIssuerRefGroup, "issuer-group", "", "Deprecated; value is ignored")
88+
89+
err := fs.MarkDeprecated("issuer-name", "issuer-name is deprecated and will be ignored")
90+
if err != nil {
91+
panic("failed to mark issuer-name flag as deprecated; this is an internal programming error")
92+
}
93+
94+
err = fs.MarkDeprecated("issuer-kind", "issuer-kind is deprecated and will be ignored")
95+
if err != nil {
96+
panic("failed to mark issuer-kind flag as deprecated; this is an internal programming error")
97+
}
98+
99+
err = fs.MarkDeprecated("issuer-group", "issuer-group is deprecated and will be ignored")
100+
if err != nil {
101+
panic("failed to mark issuer-group flag as deprecated; this is an internal programming error")
102+
}
94103
}
95104

96105
func (o *Options) addControllerFlags(fs *pflag.FlagSet) {

internal/approver/controller/controller.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/manager"
3131
"sigs.k8s.io/controller-runtime/pkg/predicate"
3232

33+
"github.com/cert-manager/csi-driver-spiffe/internal/annotations"
3334
"github.com/cert-manager/csi-driver-spiffe/internal/approver/evaluator"
3435
)
3536

3637
type Options struct {
37-
// IssuerRef will be used to match against CertificateRequest that need
38-
// evaluation.
39-
IssuerRef cmmeta.ObjectReference
40-
4138
// Evaluator will be used to evaluate whether CertificateRequests should be
4239
// Approved or Denied.
4340
Evaluator evaluator.Interface
@@ -60,10 +57,6 @@ type approver struct {
6057
// objects.
6158
lister client.Reader
6259

63-
// issuerRef is the issuerRef that will be matched on CertificateRequests for
64-
// evaluation.
65-
issuerRef cmmeta.ObjectReference
66-
6760
// evaluator evaluates matched CertificateRequests for whether they should be
6861
// approved or denied.
6962
evaluator evaluator.Interface
@@ -75,7 +68,6 @@ func AddApprover(ctx context.Context, log logr.Logger, opts Options) error {
7568
log: log.WithName("controller"),
7669
client: opts.Manager.GetClient(),
7770
lister: opts.Manager.GetCache(),
78-
issuerRef: opts.IssuerRef,
7971
evaluator: opts.Evaluator,
8072
}
8173

@@ -103,7 +95,10 @@ func AddApprover(ctx context.Context, log logr.Logger, opts Options) error {
10395
return false
10496
}
10597

106-
return req.Spec.IssuerRef == a.issuerRef
98+
// We expect that all csi-driver-spiffe certificates will have the identity
99+
// annotation, so check for its existence as a final filter
100+
_, annotationExists := req.ObjectMeta.Annotations[annotations.SPIFFEIdentityAnnnotationKey]
101+
return annotationExists
107102
})).
108103
Complete(a)
109104
}

internal/approver/controller/test/suite.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3232

33+
"github.com/cert-manager/csi-driver-spiffe/internal/annotations"
3334
"github.com/cert-manager/csi-driver-spiffe/internal/approver/controller"
3435
evaluatorfake "github.com/cert-manager/csi-driver-spiffe/internal/approver/evaluator/fake"
3536

@@ -88,7 +89,6 @@ var _ = Context("Approval", func() {
8889
Expect(controller.AddApprover(ctx, log, controller.Options{
8990
Manager: mgr,
9091
Evaluator: evaluator,
91-
IssuerRef: issuerRef,
9292
})).NotTo(HaveOccurred())
9393

9494
By("Running Approver controller")
@@ -108,19 +108,18 @@ var _ = Context("Approval", func() {
108108
cancel()
109109
})
110110

111-
It("should ignore CertificateRequest that have the wrong IssuerRef", func() {
111+
It("should ignore CertificateRequests that are missing the identity annotation", func() {
112112
cr := cmapi.CertificateRequest{
113113
ObjectMeta: metav1.ObjectMeta{
114114
GenerateName: "cert-manager-csi-driver-spiffe-",
115115
Namespace: namespace.Name,
116+
Annotations: map[string]string{
117+
// intentionally left blank
118+
},
116119
},
117120
Spec: cmapi.CertificateRequestSpec{
118-
Request: []byte("request"),
119-
IssuerRef: cmmeta.ObjectReference{
120-
Name: "not-spiffe-ca",
121-
Kind: "ClusterIssuer",
122-
Group: "cert-manager.io",
123-
},
121+
Request: []byte("request"),
122+
IssuerRef: issuerRef,
124123
},
125124
}
126125
Expect(cl.Create(ctx, &cr)).NotTo(HaveOccurred())
@@ -142,6 +141,9 @@ var _ = Context("Approval", func() {
142141
ObjectMeta: metav1.ObjectMeta{
143142
GenerateName: "cert-manager-csi-driver-spiffe-",
144143
Namespace: namespace.Name,
144+
Annotations: map[string]string{
145+
annotations.SPIFFEIdentityAnnnotationKey: "sentinel",
146+
},
145147
},
146148
Spec: cmapi.CertificateRequestSpec{
147149
Request: []byte("request"),
@@ -167,6 +169,9 @@ var _ = Context("Approval", func() {
167169
ObjectMeta: metav1.ObjectMeta{
168170
GenerateName: "cert-manager-csi-driver-spiffe-",
169171
Namespace: namespace.Name,
172+
Annotations: map[string]string{
173+
annotations.SPIFFEIdentityAnnnotationKey: "sentinel",
174+
},
170175
},
171176
Spec: cmapi.CertificateRequestSpec{
172177
Request: []byte("request"),

test/e2e/suite/approval/approval.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/utils/ptr"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535

36+
"github.com/cert-manager/csi-driver-spiffe/internal/annotations"
3637
"github.com/cert-manager/csi-driver-spiffe/test/e2e/framework"
3738

3839
. "github.com/onsi/ginkgo/v2"
@@ -107,13 +108,17 @@ var _ = framework.CasesDescribe("Approval", func() {
107108

108109
It("should approve a valid request", func() {
109110
By("Creating valid request")
111+
spiffeID := fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)
110112
certificateRequest := cmapi.CertificateRequest{
111113
ObjectMeta: metav1.ObjectMeta{
112114
GenerateName: "test-request-",
113115
Namespace: f.Namespace.Name,
116+
Annotations: map[string]string{
117+
annotations.SPIFFEIdentityAnnnotationKey: spiffeID,
118+
},
114119
},
115120
Spec: cmapi.CertificateRequestSpec{
116-
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)),
121+
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, spiffeID),
117122
Duration: &metav1.Duration{Duration: time.Hour},
118123
IssuerRef: f.Config().IssuerRef,
119124
IsCA: false,
@@ -131,13 +136,18 @@ var _ = framework.CasesDescribe("Approval", func() {
131136

132137
It("should deny a request with the wrong duration", func() {
133138
By("Creating request with wrong duration")
139+
140+
spiffeID := fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)
134141
certificateRequest := cmapi.CertificateRequest{
135142
ObjectMeta: metav1.ObjectMeta{
136143
GenerateName: "test-request-",
137144
Namespace: f.Namespace.Name,
145+
Annotations: map[string]string{
146+
annotations.SPIFFEIdentityAnnnotationKey: spiffeID,
147+
},
138148
},
139149
Spec: cmapi.CertificateRequestSpec{
140-
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)),
150+
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, spiffeID),
141151
Duration: &metav1.Duration{Duration: time.Hour * 3},
142152
IssuerRef: f.Config().IssuerRef,
143153
IsCA: false,
@@ -155,13 +165,19 @@ var _ = framework.CasesDescribe("Approval", func() {
155165

156166
It("should deny a request with the wrong SPIFFE ID", func() {
157167
By("Creating request with wrong SPIFFE ID")
168+
169+
wrongSPIFFEID := fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, "not-the-right-sa")
170+
158171
certificateRequest := cmapi.CertificateRequest{
159172
ObjectMeta: metav1.ObjectMeta{
160173
GenerateName: "test-request-",
161174
Namespace: f.Namespace.Name,
175+
Annotations: map[string]string{
176+
annotations.SPIFFEIdentityAnnnotationKey: wrongSPIFFEID,
177+
},
162178
},
163179
Spec: cmapi.CertificateRequestSpec{
164-
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, "not-the-right-sa")),
180+
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, wrongSPIFFEID),
165181
Duration: &metav1.Duration{Duration: time.Hour},
166182
IssuerRef: f.Config().IssuerRef,
167183
IsCA: false,
@@ -179,13 +195,19 @@ var _ = framework.CasesDescribe("Approval", func() {
179195

180196
It("should deny a request with the wrong key usages", func() {
181197
By("Creating request with wrong key usages")
198+
199+
spiffeID := fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)
200+
182201
certificateRequest := cmapi.CertificateRequest{
183202
ObjectMeta: metav1.ObjectMeta{
184203
GenerateName: "test-request-",
185204
Namespace: f.Namespace.Name,
205+
Annotations: map[string]string{
206+
annotations.SPIFFEIdentityAnnnotationKey: spiffeID,
207+
},
186208
},
187209
Spec: cmapi.CertificateRequestSpec{
188-
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)),
210+
Request: genCSRPEM(pk, cmapi.ECDSAKeyAlgorithm, spiffeID),
189211
Duration: &metav1.Duration{Duration: time.Hour},
190212
IssuerRef: f.Config().IssuerRef,
191213
IsCA: false,
@@ -206,13 +228,19 @@ var _ = framework.CasesDescribe("Approval", func() {
206228
Expect(err).NotTo(HaveOccurred())
207229

208230
By("Creating request with wrong key type")
231+
232+
spiffeID := fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)
233+
209234
certificateRequest := cmapi.CertificateRequest{
210235
ObjectMeta: metav1.ObjectMeta{
211236
GenerateName: "test-request-",
212237
Namespace: f.Namespace.Name,
238+
Annotations: map[string]string{
239+
annotations.SPIFFEIdentityAnnnotationKey: spiffeID,
240+
},
213241
},
214242
Spec: cmapi.CertificateRequestSpec{
215-
Request: genCSRPEM(pk, cmapi.RSAKeyAlgorithm, fmt.Sprintf("spiffe://foo.bar/ns/%s/sa/%s", f.Namespace.Name, serviceAccount.Name)),
243+
Request: genCSRPEM(pk, cmapi.RSAKeyAlgorithm, spiffeID),
216244
Duration: &metav1.Duration{Duration: time.Hour},
217245
IssuerRef: f.Config().IssuerRef,
218246
IsCA: false,

0 commit comments

Comments
 (0)