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

Allow disabling Reaper auth #1163

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion apis/reaper/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type ReaperTemplate struct {

// Defines the secret which contains the username and password for the Reaper UI and REST API authentication.
// +optional
UiUserSecretRef corev1.LocalObjectReference `json:"uiUserSecretRef,omitempty"`
UiUserSecretRef *corev1.LocalObjectReference `json:"uiUserSecretRef,omitempty"`
Miles-Garnsey marked this conversation as resolved.
Show resolved Hide resolved

// SecretsProvider defines whether the secrets used for credentials and certs will be backed
// by an external secret backend. This moves the responsibility of generating and storing
Expand Down
6 changes: 5 additions & 1 deletion apis/reaper/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion controllers/k8ssandra/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (r *K8ssandraClusterReconciler) reconcileReaper(

logger.Info("Reaper present for DC " + actualDc.DatacenterName())

desiredReaper, err := reaper.NewReaper(reaperKey, kc, actualDc, reaperTemplate)
desiredReaper, err := reaper.NewReaper(reaperKey, kc, actualDc, reaperTemplate, logger)

if err != nil {
logger.Error(err, "failed to create Reaper API object")
return result.Error(err)
Expand Down
14 changes: 9 additions & 5 deletions controllers/k8ssandra/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,26 @@
var uiUserSecretRef corev1.LocalObjectReference
if kc.Spec.Reaper != nil {
cassandraUserSecretRef = kc.Spec.Reaper.CassandraUserSecretRef
uiUserSecretRef = kc.Spec.Reaper.UiUserSecretRef
if kc.Spec.Reaper.UiUserSecretRef != nil {
uiUserSecretRef = *kc.Spec.Reaper.UiUserSecretRef
}

Check warning on line 71 in controllers/k8ssandra/secrets.go

View check run for this annotation

Codecov / codecov/patch

controllers/k8ssandra/secrets.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}
if cassandraUserSecretRef.Name == "" {
cassandraUserSecretRef.Name = reaper.DefaultUserSecretName(kc.SanitizedName())
}
if uiUserSecretRef.Name == "" {
if kc.Spec.Reaper.UiUserSecretRef == nil {
uiUserSecretRef.Name = reaper.DefaultUiSecretName(kc.SanitizedName())
}
kcKey := utils.GetKey(kc)
if err := secret.ReconcileSecret(ctx, r.Client, cassandraUserSecretRef.Name, kcKey); err != nil {
logger.Error(err, "Failed to reconcile Reaper CQL user secret", "ReaperCassandraUserSecretRef", cassandraUserSecretRef)
return result.Error(err)
}
if err := secret.ReconcileSecret(ctx, r.Client, uiUserSecretRef.Name, kcKey); err != nil {
logger.Error(err, "Failed to reconcile Reaper UI secret", "ReaperUiUserSecretRef", uiUserSecretRef)
return result.Error(err)
if kc.Spec.Reaper.UiUserSecretRef == nil || kc.Spec.Reaper.UiUserSecretRef.Name != "" {
if err := secret.ReconcileSecret(ctx, r.Client, uiUserSecretRef.Name, kcKey); err != nil {
logger.Error(err, "Failed to reconcile Reaper UI secret", "ReaperUiUserSecretRef", uiUserSecretRef)
return result.Error(err)
}

Check warning on line 88 in controllers/k8ssandra/secrets.go

View check run for this annotation

Codecov / codecov/patch

controllers/k8ssandra/secrets.go#L86-L88

Added lines #L86 - L88 were not covered by tests
Comment on lines +76 to +88
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @Miles-Garnsey @adejanovski ,

Isn't this change backward incompatible?

I just opened a GitHub issue #1269

}
logger.Info("Reaper user secrets successfully reconciled")

Expand Down
7 changes: 4 additions & 3 deletions controllers/reaper/reaper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ func (r *ReaperReconciler) configureReaper(ctx context.Context, actualReaper *re
}

func (r *ReaperReconciler) getReaperUICredentials(ctx context.Context, actualReaper *reaperapi.Reaper, logger logr.Logger) (string, string, error) {
if actualReaper.Spec.UiUserSecretRef.Name == "" {

if actualReaper.Spec.UiUserSecretRef == nil || actualReaper.Spec.UiUserSecretRef.Name == "" {
// The UI user secret doesn't exist, meaning auth is disabled
return "", "", nil
}
Expand Down Expand Up @@ -383,11 +384,11 @@ func (r *ReaperReconciler) collectAuthVarsForType(ctx context.Context, actualRea
secretRef = &actualReaper.Spec.CassandraUserSecretRef
envVars = []*corev1.EnvVar{}
case "ui":
secretRef = &actualReaper.Spec.UiUserSecretRef
secretRef = actualReaper.Spec.UiUserSecretRef
envVars = []*corev1.EnvVar{reaper.EnableAuthVar}
}

if len(secretRef.Name) > 0 && !actualReaper.Spec.UseExternalSecrets() {
if secretRef != nil && len(secretRef.Name) > 0 && !actualReaper.Spec.UseExternalSecrets() {
secretKey := types.NamespacedName{Namespace: actualReaper.Namespace, Name: secretRef.Name}
if secret, err := r.getSecret(ctx, secretKey); err != nil {
logger.Error(err, "Failed to get Cassandra authentication secret", authType, secretKey)
Expand Down
4 changes: 2 additions & 2 deletions controllers/reaper/reaper_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func testCreateReaperWithAuthEnabled(t *testing.T, ctx context.Context, k8sClien
t.Log("create the Reaper object and modify it")
rpr := newReaper(testNamespace)
rpr.Spec.CassandraUserSecretRef.Name = "top-secret-cass"
rpr.Spec.UiUserSecretRef.Name = "top-secret-ui"
rpr.Spec.UiUserSecretRef = &corev1.LocalObjectReference{Name: "top-secret-ui"}
err = k8sClient.Create(ctx, rpr)
require.NoError(t, err)

Expand Down Expand Up @@ -477,7 +477,7 @@ func testCreateReaperWithAuthEnabledExternalSecret(t *testing.T, ctx context.Con
//lint:ignore SA1019 Verify deprecated method is ineffective
rpr.Spec.JmxUserSecretRef.Name = "top-secret-jmx" //nolint:staticcheck

rpr.Spec.UiUserSecretRef.Name = "top-secret-ui"
rpr.Spec.UiUserSecretRef = &corev1.LocalObjectReference{Name: "top-secret-ui"}
err = k8sClient.Create(ctx, rpr)
require.NoError(t, err)

Expand Down
17 changes: 12 additions & 5 deletions pkg/reaper/resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reaper

import (
"github.com/go-logr/logr"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
k8ssandraapi "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1"
reaperapi "github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1"
Expand Down Expand Up @@ -32,6 +33,7 @@
kc *k8ssandraapi.K8ssandraCluster,
dc *cassdcapi.CassandraDatacenter,
reaperTemplate *reaperapi.ReaperClusterTemplate,
logger logr.Logger,
) (*reaperapi.Reaper, error) {
labels := createResourceLabels(kc)
var anns map[string]string
Expand All @@ -58,6 +60,7 @@
},
}
if kc.Spec.IsAuthEnabled() && !kc.Spec.UseExternalSecrets() {
logger.Info("Auth is enabled, adding user secrets to Reaper spec")

Check warning on line 63 in pkg/reaper/resource.go

View check run for this annotation

Codecov / codecov/patch

pkg/reaper/resource.go#L63

Added line #L63 was not covered by tests
// if auth is enabled in this cluster, the k8ssandra controller will automatically create two secrets for
// Reaper: one for CQL and JMX connections, one for the UI. Here we assume that these secrets exist. If the
// secrets were specified by the user they should be already present in desiredReaper.Spec; otherwise, we assume
Expand All @@ -67,8 +70,8 @@
desiredReaper.Spec.CassandraUserSecretRef.Name = DefaultUserSecretName(kc.SanitizedName())
}
// Note: deliberately skip JmxUserSecretRef, which is deprecated.
if desiredReaper.Spec.UiUserSecretRef.Name == "" {
desiredReaper.Spec.UiUserSecretRef.Name = DefaultUiSecretName(kc.SanitizedName())
if kc.Spec.Reaper.UiUserSecretRef == nil && kc.Spec.IsAuthEnabled() {
desiredReaper.Spec.UiUserSecretRef = &corev1.LocalObjectReference{Name: DefaultUiSecretName(kc.SanitizedName())}

Check warning on line 74 in pkg/reaper/resource.go

View check run for this annotation

Codecov / codecov/patch

pkg/reaper/resource.go#L73-L74

Added lines #L73 - L74 were not covered by tests
}

if desiredReaper.Spec.ResourceMeta == nil {
Expand All @@ -79,10 +82,14 @@
if err != nil {
return desiredReaper, err
}
err = secret.AddInjectionAnnotationReaperContainers(&desiredReaper.Spec.ResourceMeta.Pods, desiredReaper.Spec.UiUserSecretRef.Name)
if err != nil {
return desiredReaper, err
if desiredReaper.Spec.UiUserSecretRef != nil && desiredReaper.Spec.UiUserSecretRef.Name != "" {
err = secret.AddInjectionAnnotationReaperContainers(&desiredReaper.Spec.ResourceMeta.Pods, desiredReaper.Spec.UiUserSecretRef.Name)
if err != nil {
return desiredReaper, err
}

Check warning on line 89 in pkg/reaper/resource.go

View check run for this annotation

Codecov / codecov/patch

pkg/reaper/resource.go#L85-L89

Added lines #L85 - L89 were not covered by tests
}
} else {
logger.Info("Auth not enabled, no secrets added to Reaper spec")

Check warning on line 92 in pkg/reaper/resource.go

View check run for this annotation

Codecov / codecov/patch

pkg/reaper/resource.go#L91-L92

Added lines #L91 - L92 were not covered by tests
}
// If the cluster is already initialized and some DCs are flagged as stopped, we cannot achieve QUORUM in the
// cluster for Reaper's keyspace. In this case we simply skip schema migration, otherwise Reaper wouldn't be able to
Expand Down
Loading