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

feat: Add support to extra dns names #52

Merged
merged 2 commits into from
Jan 11, 2023
Merged
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 @@ -51,6 +51,7 @@ The following code snippet is taken from the Gatekeeper project:
CAName: caName,
CAOrganization: caOrganization,
DNSName: dnsName,
ExtraDNSNames: extraDnsNames,
IsReady: setupFinished,
VWHName: vwhName,
}); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/rotator/rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type CertRotator struct {
CAName string
CAOrganization string
DNSName string
ExtraDNSNames []string
IsReady chan struct{}
Webhooks []WebhookInfo
RestartOnSecretRefresh bool
Expand Down Expand Up @@ -475,14 +476,14 @@ func (cr *CertRotator) CreateCACert(begin, end time.Time) (*KeyPairArtifacts, er
// CreateCertPEM takes the results of CreateCACert and uses it to create the
// PEM-encoded public certificate and private key, respectively
func (cr *CertRotator) CreateCertPEM(ca *KeyPairArtifacts, begin, end time.Time) ([]byte, []byte, error) {
dnsNames := []string{cr.DNSName}
dnsNames = append(dnsNames, cr.ExtraDNSNames...)
templ := &x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
CommonName: cr.DNSName,
},
DNSNames: []string{
cr.DNSName,
},
DNSNames: dnsNames,
NotBefore: begin,
NotAfter: end,
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
Expand Down
10 changes: 9 additions & 1 deletion pkg/rotator/rotator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var (
CAName: "ca",
CAOrganization: "org",
DNSName: "service.namespace",
ExtraDNSNames: []string{
"other-service.namespace",
},
ExtKeyUsages: &[]x509.ExtKeyUsage{
x509.ExtKeyUsageClientAuth,
x509.ExtKeyUsageServerAuth,
Expand All @@ -48,7 +51,12 @@ func TestCertSigning(t *testing.T) {
}

if !cr.validServerCert(caArtifacts.CertPEM, cert, key) {
t.Error("Generated cert is not valid")
t.Error("Generated cert is not valid for common name")
}

valid, err := ValidCert(caArtifacts.CertPEM, cert, key, cr.ExtraDNSNames[0], cr.ExtKeyUsages, lookaheadTime())
if err != nil || !valid {
t.Error("Generated cert is not valid for ExtraDnsName")
}
}

Expand Down