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 all 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 CHANGELOG/CHANGELOG-1.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Changelog for the K8ssandra Operator, new PRs should update the `unreleased` sec
When cutting a new release, update the `unreleased` heading to the tag being generated and date, like `## vX.Y.Z - YYYY-MM-DD` and create a new placeholder section for `unreleased` entries.

## unreleased

* [ENHANCEMENT] [#1160](https://github.com/k8ssandra/k8ssandra-operator/issues/1160) Allow disabling Reaper front-end auth.
- [ENHANCEMENT] [#1115](https://github.com/k8ssandra/k8ssandra-operator/issues/1115) Add a validation check for the projected pod names length
* [CHANGE] [#1050](https://github.com/k8ssandra/k8ssandra-operator/issues/1050) Remove unnecessary requeues in the Medusa controllers
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ catalog-push: ## Push a catalog image.
# E2E tests from kuttl
kuttl-test: install-kuttl docker-build
./bin/kubectl-kuttl test --kind-context=k8ssandra-0 --start-kind=false --test test-servicemonitors
./bin/kubectl-kuttl test --kind-context=k8ssandra-0 --start-kind=false --test test-cassandra-versions
./bin/kubectl-kuttl test --kind-context=k8ssandra-0 --start-kind=false --test test-user-defined-ns
# ./bin/kubectl-kuttl test --kind-context=k8ssandra-0 --start-kind=false --test test-cassandra-versions
# ./bin/kubectl-kuttl test --kind-context=k8ssandra-0 --start-kind=false --test test-user-defined-ns

# Install kuttl for e2e tests.
install-kuttl:
Expand Down
4 changes: 2 additions & 2 deletions apis/reaper/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type ReaperTemplate struct {
// this field is ignored.
JmxUserSecretRef corev1.LocalObjectReference `json:"jmxUserSecretRef,omitempty"`

// Defines the secret which contains the username and password for the Reaper UI and REST API authentication.
// Defines the secret which contains the username and password for the Reaper UI and REST API authentication. When UiUserSecretRef.Name == "", authentication is turned off in the front-end only.
// +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.

4 changes: 3 additions & 1 deletion config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29787,7 +29787,9 @@ spec:
type: array
uiUserSecretRef:
description: Defines the secret which contains the username and
password for the Reaper UI and REST API authentication.
password for the Reaper UI and REST API authentication. When
UiUserSecretRef.Name == "", authentication is turned off in
the front-end only.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Expand Down
3 changes: 2 additions & 1 deletion config/crd/bases/reaper.k8ssandra.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,8 @@ spec:
type: array
uiUserSecretRef:
description: Defines the secret which contains the username and password
for the Reaper UI and REST API authentication.
for the Reaper UI and REST API authentication. When UiUserSecretRef.Name
== "", authentication is turned off in the front-end only.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Expand Down
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
Loading
Loading