Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit f166c3a

Browse files
committed
Make the default value of the --region flag be more explicit.
1 parent 02e246a commit f166c3a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

cmd/kiam/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (o *serverOptions) bind(parser parser) {
5757
parser.Flag("session-duration", "Requested session duration for STS Tokens.").Default("15m").DurationVar(&o.SessionDuration)
5858
parser.Flag("session-refresh", "How soon STS Tokens should be refreshed before their expiration.").Default("5m").DurationVar(&o.SessionRefresh)
5959
parser.Flag("assume-role-arn", "IAM Role to assume before processing requests").Default("").StringVar(&o.AssumeRoleArn)
60-
parser.Flag("region", "AWS Region to use for STS calls").Default("").StringVar(&o.Region)
60+
parser.Flag("region", "AWS Region to use for STS calls.").Default(sts.GlobalEndpoint).StringVar(&o.Region)
6161
}
6262

6363
func (opts *serverCommand) Run() {

pkg/aws/sts/gateway.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"github.com/uswitch/kiam/pkg/statsd"
2929
)
3030

31+
const GlobalEndpoint = "global-endpoint"
32+
3133
type STSGateway interface {
3234
Issue(ctx context.Context, role, session string, expiry time.Duration) (*Credentials, error)
3335
}
@@ -42,7 +44,7 @@ func DefaultGateway(assumeRoleArn, region string) *DefaultSTSGateway {
4244
config.WithCredentials(stscreds.NewCredentials(session.Must(session.NewSession()), assumeRoleArn))
4345
}
4446

45-
if region != "" {
47+
if region != "" && region != GlobalEndpoint {
4648
config.WithRegion(region).WithEndpointResolver(endpoints.ResolverFunc(endpointFor))
4749
}
4850

pkg/aws/sts/gateway_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ func TestRegionalGatewayFips(t *testing.T) {
6060
t.Error("Unexpected regional endpoint. Endpoint was: ", config.Endpoint)
6161
}
6262
}
63+
64+
func TestGlobalGatewayFips(t *testing.T) {
65+
gateway := DefaultGateway("", "global-endpoint")
66+
67+
config := gateway.session.ClientConfig(sts.EndpointsID)
68+
69+
if config.SigningRegion != "us-east-1" {
70+
t.Error("Unexpected region. Region was: ", config.SigningRegion)
71+
}
72+
73+
if config.Endpoint != "https://sts.amazonaws.com" {
74+
t.Error("Unexpected regional endpoint. Endpoint was: ", config.Endpoint)
75+
}
76+
}

0 commit comments

Comments
 (0)