Skip to content

Commit

Permalink
Consume AWS session token for Stow (#296)
Browse files Browse the repository at this point in the history
Pass AWS session token from secret or environment variable to Stow configmap.

* Consume AWS session token.
* Update the test.
* Update the go mod files.
  • Loading branch information
Hakan Memisoglu committed Sep 17, 2019
1 parent 1edcd0f commit 0812700
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

replace (
cloud.google.com/go => github.com/GoogleCloudPlatform/google-cloud-go v0.1.1-0.20160913182117-3b1ae45394a2
github.com/graymeta/stow => github.com/kastenhq/stow v0.1.1-kasten
github.com/graymeta/stow => github.com/kastenhq/stow v0.1.2-kasten
github.com/rook/operator-kit => github.com/kastenhq/operator-kit v0.0.0-20180316185208-859e831cc18d
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kastenhq/stow v0.1.1-kasten h1:0IuykRy/KfqUttO2n6w3XTJzyFhSThXeE5UtKvstmYs=
github.com/kastenhq/stow v0.1.1-kasten/go.mod h1:ABI2whmZOX25JbmbVuHRLFuPiGnv5lxXhduCtof7UHk=
github.com/kastenhq/stow v0.1.2-kasten h1:3msAbg6woEPWzYaBPmsOY4a0V55QosWD86XMOE+gDbM=
github.com/kastenhq/stow v0.1.2-kasten/go.mod h1:ABI2whmZOX25JbmbVuHRLFuPiGnv5lxXhduCtof7UHk=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down
5 changes: 4 additions & 1 deletion pkg/objectstore/objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ func Supported(t ProviderType) bool {
}

func s3Config(config ProviderConfig, secret *Secret, region string) (stowKind string, stowConfig stow.Config, err error) {
var awsAccessKeyID, awsSecretAccessKey string
var awsAccessKeyID, awsSecretAccessKey, awsSessionToken string
if secret != nil {
if secret.Type != SecretTypeAwsAccessKey {
return "", nil, errors.Errorf("invalid secret type %s", secret.Type)
}
awsAccessKeyID = secret.Aws.AccessKeyID
awsSecretAccessKey = secret.Aws.SecretAccessKey
awsSessionToken = secret.Aws.SessionToken
} else {
var ok bool
if awsAccessKeyID, ok = os.LookupEnv("AWS_ACCESS_KEY_ID"); !ok {
Expand All @@ -127,10 +128,12 @@ func s3Config(config ProviderConfig, secret *Secret, region string) (stowKind st
if awsSecretAccessKey, ok = os.LookupEnv("AWS_SECRET_ACCESS_KEY"); !ok {
return "", nil, errors.New("AWS_SECRET_ACCESS_KEY environment not set")
}
awsSessionToken = os.Getenv("AWS_SESSION_TOKEN")
}
cm := stow.ConfigMap{
stows3.ConfigAccessKeyID: awsAccessKeyID,
stows3.ConfigSecretKey: awsSecretAccessKey,
stows3.ConfigToken: awsSessionToken,
}
if region != "" {
cm[stows3.ConfigRegion] = region
Expand Down
1 change: 1 addition & 0 deletions pkg/objectstore/objectstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func getSecret(c *C, osType ProviderType) *Secret {
secret.Aws = &SecretAws{
AccessKeyID: os.Getenv("AWS_ACCESS_KEY_ID"),
SecretAccessKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
SessionToken: os.Getenv("AWS_SESSION_TOKEN"),
}
c.Check(secret.Aws.AccessKeyID, Not(Equals), "")
c.Check(secret.Aws.SecretAccessKey, Not(Equals), "")
Expand Down

0 comments on commit 0812700

Please sign in to comment.