redhat-cop / vault-config-operator

An operator to support Haschicorp Vault configuration workflows from within Kubernetes
Apache License 2.0
110 stars 49 forks source link

Operator crashes when Creating a RandomSecret referencing non-existent PasswordPolicy #153

Closed dabelenda closed 1 year ago

dabelenda commented 1 year ago

This operator seems very promising and I wanted to test it since the beginning, I finally took the time and had lots of trouble setting up a full environment because the operator crashed very often when trying things with the CRDs.

It can be reproduced this issue with latest released version 0.8.15, when setting up an empty vault, not creating a PasswordPolicy and trying to create a RandomSecret. Creating a PasswordPolicy and referencing it in the RandomSecret makes the reconcile work.

The operator will crash in loop when trying to reconcile the RandomSecret with the following stacktrace:

1.6855987280520434e+09 INFO Observed a panic in reconciler: runtime error: invalid memory address or nil pointer dereference {"controller": "randomsecret", "controllerGroup": "redhatcop.redhat.io", "controllerKind": "RandomSecret", "RandomSecret": {"name":"makeitcrash","namespace":"vault-admin"}, "namespace": "vault-admin", "name": "makeitcrash", "reconcileID": "315e5fbf-99dd-4c39-bde2-38d33981aad3"}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1686e58]
goroutine 1165 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:118 +0x1f4
panic({0x18709c0, 0x2a5f760})
/opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:884 +0x212
github.com/redhat-cop/vault-config-operator/api/v1alpha1.(*RandomSecret).GenerateNewPassword(0xc0005361e0, {0x1d69f08?, 0xc002269290?})
/home/runner/work/vault-config-operator/vault-config-operator/api/v1alpha1/randomsecret_types.go:212 +0xd8
github.com/redhat-cop/vault-config-operator/api/v1alpha1.(*RandomSecret).PrepareInternalValues(...)
/home/runner/work/vault-config-operator/vault-config-operator/api/v1alpha1/randomsecret_types.go:120
github.com/redhat-cop/vault-config-operator/controllers.(*RandomSecretReconciler).manageReconcileLogic(0xc00015eee0, {0x1d69f08, 0xc002269290}, 0xc0005361e0)
/home/runner/work/vault-config-operator/vault-config-operator/controllers/randomsecret_controller.go:144 +0x13e
github.com/redhat-cop/vault-config-operator/controllers.(*RandomSecretReconciler).Reconcile(0xc00015eee0, {0x1d69f08, 0xc001d7e5a0}, {{{0xc000704890?, 0xc00073bd30?}, {0xc000704880?, 0x40f687?}}})
/home/runner/work/vault-config-operator/vault-config-operator/controllers/randomsecret_controller.go:108 +0x459
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1d69e60?, {0x1d69f08?, 0xc001d7e5a0?}, {{{0xc000704890?, 0x19bfb80?}, {0xc000704880?, 0x405094?}}})
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:121 +0xc8
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc00035d900, {0x1d69e60, 0xc00029f340}, {0x18d8c80?, 0xc00082cfe0?})
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:320 +0x33c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc00035d900, {0x1d69e60, 0xc00029f340})
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:273 +0x1d9
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:234 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
/home/runner/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.13.0/pkg/internal/controller/controller.go:230 +0x333
tmmorin commented 1 year ago

I happen to have it the same issue, and found that issue #102 was already filed some time ago, but the patch done at the time isn't sufficient.

I proposed PR #155 to fix this.