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

Regenerate user passwords when user reconciles #896

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions api/v1beta1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type UserSpec struct {
//
// Note that this import only occurs at creation time, and is ignored once a password has been set on a User.
ImportCredentialsSecret *corev1.LocalObjectReference `json:"importCredentialsSecret,omitempty"`
// Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
// Defaults to false if omitted.
// +kubebuilder:validation:Optional
AutoUpdateCredentialsSecret bool `json:"autoUpdateCredentialsSecret,omitempty"`
}

// UserStatus defines the observed state of User.
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rabbitmq.com_users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ spec:
spec:
description: Spec configures the desired state of the User object.
properties:
autoUpdateCredentialsSecret:
description: |-
Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
Defaults to false if omitted.
type: boolean
importCredentialsSecret:
description: |-
Defines a Secret containing the credentials for the User. If this field is omitted, random a username and
Expand Down
5 changes: 3 additions & 2 deletions controllers/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (r *UserReconciler) declareCredentials(ctx context.Context, user *topology.
for i := range credentialSecret.ObjectMeta.OwnerReferences {
credentialSecret.ObjectMeta.OwnerReferences[i].BlockOwnerDeletion = ptr.To(false)
}
credentialSecret.Data = credentialSecretData
return nil
})
return apiError
Expand Down Expand Up @@ -188,7 +189,7 @@ func (r *UserReconciler) setUserStatus(ctx context.Context, user *topology.User,
func (r *UserReconciler) DeclareFunc(ctx context.Context, client rabbitmqclient.Client, obj topology.TopologyResource) error {
logger := ctrl.LoggerFrom(ctx)
user := obj.(*topology.User)
if user.Status.Credentials == nil || user.Status.Username == "" {
if user.Status.Credentials == nil || user.Status.Username == "" || user.Spec.AutoUpdateCredentialsSecret {
var username string
if user.Status.Credentials != nil && user.Status.Username == "" {
// Only run once for migration to set user.Status.Username on existing resources
Expand All @@ -198,7 +199,7 @@ func (r *UserReconciler) DeclareFunc(ctx context.Context, client rabbitmqclient.
}
username = string(credentials.Data["username"])
} else {
logger.Info("User does not yet have a Credentials Secret; generating", "user", user.Name)
logger.Info("User does not yet have a Credentials Secret or AutoUpdateCredentialsSecret is enabled; generating Credentials Secret", "user", user.Name)
var err error
if username, err = r.declareCredentials(ctx, user); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions docs/api/rabbitmq.com.ref.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,8 @@ password will be generated. The Secret must have the following keys in its Data


Note that this import only occurs at creation time, and is ignored once a password has been set on a User.
| *`autoUpdateCredentialsSecret`* __boolean__ | Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
Defaults to false if omitted.
|===


Expand Down
Loading