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

Remove usage of ES ConfigMap and PublicCertSecret #2954

Merged
merged 14 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
28 changes: 1 addition & 27 deletions pkg/controller/compliance/compliance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/tigera/operator/pkg/dns"
"github.com/tigera/operator/pkg/render"
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"
"github.com/tigera/operator/pkg/tls/certificatemanagement"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -133,7 +132,6 @@ func add(mgr manager.Manager, c controller.Controller) error {
render.ElasticsearchComplianceControllerUserSecret, render.ElasticsearchComplianceReporterUserSecret,
render.ElasticsearchComplianceSnapshotterUserSecret, render.ElasticsearchComplianceServerUserSecret,
render.ComplianceServerCertSecret, render.ManagerInternalTLSSecretName, certificatemanagement.CASecretName,
relasticsearch.PublicCertSecret,
render.TigeraLinseedSecret, render.VoltronLinseedTLS,
render.VoltronLinseedPublicCert,
} {
Expand All @@ -143,10 +141,6 @@ func add(mgr manager.Manager, c controller.Controller) error {
}
}

if err = utils.AddConfigMapWatch(c, relasticsearch.ClusterConfigConfigMapName, common.OperatorNamespace(), &handler.EnqueueRequestForObject{}); err != nil {
return fmt.Errorf("compliance-controller failed to watch the ConfigMap resource: %w", err)
}

