Skip to content

Commit de7764d

Browse files
committed
feat: bypass hostname check
relates to #76 [skip ci]
1 parent 1eeede6 commit de7764d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

internal/controller/csr_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Config struct {
5656
BypassDNSResolution bool
5757
IgnoreNonSystemNodeCsr bool
5858
AllowedDNSNames int
59+
BypassHostnameCheck bool
5960
}
6061

6162
// CertificateSigningRequestReconciler reconciles a CertificateSigningRequest object
@@ -73,7 +74,7 @@ type CertificateSigningRequestReconciler struct {
7374
// Reconcile will perform a series of checks before deciding whether the CSR should be approved or denied
7475
// cyclomatic complexity is high (over 15), but this improves
7576
// readibility for the programmer, therefore we ignore the linting error
76-
//nolint: gocyclo
77+
// nolint: gocyclo
7778
func (r *CertificateSigningRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, returnErr error) {
7879
l := log.FromContext(ctx)
7980

internal/controller/regex_ip_checks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
// DNSCheck is a function checking that the DNS name:
1616
// complies with the provider-specific regex
1717
// is resolvable (this check can be opted out with a parameter)
18+
// nolint: gocyclo
1819
func (r *CertificateSigningRequestReconciler) DNSCheck(ctx context.Context, csr *certificatesv1.CertificateSigningRequest, x509cr *x509.CertificateRequest) (valid bool, reason string, err error) {
1920
if valid = (len(x509cr.DNSNames) <= r.AllowedDNSNames); !valid {
2021
reason = "The x509 Cert Request contains more DNS names than allowed through the config flag"
@@ -41,7 +42,7 @@ func (r *CertificateSigningRequestReconciler) DNSCheck(ctx context.Context, csr
4142
for _, sanDNSName := range x509cr.DNSNames {
4243
hostname := strings.TrimPrefix(csr.Spec.Username, "system:node:")
4344

44-
if valid = strings.HasPrefix(sanDNSName, hostname); !valid {
45+
if valid = strings.HasPrefix(sanDNSName, hostname); !valid && !r.BypassHostnameCheck {
4546
reason = "The SAN DNS Name in the x509 CSR is not prefixed by the node name (hostname)"
4647
return
4748
}

0 commit comments

Comments
 (0)