Skip to content

Commit

Permalink
update password (#4952)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowinkeyy authored Oct 23, 2024
1 parent 32f6973 commit 786c518
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
4 changes: 4 additions & 0 deletions controllers/objectstorage/api/v1/objectstorageuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

// ObjectStorageUserSpec defines the desired state of ObjectStorageUser
type ObjectStorageUserSpec struct {
// +kubebuilder:default=0
SecretKeyVersion int64 `json:"secretKeyVersion,omitempty"`
}

// ObjectStorageUserStatus defines the observed state of ObjectStorageUser
Expand All @@ -34,6 +36,8 @@ type ObjectStorageUserStatus struct {
SecretKey string `json:"secretKey,omitempty"`
Internal string `json:"internal,omitempty"`
External string `json:"external,omitempty"`
// +kubebuilder:default=0
SecretKeyVersion int64 `json:"secretKeyVersion,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2023 sealos.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2023 sealos.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -48,6 +34,11 @@ spec:
type: object
spec:
description: ObjectStorageUserSpec defines the desired state of ObjectStorageUser
properties:
secretKeyVersion:
default: 0
format: int64
type: integer
type: object
status:
description: ObjectStorageUserStatus defines the observed state of ObjectStorageUser
Expand All @@ -66,6 +57,10 @@ spec:
type: integer
secretKey:
type: string
secretKeyVersion:
default: 0
format: int64
type: integer
size:
description: unit is byte
format: int64
Expand Down
14 changes: 0 additions & 14 deletions controllers/objectstorage/config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2023 sealos.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ func (r *ObjectStorageUserReconciler) Reconcile(ctx context.Context, req ctrl.Re

updated := r.initObjectStorageUser(user, username, quota.Value())

pwdUpdated := false

if user.Spec.SecretKeyVersion > user.Status.SecretKeyVersion {
user.Status.SecretKey = rand.String(16)
user.Status.SecretKeyVersion = user.Spec.SecretKeyVersion
pwdUpdated = true
updated = true
}

accessKey := user.Status.AccessKey
secretKey := user.Status.SecretKey

Expand All @@ -170,6 +179,13 @@ func (r *ObjectStorageUserReconciler) Reconcile(ctx context.Context, req ctrl.Re
}
}

if pwdUpdated {
if err := r.OSAdminClient.SetUser(ctx, accessKey, secretKey, madmin.AccountEnabled); err != nil {
r.Logger.Error(err, "failed to set user secret key", "name", accessKey)
}
r.Logger.V(1).Info("[user] password change info", "name", user.Name, "spec secret key version", user.Spec.SecretKeyVersion)
}

secret := &corev1.Secret{}
if err := r.Get(ctx, client.ObjectKey{Name: OSKeySecret, Namespace: userNamespace}, secret); err != nil {
if !errors.IsNotFound(err) {
Expand Down

0 comments on commit 786c518

Please sign in to comment.