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

fix(tls): use fixed-length cert CommonNames #968

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:4.0.0-dev
createdAt: "2024-10-10T18:16:26Z"
createdAt: "2024-11-05T19:02:47Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down
11 changes: 6 additions & 5 deletions internal/controllers/common/resource_definitions/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
certv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
certMeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
"github.com/cryostatio/cryostat-operator/internal/controllers/common"
"github.com/cryostatio/cryostat-operator/internal/controllers/constants"
"github.com/cryostatio/cryostat-operator/internal/controllers/model"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -62,7 +63,7 @@ func NewCryostatCACert(gvk *schema.GroupVersionKind, cr *model.CryostatInstance)
Namespace: cr.InstallNamespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("ca.%s.cert-manager", cr.Name),
CommonName: constants.CryostatCATLSCommonName,
SecretName: common.ClusterUniqueNameWithPrefix(gvk, "ca", cr.Name, cr.InstallNamespace),
IssuerRef: certMeta.ObjectReference{
Name: cr.Name + "-self-signed",
Expand All @@ -79,7 +80,7 @@ func NewCryostatCert(cr *model.CryostatInstance, keystoreSecretName string) *cer
Namespace: cr.InstallNamespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("%s.%s.svc", cr.Name, cr.InstallNamespace),
CommonName: constants.CryostatTLSCommonName,
DNSNames: []string{
cr.Name,
fmt.Sprintf("%s.%s.svc", cr.Name, cr.InstallNamespace),
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewReportsCert(cr *model.CryostatInstance) *certv1.Certificate {
Namespace: cr.InstallNamespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("%s-reports.%s.svc", cr.Name, cr.InstallNamespace),
CommonName: constants.ReportsTLSCommonName,
DNSNames: []string{
cr.Name + "-reports",
fmt.Sprintf("%s-reports.%s.svc", cr.Name, cr.InstallNamespace),
Expand All @@ -140,7 +141,7 @@ func NewAgentCert(cr *model.CryostatInstance, namespace string, gvk *schema.Grou
Namespace: cr.InstallNamespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("*.%s.pod", namespace),
CommonName: constants.AgentsTLSCommonName,
DNSNames: []string{
fmt.Sprintf("*.%s.pod", namespace),
},
Expand All @@ -163,7 +164,7 @@ func NewAgentProxyCert(cr *model.CryostatInstance) *certv1.Certificate {
Namespace: cr.InstallNamespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("%s-agent.%s.svc", cr.Name, cr.InstallNamespace),
CommonName: constants.AgentAuthProxyTLSCommonName,
DNSNames: []string{
cr.Name + "-agent",
fmt.Sprintf("%s-agent.%s.svc", cr.Name, cr.InstallNamespace),
Expand Down
6 changes: 6 additions & 0 deletions internal/controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ const (
targetNamespaceCRLabelPrefix = "operator.cryostat.io/"
TargetNamespaceCRNameLabel = targetNamespaceCRLabelPrefix + "name"
TargetNamespaceCRNamespaceLabel = targetNamespaceCRLabelPrefix + "namespace"

CryostatCATLSCommonName = "cryostat-ca-cert-manager"
CryostatTLSCommonName = "cryostat"
ReportsTLSCommonName = "cryostat-reports"
AgentsTLSCommonName = "cryostat-agent"
AgentAuthProxyTLSCommonName = "cryostat-agent-proxy"
)
10 changes: 5 additions & 5 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ func (r *TestResources) NewCryostatCert() *certv1.Certificate {
Namespace: r.Namespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf(r.Name+".%s.svc", r.Namespace),
CommonName: "cryostat",
DNSNames: []string{
r.Name,
fmt.Sprintf(r.Name+".%s.svc", r.Namespace),
Expand Down Expand Up @@ -1065,7 +1065,7 @@ func (r *TestResources) NewReportsCert() *certv1.Certificate {
Namespace: r.Namespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf(r.Name+"-reports.%s.svc", r.Namespace),
CommonName: "cryostat-reports",
DNSNames: []string{
r.Name + "-reports",
fmt.Sprintf(r.Name+"-reports.%s.svc", r.Namespace),
Expand All @@ -1091,7 +1091,7 @@ func (r *TestResources) NewAgentProxyCert() *certv1.Certificate {
Namespace: r.Namespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf(r.Name+"-agent.%s.svc", r.Namespace),
CommonName: "cryostat-agent-proxy",
DNSNames: []string{
r.Name + "-agent",
fmt.Sprintf(r.Name+"-agent.%s.svc", r.Namespace),
Expand All @@ -1117,7 +1117,7 @@ func (r *TestResources) NewCACert() *certv1.Certificate {
Namespace: r.Namespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("ca.%s.cert-manager", r.Name),
CommonName: "cryostat-ca-cert-manager",
SecretName: r.getClusterUniqueNameForCA(),
IssuerRef: certMeta.ObjectReference{
Name: r.Name + "-self-signed",
Expand All @@ -1135,7 +1135,7 @@ func (r *TestResources) NewAgentCert(namespace string) *certv1.Certificate {
Namespace: r.Namespace,
},
Spec: certv1.CertificateSpec{
CommonName: fmt.Sprintf("*.%s.pod", namespace),
CommonName: "cryostat-agent",
DNSNames: []string{
fmt.Sprintf("*.%s.pod", namespace),
},
Expand Down
Loading