-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
acme.go
156 lines (132 loc) · 4.7 KB
/
acme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
Copyright 2021 The cert-manager Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package acme
import (
"context"
"encoding/base64"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cmacme "github.com/jetstack/cert-manager/pkg/apis/acme/v1"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
"github.com/jetstack/cert-manager/pkg/controller/certificatesigningrequests/util"
"github.com/jetstack/cert-manager/test/e2e/framework"
"github.com/jetstack/cert-manager/test/e2e/framework/helper/featureset"
"github.com/jetstack/cert-manager/test/e2e/suite/conformance/certificatesigningrequests"
)
var _ = framework.ConformanceDescribe("Certificates", func() {
runACMEIssuerTests(nil)
})
var _ = framework.ConformanceDescribe("Certificates with External Account Binding", func() {
runACMEIssuerTests(&cmacme.ACMEExternalAccountBinding{
KeyID: "kid-1",
})
})
func runACMEIssuerTests(eab *cmacme.ACMEExternalAccountBinding) {
// unsupportedHTTP01Features is a list of features that are not supported by the ACME
// issuer type using HTTP01
var unsupportedHTTP01Features = featureset.NewFeatureSet(
featureset.IPAddressFeature,
featureset.DurationFeature,
featureset.WildcardsFeature,
featureset.URISANsFeature,
featureset.CommonNameFeature,
featureset.KeyUsagesFeature,
featureset.EmailSANsFeature,
)
// unsupportedDNS01Features is a list of features that are not supported by the ACME
// issuer type using DNS01
var unsupportedDNS01Features = featureset.NewFeatureSet(
featureset.IPAddressFeature,
featureset.DurationFeature,
featureset.URISANsFeature,
featureset.CommonNameFeature,
featureset.KeyUsagesFeature,
featureset.EmailSANsFeature,
)
http01 := &acme{
eab: eab,
}
dns01 := &acme{
eab: eab,
}
(&certificatesigningrequests.Suite{
Name: "ACME HTTP01 Issuer",
DomainSuffix: "ingress-nginx.http01.example.com",
CreateIssuerFunc: http01.createHTTP01Issuer,
DeleteIssuerFunc: http01.delete,
UnsupportedFeatures: unsupportedHTTP01Features,
}).Define()
(&certificatesigningrequests.Suite{
Name: "ACME DNS01 Issuer",
DomainSuffix: "dns01.example.com",
CreateIssuerFunc: dns01.createDNS01Issuer,
DeleteIssuerFunc: dns01.delete,
UnsupportedFeatures: unsupportedDNS01Features,
}).Define()
(&certificatesigningrequests.Suite{
Name: "ACME HTTP01 ClusterIssuer",
DomainSuffix: "ingress-nginx.http01.example.com",
CreateIssuerFunc: http01.createHTTP01ClusterIssuer,
DeleteIssuerFunc: http01.delete,
UnsupportedFeatures: unsupportedHTTP01Features,
}).Define()
(&certificatesigningrequests.Suite{
Name: "ACME DNS01 ClusterIssuer",
DomainSuffix: "dns01.example.com",
CreateIssuerFunc: dns01.createDNS01ClusterIssuer,
DeleteIssuerFunc: dns01.delete,
UnsupportedFeatures: unsupportedDNS01Features,
}).Define()
}
type acme struct {
eab *cmacme.ACMEExternalAccountBinding
secretNamespace string
}
func (a *acme) delete(f *framework.Framework, signerName string) {
if a.eab != nil {
err := f.KubeClientSet.CoreV1().Secrets(a.secretNamespace).Delete(context.TODO(), a.eab.Key.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
}
ref, _ := util.SignerIssuerRefFromSignerName(signerName)
if ref.Type == "clusterissuers" {
err := f.CertManagerClientSet.CertmanagerV1().ClusterIssuers().Delete(context.TODO(), ref.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
}
}
func (a *acme) ensureEABSecret(f *framework.Framework, ns string) {
if a.eab == nil {
return
}
if ns == "" {
ns = f.Namespace.Name
}
sec, err := f.KubeClientSet.CoreV1().Secrets(ns).Create(context.TODO(), &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "external-account-binding-",
Namespace: ns,
},
Data: map[string][]byte{
// base64 url encode (without padding) the HMAC key
"key": []byte(base64.RawURLEncoding.EncodeToString([]byte("kid-secret-1"))),
},
}, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred())
a.eab.Key = cmmeta.SecretKeySelector{
Key: "key",
LocalObjectReference: cmmeta.LocalObjectReference{
Name: sec.Name,
},
}
a.secretNamespace = sec.Namespace
}