Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement E-mail SAN annotation #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ metadata:
cert-manager.io/alt-names: "mycooldomain.com,mysecondarydomain.com" # Optional, no default
cert-manager.io/ip-sans: "10.20.30.40,192.168.192.168" # Optional, no default
cert-manager.io/uri-sans: "spiffe://trustdomain/workload" # Optional, no default
cert-manager.io/email-sans: "[email protected],[email protected]" # Optional, no default
cert-manager.io/private-key-algorithm: "ECDSA" # Optional, defaults to RSA
spec:
host: app.service.clustername.domain.com # will be added to the Subject Alternative Names of the CertificateRequest
Expand Down
11 changes: 8 additions & 3 deletions internal/controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ func (r *Route) buildNextCR(ctx context.Context, route *routev1.Route, revision
uriSans = append(uriSans, ur)
}
}
emailSans := []string{}
if metav1.HasAnnotation(route.ObjectMeta, cmapi.EmailsAnnotationKey) {
emailSans = strings.Split(route.Annotations[cmapi.EmailsAnnotationKey], ",")
}

privateKeyAlgorithm, found := route.Annotations[cmapi.PrivateKeyAlgorithmAnnotationKey]
if !found {
Expand Down Expand Up @@ -446,9 +450,10 @@ func (r *Route) buildNextCR(ctx context.Context, route *routev1.Route, revision
Subject: pkix.Name{
CommonName: route.Annotations[cmapi.CommonNameAnnotationKey],
},
DNSNames: dnsNames,
IPAddresses: ipSans,
URIs: uriSans,
DNSNames: dnsNames,
IPAddresses: ipSans,
URIs: uriSans,
EmailAddresses: emailSans,
},
key,
)
Expand Down
60 changes: 60 additions & 0 deletions internal/controller/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,65 @@ func TestRoute_buildNextCR(t *testing.T) {
},
wantErr: nil,
},
{
name: "With subject alternative names",
revision: 1337,
route: generateRouteStatus(&routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: "some-route",
Namespace: "some-namespace",
Annotations: map[string]string{
cmapi.IsNextPrivateKeySecretLabelKey: string(rsaPEM),
cmapi.AltNamesAnnotationKey: "mycooldomain.com,mysecondarydomain.com",
cmapi.IPSANAnnotationKey: "10.20.30.40,192.168.192.168",
cmapi.URISANAnnotationKey: "spiffe://trustdomain/workload",
cmapi.EmailsAnnotationKey: "[email protected],[email protected]",
},
},
Spec: routev1.RouteSpec{
Host: "some-host.some-domain.tld",
},
Status: routev1.RouteStatus{
Ingress: []routev1.RouteIngress{
{
Host: "some-host.some-domain.tld",
Conditions: []routev1.RouteIngressCondition{
{
Type: "Admitted",
Status: "True",
},
},
},
},
},
},
true),
want: &cmapi.CertificateRequest{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "some-route-",
Namespace: "some-namespace",
Annotations: map[string]string{
cmapi.CertificateRequestRevisionAnnotationKey: "1338",
},
},
Spec: cmapi.CertificateRequestSpec{
Usages: []cmapi.KeyUsage{cmapi.UsageServerAuth, cmapi.UsageDigitalSignature, cmapi.UsageKeyEncipherment},
Duration: &metav1.Duration{Duration: DefaultCertificateDuration},
},
},
wantCSR: &x509.CertificateRequest{
SignatureAlgorithm: x509.SHA256WithRSA,
PublicKeyAlgorithm: x509.RSA,
Subject: pkix.Name{
CommonName: "",
},
DNSNames: []string{"some-host.some-domain.tld", "mycooldomain.com", "mysecondarydomain.com"},
IPAddresses: []net.IP{net.IPv4(10, 20, 30, 40), net.IPv4(192, 168, 192, 168)},
URIs: []*url.URL{{Scheme: "spiffe", Host: "trustdomain", Path: "workload"}},
EmailAddresses: []string{"[email protected]", "[email protected]"},
},
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1176,6 +1235,7 @@ func TestRoute_buildNextCR(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.wantCSR.DNSNames, parsedCSR.DNSNames)
assert.Equal(t, tt.wantCSR.IPAddresses, parsedCSR.IPAddresses)
assert.Equal(t, tt.wantCSR.EmailAddresses, parsedCSR.EmailAddresses)
assert.Equal(t, tt.wantCSR.PublicKeyAlgorithm, parsedCSR.PublicKeyAlgorithm)
assert.Equal(t, tt.wantCSR.SignatureAlgorithm, parsedCSR.SignatureAlgorithm)
assert.Equal(t, tt.wantCSR.Subject.CommonName, parsedCSR.Subject.CommonName)
Expand Down