Skip to content

Commit

Permalink
Use credentials file passed through config
Browse files Browse the repository at this point in the history
Add a new supported key to the config which allows the path to a
credentials file to be passed through to the ObjectStore and
VolumeSnapshotter plugins. If that key is set in the config, use that
file as the credentials file for the AWS client.

This can be tested by adding a new key to the `cloud-credentials` secret
and adding the key value pair `credentialsFile=/credentials/<key_name>`.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
  • Loading branch information
zubron committed Jan 26, 2021
1 parent c46c38d commit 33a2c0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions velero-plugin-for-aws/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
s3ForcePathStyleKey = "s3ForcePathStyle"
bucketKey = "bucket"
signatureVersionKey = "signatureVersion"
credentialsFileKey = "credentialsFile"
credentialProfileKey = "profile"
serverSideEncryptionKey = "serverSideEncryption"
insecureSkipTLSVerifyKey = "insecureSkipTLSVerify"
Expand Down Expand Up @@ -90,6 +91,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
kmsKeyIDKey,
s3ForcePathStyleKey,
signatureVersionKey,
credentialsFileKey,
credentialProfileKey,
serverSideEncryptionKey,
insecureSkipTLSVerifyKey,
Expand All @@ -105,6 +107,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
s3ForcePathStyleVal = config[s3ForcePathStyleKey]
signatureVersion = config[signatureVersionKey]
credentialProfile = config[credentialProfileKey]
credentialsFile = config[credentialsFileKey]
serverSideEncryption = config[serverSideEncryptionKey]
insecureSkipTLSVerifyVal = config[insecureSkipTLSVerifyKey]

Expand Down Expand Up @@ -170,6 +173,9 @@ func (o *ObjectStore) Init(config map[string]string) error {
if len(caCert) > 0 {
sessionOptions.CustomCABundle = strings.NewReader(caCert)
}
if credentialsFile != "" {
sessionOptions.SharedConfigFiles = []string{credentialsFile}
}
serverSession, err := getSession(sessionOptions)
if err != nil {
return err
Expand All @@ -196,6 +202,9 @@ func (o *ObjectStore) Init(config map[string]string) error {
if len(caCert) > 0 {
sessionOptions.CustomCABundle = strings.NewReader(caCert)
}
if credentialsFile != "" {
sessionOptions.SharedConfigFiles = []string{credentialsFile}
}
publicSession, err := getSession(sessionOptions)
if err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion velero-plugin-for-aws/volume_snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ func newVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
}

func (b *VolumeSnapshotter) Init(config map[string]string) error {
if err := veleroplugin.ValidateVolumeSnapshotterConfigKeys(config, regionKey, credentialProfileKey); err != nil {
if err := veleroplugin.ValidateVolumeSnapshotterConfigKeys(config, regionKey, credentialsFileKey, credentialProfileKey); err != nil {
return err
}

region := config[regionKey]
credentialProfile := config[credentialProfileKey]
credentialsFile := config[credentialsFileKey]
if region == "" {
return errors.Errorf("missing %s in aws configuration", regionKey)
}

awsConfig := aws.NewConfig().WithRegion(region)

sessionOptions := session.Options{Config: *awsConfig, Profile: credentialProfile}
if credentialsFile != "" {
sessionOptions.SharedConfigFiles = []string{credentialsFile}
}
sess, err := getSession(sessionOptions)
if err != nil {
return err
Expand Down

0 comments on commit 33a2c0b

Please sign in to comment.