// Watch for changes to primary resource ManagementCluster
err = c.Watch(&source.Kind{Type: &operatorv1.ManagementCluster{}}, &handler.EnqueueRequestForObject{})
if err != nil {
Expand Down Expand Up @@ -296,16 +290,6 @@ func (r *ReconcileCompliance) Reconcile(ctx context.Context, request reconcile.R
return reconcile.Result{}, err
}

esClusterConfig, err := utils.GetElasticsearchClusterConfig(ctx, r.client)
if err != nil {
if errors.IsNotFound(err) {
r.status.SetDegraded(operatorv1.ResourceNotReady, "Elasticsearch cluster configuration is not available, waiting for it to become available", err, reqLogger)
return reconcile.Result{}, nil
}
r.status.SetDegraded(operatorv1.ResourceReadError, "Failed to get the elasticsearch cluster configuration", err, reqLogger)
return reconcile.Result{}, err
}

secretsToWatch := []string{
render.ElasticsearchComplianceBenchmarkerUserSecret, render.ElasticsearchComplianceControllerUserSecret,
render.ElasticsearchComplianceReporterUserSecret, render.ElasticsearchComplianceSnapshotterUserSecret,
Expand Down Expand Up @@ -357,15 +341,6 @@ func (r *ReconcileCompliance) Reconcile(ctx context.Context, request reconcile.R
return reconcile.Result{}, err
}
}
esgwCertificate, err := certificateManager.GetCertificate(r.client, relasticsearch.PublicCertSecret, common.OperatorNamespace())
if err != nil {
r.status.SetDegraded(operatorv1.ResourceValidationError, fmt.Sprintf("Failed to retrieve / validate %s", relasticsearch.PublicCertSecret), err, reqLogger)
return reconcile.Result{}, err
} else if esgwCertificate == nil {
log.Info("Elasticsearch gateway certificates are not available yet, waiting until they become available")
r.status.SetDegraded(operatorv1.ResourceNotReady, "Elasticsearch gateway certificates are not available yet, waiting until they become available", nil, reqLogger)
return reconcile.Result{}, nil
}

// The location of the Linseed certificate varies based on if this is a managed cluster or not.
// For standalone and management clusters, we just use Linseed's actual certificate.
Expand All @@ -384,7 +359,7 @@ func (r *ReconcileCompliance) Reconcile(ctx context.Context, request reconcile.R
r.status.SetDegraded(operatorv1.ResourceNotReady, "Linseed certificate is not available yet, waiting until it becomes available", nil, reqLogger)
return reconcile.Result{}, nil
}
trustedBundle := certificateManager.CreateTrustedBundle(managerInternalTLSSecret, esgwCertificate, linseedCertificate)
trustedBundle := certificateManager.CreateTrustedBundle(managerInternalTLSSecret, linseedCertificate)

// Get the key pairs for each component, generating them as needed.
type complianceKeyPair struct {
Expand Down Expand Up @@ -455,7 +430,6 @@ func (r *ReconcileCompliance) Reconcile(ctx context.Context, request reconcile.R
BenchmarkerKeyPair: benchmarkerKeyPair.Interface,
SnapshotterKeyPair: snapshotterKeyPair.Interface,
ReporterKeyPair: reporterKeyPair.Interface,
ESClusterConfig: esClusterConfig,
PullSecrets: pullSecrets,
Openshift: openshift,
ManagementCluster: managementCluster,
Expand Down
13 changes: 0 additions & 13 deletions pkg/controller/compliance/compliance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/tigera/operator/pkg/controller/certificatemanager"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"
rmeta "github.com/tigera/operator/pkg/render/common/meta"
"github.com/tigera/operator/pkg/render/common/secret"
"github.com/tigera/operator/pkg/tls"
Expand Down Expand Up @@ -127,15 +126,6 @@ var _ = Describe("Compliance controller tests", func() {
Expect(c.Create(ctx, &operatorv1.APIServer{ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"}, Status: operatorv1.APIServerStatus{State: operatorv1.TigeraStatusReady}})).NotTo(HaveOccurred())
Expect(c.Create(ctx, &v3.Tier{ObjectMeta: metav1.ObjectMeta{Name: "allow-tigera"}})).NotTo(HaveOccurred())
Expect(c.Create(ctx, &v3.LicenseKey{ObjectMeta: metav1.ObjectMeta{Name: "default"}, Status: v3.LicenseKeyStatus{Features: []string{common.ComplianceFeature}}})).NotTo(HaveOccurred())
Expect(c.Create(ctx, &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: relasticsearch.ClusterConfigConfigMapName, Namespace: common.OperatorNamespace()},
Data: map[string]string{
"clusterName": "cluster",
"shards": "2",
"replicas": "1",
"flowShards": "2",
},
})).NotTo(HaveOccurred())

// Create a bunch of empty secrets, such that the reconcile loop will make it to the render functionality.
Expect(c.Create(ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: render.ElasticsearchComplianceBenchmarkerUserSecret, Namespace: "tigera-operator"}})).NotTo(HaveOccurred())
Expand All @@ -149,16 +139,13 @@ var _ = Describe("Compliance controller tests", func() {
Expect(c.Create(context.Background(), certificateManager.KeyPair().Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())

esDNSNames := dns.GetServiceDNSNames(render.TigeraElasticsearchGatewaySecret, render.ElasticsearchNamespace, dns.DefaultClusterDomain)
gwKeyPair, err := certificateManager.GetOrCreateKeyPair(c, relasticsearch.PublicCertSecret, render.ElasticsearchNamespace, esDNSNames)
Expect(err).NotTo(HaveOccurred())
linseedKeyPair, err := certificateManager.GetOrCreateKeyPair(c, render.TigeraLinseedSecret, render.ElasticsearchNamespace, esDNSNames)
Expect(err).NotTo(HaveOccurred())

// For managed clusters, we also need the public cert for Linseed.
linseedPublicCert, err := certificateManager.GetOrCreateKeyPair(c, render.VoltronLinseedPublicCert, common.OperatorNamespace(), esDNSNames)
Expect(err).NotTo(HaveOccurred())

Expect(c.Create(ctx, gwKeyPair.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())
Expect(c.Create(ctx, linseedKeyPair.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())
Expect(c.Create(ctx, linseedPublicCert.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())

Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"strconv"
"strings"

relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

"github.com/elastic/cloud-on-k8s/v2/pkg/utils/stringsutil"
"github.com/go-logr/logr"
configv1 "github.com/openshift/api/config/v1"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -1193,7 +1193,8 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile

// es-kube-controllers needs to trust the ESGW certificate. We'll fetch it here and add it to the trusted bundle.
caseydavenport marked this conversation as resolved.
Show resolved Hide resolved
// Note that although we're adding this to the typhaNodeTLS trusted bundle, it will be used by es-kube-controllers. This is because
// all components within this namespace share a trusted CA bundle.
// all components within this namespace share a trusted CA bundle. This is necessary because prior to v3.13 secrets were not signed by
// a single CA so we need to include each individually.
esgwCertificate, err := certificateManager.GetCertificate(r.client, relasticsearch.PublicCertSecret, common.OperatorNamespace())
if err != nil {
r.status.SetDegraded(operator.CertificateError, fmt.Sprintf("Failed to retrieve / validate %s", relasticsearch.PublicCertSecret), err, reqLogger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"context"
"fmt"

relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1"

"github.com/tigera/operator/pkg/render/common/networkpolicy"
Expand All @@ -36,7 +38,6 @@ import (
"github.com/tigera/operator/pkg/controller/utils/imageset"
"github.com/tigera/operator/pkg/render"
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"
"github.com/tigera/operator/pkg/render/intrusiondetection/dpi"
"github.com/tigera/operator/pkg/tls/certificatemanagement"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -172,7 +173,6 @@ func add(mgr manager.Manager, c controller.Controller) error {
}

for _, secretName := range []string{
relasticsearch.PublicCertSecret,
render.ElasticsearchIntrusionDetectionUserSecret,
render.ElasticsearchIntrusionDetectionJobUserSecret,
render.ElasticsearchPerformanceHotspotsUserSecret,
Expand All @@ -192,11 +192,6 @@ func add(mgr manager.Manager, c controller.Controller) error {
return fmt.Errorf("intrusiondetection-controller failed to watch the Secret resource: %v", err)
}

// These watches are here to catch a modification to the resources we create in reconcile so the changes would be corrected.
if err = utils.AddSecretsWatch(c, relasticsearch.PublicCertSecret, render.IntrusionDetectionNamespace); err != nil {
return fmt.Errorf("intrusiondetection-controller failed to watch the Secret resource: %v", err)
}

if err = utils.AddSecretsWatch(c, render.TigeraLinseedSecret, render.IntrusionDetectionNamespace); err != nil {
return fmt.Errorf("intrusiondetection-controller failed to watch the Secret resource: %v", err)
}
Expand Down Expand Up @@ -393,6 +388,15 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
return reconcile.Result{}, err
}

if isManagedCluster {
if esClusterConfig.ClusterName() == render.DefaultElasticsearchClusterName {
msg := fmt.Sprintf("%s/%s ConfigMap must contain a 'clusterName' field that is not '%s'", common.OperatorNamespace(), relasticsearch.ClusterConfigConfigMapName, render.DefaultElasticsearchClusterName)
err = fmt.Errorf("Elasticsearch cluster name must be non-default value in managed clusters")
r.status.SetDegraded(operatorv1.InvalidConfigurationError, msg, err, reqLogger)
return reconcile.Result{}, err
}
}

secrets := []string{
render.ElasticsearchIntrusionDetectionUserSecret,
render.ElasticsearchPerformanceHotspotsUserSecret,
Expand Down Expand Up @@ -549,7 +553,6 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
ManagementCluster: isManagementCluster,
HasNoLicense: hasNoLicense,
HasNoDPIResource: hasNoDPIResource,
ESClusterConfig: esClusterConfig,
ClusterDomain: r.clusterDomain,
DPICertSecret: dpiKeyPair,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"time"

relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

esv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/elasticsearch/v1"

"github.com/tigera/operator/pkg/apis"
Expand All @@ -42,8 +44,6 @@ import (
"github.com/tigera/operator/pkg/controller/status"
"github.com/tigera/operator/pkg/controller/utils"
"github.com/tigera/operator/pkg/render"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -348,6 +348,8 @@ var _ = Describe("IntrusionDetection controller tests", func() {
},
})).ToNot(HaveOccurred())

Expect(c.Update(ctx, relasticsearch.NewClusterConfig("non-default-cluster-name", 1, 1, 1).ConfigMap())).NotTo(HaveOccurred())

_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())

Expand Down Expand Up @@ -428,6 +430,8 @@ var _ = Describe("IntrusionDetection controller tests", func() {
},
})).ToNot(HaveOccurred())

Expect(c.Update(ctx, relasticsearch.NewClusterConfig("non-default-cluster-name", 1, 1, 1).ConfigMap())).NotTo(HaveOccurred())

_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
mockStatus.AssertNumberOfCalls(GinkgoT(), "SetDegraded", 0)
Expand Down Expand Up @@ -560,6 +564,23 @@ var _ = Describe("IntrusionDetection controller tests", func() {
Expect(*ids.Spec.ComponentResources[0].ResourceRequirements.Requests.Memory()).Should(Equal(resource.MustParse(memoryRequest)))
Expect(*ids.Spec.ComponentResources[0].ResourceRequirements.Limits.Memory()).Should(Equal(resource.MustParse(memoryLimit)))
})

It("should error if Elasticsearch configuration ConfigMap contains default cluster-name field in managed cluster", func() {
Expect(c.Create(ctx, &operatorv1.ManagementClusterConnection{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
Spec: operatorv1.ManagementClusterConnectionSpec{
ManagementClusterAddr: "127.0.0.1:12345",
},
})).ToNot(HaveOccurred())

_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).Should(HaveOccurred())

Expect(c.Update(ctx, relasticsearch.NewClusterConfig("managed-cluster-name", 1, 1, 1).ConfigMap())).NotTo(HaveOccurred())

_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
})
})

Context("Reconcile for Condition status", func() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/logcollector/logcollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"strings"

relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"

"github.com/tigera/operator/pkg/render/common/networkpolicy"

v3 "github.com/tigera/api/pkg/apis/projectcalico/v3"
Expand Down Expand Up @@ -46,7 +48,6 @@ import (
"github.com/tigera/operator/pkg/controller/utils/imageset"
"github.com/tigera/operator/pkg/render"
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"
rmeta "github.com/tigera/operator/pkg/render/common/meta"
"github.com/tigera/operator/pkg/render/monitor"
"github.com/tigera/operator/pkg/tls/certificatemanagement"
Expand Down Expand Up @@ -141,7 +142,7 @@ func add(mgr manager.Manager, c controller.Controller) error {

for _, secretName := range []string{
render.ElasticsearchEksLogForwarderUserSecret,
relasticsearch.PublicCertSecret, render.S3FluentdSecretName, render.EksLogForwarderSecret,
Josh-Tigera marked this conversation as resolved.
Show resolved Hide resolved
render.S3FluentdSecretName, render.EksLogForwarderSecret,
render.SplunkFluentdTokenSecretName, render.SplunkFluentdCertificateSecretName, monitor.PrometheusTLSSecretName,
render.FluentdPrometheusTLSSecretName, render.TigeraLinseedSecret, render.VoltronLinseedPublicCert,
} {
Expand Down Expand Up @@ -545,7 +546,6 @@ func (r *ReconcileLogCollector) Reconcile(ctx context.Context, request reconcile
r.status.SetDegraded(operatorv1.ResourceReadError, "Failed to get the elasticsearch cluster configuration", err, reqLogger)
return reconcile.Result{}, err
}

eksConfig, err = getEksCloudwatchLogConfig(r.client,
instance.Spec.AdditionalSources.EksCloudwatchLog.FetchInterval,
instance.Spec.AdditionalSources.EksCloudwatchLog.Region,
Expand Down
6 changes: 0 additions & 6 deletions pkg/controller/logcollector/logcollector_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"github.com/tigera/operator/pkg/controller/status"
"github.com/tigera/operator/pkg/controller/utils"
"github.com/tigera/operator/pkg/render"
relasticsearch "github.com/tigera/operator/pkg/render/common/elasticsearch"
"github.com/tigera/operator/pkg/render/monitor"
"github.com/tigera/operator/test"
)
Expand Down Expand Up @@ -127,15 +126,10 @@ var _ = Describe("LogCollector controller tests", func() {
ObjectMeta: metav1.ObjectMeta{Name: "default"},
})).NotTo(HaveOccurred())

Expect(c.Create(ctx, relasticsearch.NewClusterConfig("cluster", 1, 1, 1).ConfigMap())).NotTo(HaveOccurred())

certificateManager, err := certificatemanager.Create(c, nil, "", common.OperatorNamespace(), certificatemanager.AllowCACreation())
Expect(err).NotTo(HaveOccurred())
Expect(c.Create(ctx, certificateManager.KeyPair().Secret(common.OperatorNamespace()))) // Persist the root-ca in the operator namespace.

kibanaTLS, err := certificateManager.GetOrCreateKeyPair(c, relasticsearch.PublicCertSecret, common.OperatorNamespace(), []string{relasticsearch.PublicCertSecret})
Expect(err).NotTo(HaveOccurred())
Expect(c.Create(ctx, kibanaTLS.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())
Expect(c.Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: render.ElasticsearchEksLogForwarderUserSecret,
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/logstorage/elastic/elastic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
esmetrics.ElasticsearchMetricsServerTLSSecret,
render.TigeraLinseedSecret,
certificatemanagement.CASecretName,
relasticsearch.PublicCertSecret,
monitor.PrometheusClientTLSSecretName,
render.ElasticsearchAdminUserSecret,
render.ElasticsearchCuratorUserSecret,
Expand All @@ -206,7 +205,6 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {

// Establish watches for secrets in the tigera-elasticsearch namespace.
for _, secretName := range []string{
relasticsearch.PublicCertSecret,
render.ElasticsearchAdminUserSecret,
render.TigeraElasticsearchInternalCertSecret,
render.OIDCUsersESSecretName,
Expand Down
Loading