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 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
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
14 changes: 0 additions & 14 deletions pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"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 @@ -1198,18 +1196,6 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile
typhaNodeTLS.TrustedBundle.AddCertificates(prometheusClientCert)
}

// 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.
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)
return reconcile.Result{}, err
}
if esgwCertificate != nil {
typhaNodeTLS.TrustedBundle.AddCertificates(esgwCertificate)
}

calicoVersion = components.EnterpriseRelease
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -171,7 +170,6 @@ func add(mgr manager.Manager, c controller.Controller) error {
}

for _, secretName := range []string{
relasticsearch.PublicCertSecret,
render.ElasticsearchIntrusionDetectionUserSecret,
render.ElasticsearchIntrusionDetectionJobUserSecret,
render.ElasticsearchPerformanceHotspotsUserSecret,
Expand All @@ -191,19 +189,10 @@ 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)
}

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

if err = utils.AddConfigMapWatch(c, render.ECKLicenseConfigMapName, render.ECKOperatorNamespace, &handler.EnqueueRequestForObject{}); err != nil {
return fmt.Errorf("intrusiondetection-controller failed to watch the ConfigMap resource: %v", err)
}
Expand Down Expand Up @@ -381,16 +370,6 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
}
}

esClusterConfig, err := utils.GetElasticsearchClusterConfig(context.Background(), r.client)
if err != nil {
if errors.IsNotFound(err) {
r.status.SetDegraded(operatorv1.ResourceNotFound, "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
}

secrets := []string{
render.ElasticsearchIntrusionDetectionUserSecret,
render.ElasticsearchPerformanceHotspotsUserSecret,
Expand Down Expand Up @@ -420,16 +399,6 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
return reconcile.Result{}, err
}

esgwCertificate, err := certificateManager.GetCertificate(r.client, relasticsearch.PublicCertSecret, common.OperatorNamespace())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, intrusion-detection-controller is one of the few managed cluster components that still talks directly to elasticsearch via es-gateway.

It does talk to Linseed in most codepaths, but when searching for security events it seems it still talks to ES.

if err != nil {
r.status.SetDegraded(operatorv1.ResourceReadError, fmt.Sprintf("Failed to retrieve / validate %s", relasticsearch.PublicCertSecret), err, reqLogger)
return reconcile.Result{}, err
} else if esgwCertificate == nil {
log.Info("Elasticsearch gateway certificate is not available yet, waiting until they become available")
r.status.SetDegraded(operatorv1.ResourceNotReady, "Elasticsearch gateway certificate 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.
linseedCertLocation := render.TigeraLinseedSecret
if isManagedCluster {
Expand Down Expand Up @@ -460,7 +429,7 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec

// Intrusion detection controller sometimes needs to make requests to outside sources. Therefore, we include
// the system root certificate bundle.
trustedBundle, err := certificateManager.CreateTrustedBundleWithSystemRootCertificates(esgwCertificate, linseedCertificate)
trustedBundle, err := certificateManager.CreateTrustedBundleWithSystemRootCertificates(linseedCertificate)
if err != nil {
r.status.SetDegraded(operatorv1.ResourceCreateError, "Unable to create tigera-ca-bundle configmap", err, reqLogger)
return reconcile.Result{}, err
Expand Down Expand Up @@ -493,7 +462,6 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
LogCollector: lc,
ESSecrets: esSecrets,
Installation: network,
ESClusterConfig: esClusterConfig,
PullSecrets: pullSecrets,
Openshift: r.provider == operatorv1.ProviderOpenShift,
ClusterDomain: r.clusterDomain,
Expand Down Expand Up @@ -546,7 +514,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 @@ -42,8 +42,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 @@ -156,9 +154,6 @@ var _ = Describe("IntrusionDetection controller tests", func() {
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.
kiibanaTLS, err := certificateManager.GetOrCreateKeyPair(c, relasticsearch.PublicCertSecret, common.OperatorNamespace(), []string{relasticsearch.PublicCertSecret})
Expect(err).NotTo(HaveOccurred())
Expect(c.Create(ctx, kiibanaTLS.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())
linseedTLS, err := certificateManager.GetOrCreateKeyPair(c, render.TigeraLinseedSecret, common.OperatorNamespace(), []string{render.TigeraLinseedSecret})
Expect(err).NotTo(HaveOccurred())
Expect(c.Create(ctx, linseedTLS.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())
Expand All @@ -168,7 +163,6 @@ var _ = Describe("IntrusionDetection controller tests", func() {
Expect(err).NotTo(HaveOccurred())
Expect(c.Create(ctx, linseedPublicCert.Secret(common.OperatorNamespace()))).NotTo(HaveOccurred())

Expect(c.Create(ctx, relasticsearch.NewClusterConfig("cluster", 1, 1, 1).ConfigMap())).NotTo(HaveOccurred())
Expect(c.Create(ctx, rtest.CreateCertSecret(render.ElasticsearchIntrusionDetectionUserSecret, common.OperatorNamespace(), render.GuardianSecretName)))
Expect(c.Create(ctx, rtest.CreateCertSecret(render.ElasticsearchPerformanceHotspotsUserSecret, common.OperatorNamespace(), render.GuardianSecretName)))
Expect(c.Create(ctx, &corev1.ConfigMap{
Expand Down
22 changes: 3 additions & 19 deletions pkg/controller/logcollector/logcollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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 +140,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 All @@ -150,10 +149,8 @@ func add(mgr manager.Manager, c controller.Controller) error {
}
}

for _, configMapName := range []string{render.FluentdFilterConfigMapName, relasticsearch.ClusterConfigConfigMapName} {
if err = utils.AddConfigMapWatch(c, configMapName, common.OperatorNamespace(), &handler.EnqueueRequestForObject{}); err != nil {
return fmt.Errorf("logcollector-controller failed to watch ConfigMap %s: %v", configMapName, err)
}
if err = utils.AddConfigMapWatch(c, render.FluentdFilterConfigMapName, common.OperatorNamespace(), &handler.EnqueueRequestForObject{}); err != nil {
return fmt.Errorf("logcollector-controller failed to watch ConfigMap %s: %v", render.FluentdFilterConfigMapName, err)
}

err = c.Watch(&source.Kind{Type: &corev1.Node{}}, &handler.EnqueueRequestForObject{})
Expand Down Expand Up @@ -531,21 +528,10 @@ func (r *ReconcileLogCollector) Reconcile(ctx context.Context, request reconcile
}

var eksConfig *render.EksCloudwatchLogConfig
var esClusterConfig *relasticsearch.ClusterConfig
if installation.KubernetesProvider == operatorv1.ProviderEKS {
log.Info("Managed kubernetes EKS found, getting necessary credentials and config")
if instance.Spec.AdditionalSources != nil {
if instance.Spec.AdditionalSources.EksCloudwatchLog != nil {
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
}

eksConfig, err = getEksCloudwatchLogConfig(r.client,
instance.Spec.AdditionalSources.EksCloudwatchLog.FetchInterval,
instance.Spec.AdditionalSources.EksCloudwatchLog.Region,
Expand All @@ -564,7 +550,6 @@ func (r *ReconcileLogCollector) Reconcile(ctx context.Context, request reconcile

fluentdCfg := &render.FluentdConfiguration{
LogCollector: instance,
ESClusterConfig: esClusterConfig,
S3Credential: s3Credential,
SplkCredential: splunkCredential,
Filters: filters,
Expand Down Expand Up @@ -615,7 +600,6 @@ func (r *ReconcileLogCollector) Reconcile(ctx context.Context, request reconcile
if hasWindowsNodes {
fluentdCfg = &render.FluentdConfiguration{
LogCollector: instance,
ESClusterConfig: esClusterConfig,
S3Credential: s3Credential,
SplkCredential: splunkCredential,
Filters: filters,
Expand Down
Loading