Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-14998: Only use RoleARN for Route53 API #951

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pkg/dns/aws/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ type Config struct {
// that is used by SDK to configure the credentials.
SharedCredentialFile string

// RoleARN is an optional ARN to use for the AWS client session.
// RoleARN is an optional ARN to use for the AWS client session that is
// intended to only provide access to another account's Route 53 service.
RoleARN string

// Region is the AWS region ELBs are created in.
Expand Down Expand Up @@ -144,9 +145,6 @@ func NewProvider(config Config, operatorReleaseVersion string) (*Provider, error
Name: "openshift.io/ingress-operator",
Fn: request.MakeAddToUserAgentHandler("openshift.io ingress-operator", operatorReleaseVersion),
})
if config.RoleARN != "" {
sess.Config.WithCredentials(stscreds.NewCredentials(sess, config.RoleARN))
}

if len(region) == 0 {
if sess.Config.Region != nil {
Expand All @@ -157,6 +155,14 @@ func NewProvider(config Config, operatorReleaseVersion string) (*Provider, error
}
}

// When RoleARN is provided, make a copy of the Route 53 session and configure it to use RoleARN.
// RoleARN is intended to only provide access to another account's Route 53 service, not for ELBs.
sessRoute53 := sess
if config.RoleARN != "" {
sessRoute53 = sess.Copy()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Miciah - I made a silly mistake that broke everything. I had sessRoute53 := sess.Copy() instead of sessRoute53 = sess.Copy().

The variable was shadowed in the scope of the if statement, and didn't modify the sessRoute53 in the scope we needed. Everything works as expected now.

sessRoute53.Config.WithCredentials(stscreds.NewCredentials(sessRoute53, config.RoleARN))
}

r53Config := aws.NewConfig()
// elb requires no special region treatment.
elbConfig := aws.NewConfig().WithRegion(region)
Expand Down Expand Up @@ -238,7 +244,7 @@ func NewProvider(config Config, operatorReleaseVersion string) (*Provider, error
// TODO: Add custom endpoint support for elbv2. See the following for details:
// https://docs.aws.amazon.com/general/latest/gr/elb.html
elbv2: elbv2.New(sess, aws.NewConfig().WithRegion(region)),
route53: route53.New(sess, r53Config),
route53: route53.New(sessRoute53, r53Config),
tags: tags,
config: config,
idsToTags: map[string]map[string]string{},
Expand Down