-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
object: add support for user s3 key for cephobjectstoreuser
CephObjectStoreUser should optionally be able to reference a secret where S3 key is defined. This enables us to specify the accesskey and accesssecret rather than those values being randomly generated. Closes: rook#11563 Signed-off-by: parth-gr <partharora1010@gmail.com>
- Loading branch information
Showing
6 changed files
with
306 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2016 The Rook Authors. All rights reserved. | ||
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. | ||
*/ | ||
|
||
package secret | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"emperror.dev/errors" | ||
"github.com/ceph/go-ceph/rgw/admin" | ||
) | ||
|
||
const ( | ||
//#nosec G101 -- This is the name of an annotation key, not a secret | ||
updateObjectUserSecretAnnotation = "rook.io/source-of-truth" | ||
sourceOfTruthSecret = "secret" | ||
) | ||
|
||
func ValidateCredentials(accessKey, secretKey string, credentials []admin.UserKeySpec) ([]admin.UserKeySpec, error) { | ||
// if len is 0 just update the credentials array with the accessKey and secretKey key | ||
if len(credentials) == 0 { | ||
credentials = []admin.UserKeySpec{ | ||
{AccessKey: accessKey, | ||
SecretKey: secretKey}} | ||
return credentials, nil | ||
} | ||
// match if the credentials array contains the accessKey and secretKey key | ||
for i := range credentials { | ||
if credentials[i].AccessKey == accessKey && credentials[0].SecretKey == secretKey { | ||
return credentials, nil | ||
} | ||
} | ||
|
||
return credentials, errors.Errorf("secret keys data is invalid, please update the secret with cvalid format") | ||
} | ||
|
||
func UnmarshalKeys(credentials []byte) ([]admin.UserKeySpec, error) { | ||
var userKeys []admin.UserKeySpec | ||
err := json.Unmarshal(credentials, &userKeys) | ||
if err != nil { | ||
return userKeys, errors.Wrapf(err, "unable to unmarshal credentials from the object secret") | ||
} | ||
return userKeys, nil | ||
} | ||
|
||
func ForceUpdateObjectUserSecret(annotations map[string]string) bool { | ||
if value, found := annotations[updateObjectUserSecretAnnotation]; found { | ||
if strings.EqualFold(value, sourceOfTruthSecret) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func UpdatecredentialsUserId(uid, displayName string, credentials []admin.UserKeySpec) []admin.UserKeySpec { | ||
updatedCredentials := credentials | ||
for i := range credentials { | ||
updatedCredentials[i].UID = uid | ||
updatedCredentials[i].User = displayName | ||
} | ||
|
||
return updatedCredentials | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.