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

Compose full IAM ARN from role name or alias #169

Merged
merged 7 commits into from
Jun 21, 2023
Merged

Conversation

zewolfe
Copy link
Contributor

@zewolfe zewolfe commented Feb 1, 2023

Issue #, if available:
Reference: #78

Description of changes:
This PR introduces the ability to create a fully formed IAM ARN if just the role alias/name is specified. For example an input of s3-reader will result in arn:aws:iam::111122223333:role/s3-reader. The account ID is fetched from ec2 Metadata

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@njuettner
Copy link
Contributor

@dims @nckturner @jaypipes @micahhausler hey 👋🏻, could someone take a look at this PR? We'd like to contribute, we believe this might be helpful for others 🙂.

The idea is to set only the role name in case you're not assuming a cross-account role, but it doesn't do harm if you would still leave the account id in the annotation.

PTAL 🙇🏻

@nckturner
Copy link
Contributor

nckturner commented May 9, 2023

Can you squash the commits into reviewable chunks with vendor separate please? @zewolfe


accountId = identity.AccountID
if strings.Contains(identity.Region, "cn-") {
partition = "aws-cn"
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to account for other paritions (aws-us-gov, aws-iso and aws-iso-b)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks will update them, we were not aware of all the partitions 😅

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I added the other partitions.

main.go Outdated
metadataClient := ec2metadata.New(sess)
identity, err := metadataClient.GetInstanceIdentityDocument()
if err != nil {
klog.Fatalf("Error getting instance identity document: %v", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this introduce a new required dependency on EC2 metadata where there wasn't one before?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct, this is a new dependency. We need to call instance identity document in order to get the account ID

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we only fail on this dependency if the feature is enabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok should be done, I just wrapped a if condition around it 🙂

@njuettner
Copy link
Contributor

Thanks again for your input, I hope I addressed your comments. PTAL again ❤️

@njuettner
Copy link
Contributor

@nckturner @dims could you take a look again please?

@njuettner
Copy link
Contributor

@nckturner @dims I know you're super busy, I'd would really like to see this move. Is there any chance you have a couple of minutes to have a look again or you might point me to another person who can take a look, I don't want to waste your time but I'm a bit clueless here how we can move forward.

Thank you again ❤️

@dims
Copy link
Member

dims commented Jun 1, 2023

cc @nnmin-aws

@nnmin-aws
Copy link
Contributor

thanks @dims! I will review it today.

@nnmin-aws
Copy link
Contributor

/lgtm

main.go Outdated
*tokenExpiration,
saInformer,
cmInformer,
identity,
Copy link
Contributor

@nckturner nckturner Jun 1, 2023

Choose a reason for hiding this comment

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

Passing the entire instance identity document to the cache constructor seems excessive and leaky, can we instead create a struct which includes all the data required for this feature, called something like ComposeRoleArn, which contains Enabled, Region, Partition and AccountId?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I changed it slightly, I hope this is better now.

@nckturner
Copy link
Contributor

@njuettner Thanks for the update! Sorry I've been unresponsive, I have one more piece of feedback for you to address.

@njuettner
Copy link
Contributor

@nckturner Addressed the feedback, thank you 👍🏻

@njuettner
Copy link
Contributor

@nckturner sorry for pinging you again, can you take a look again please?

@nckturner
Copy link
Contributor

@njuettner thanks for doing that, taking a look.

Copy link
Contributor

@nckturner nckturner left a comment

Choose a reason for hiding this comment

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

Looks good! Just two minor suggestions, otherwise lgtm.

main.go Outdated Show resolved Hide resolved
pkg/cache/cache.go Show resolved Hide resolved
@njuettner
Copy link
Contributor

@nckturner Awesome, thank you 👍🏻. I committed your two suggestions.

@njuettner
Copy link
Contributor

@nckturner if you have time again to have a final look that would be awesome 🙂

@njuettner
Copy link
Contributor

@nckturner any news 🙏🏻?

@njuettner
Copy link
Contributor

@nckturner do you mind having a look? I think we can merge this PR 🙂

@nnmin-aws
Copy link
Contributor

@njuettner apology for the delay as Nick is on leave. I am checking it.

@nnmin-aws
Copy link
Contributor

/lgtm

@nnmin-aws
Copy link
Contributor

@dims Could you please kindly help merge this PR as Nick is on leave? thank you!

@dims
Copy link
Member

dims commented Jun 20, 2023

@nnmin-aws running the tests one last time

@dims
Copy link
Member

dims commented Jun 20, 2023

@zewolfe can you please rebase and fix the broken test?

zewolfe and others added 6 commits June 21, 2023 08:32
@njuettner
Copy link
Contributor

@dims please take a look again 👍🏻

@dims dims merged commit 9f7a868 into aws:master Jun 21, 2023
1 check passed
@dims
Copy link
Member

dims commented Jun 21, 2023

thanks @njuettner

@njuettner
Copy link
Contributor

thank you @dims and @nckturner ❤️

@dims
Copy link
Member

dims commented Jun 21, 2023

and @nnmin-aws :)

@calvix
Copy link

calvix commented Aug 15, 2023

Hello @nnmin-aws and @dims, would it be possible to create a release with this change?

@nnmin-aws
Copy link
Contributor

apology for your inconvenience. we will work on this and let you know when new release is out

@nnmin-aws
Copy link
Contributor

@calvix the new release v0.5.0 is out. thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants