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

Prevent duplication, and add flag to disable shadowing of IAM Identity Mappings #4963

Merged
merged 8 commits into from
Apr 6, 2022

Conversation

DameonSmith
Copy link
Contributor

@DameonSmith DameonSmith commented Mar 16, 2022

Description

I implemented functionality that will prevent duplication of aws_auth entries. The goal of this was to make the eksctl create iamidentitymapping command more automation friendly. I had been using this command in some IAC code and ended up having a large number of copies of the exact same record.

This involved changes in 2 areas primarily:

  1. The create command itself to exit when a duplicate Identity is found.
  2. Creation of a compare function for Identities.
  • This might be more robust if the Identity groups were sorted before being compared. Wasn't sure if it made sense to implement that way.

I also added a flag to the eksctl create iamidentitymapping called --no-shadow when this flag is set the command will error should there be an Identity using the same ARN already in place. The goal of this change is to be able to provide better guarantees that configurations aren't accidentally changed.

Let me know if there's anything here that doesn't match the projects style or format, or if I'm just contributing to technical debt by working it in the way that I did.

Also as a side note the tests ran extremely slowly on my machine (1-2 second per package), is that expected behavior?

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the userdocs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes
  • (Core team) Added labels for change area (e.g. area/nodegroup) and kind (e.g. kind/improvement)

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@Skarlso
Copy link
Contributor

Skarlso commented Mar 17, 2022

Hi!

Thank you for your contribution! :)

Also as a side note the tests ran extremely slowly on my machine (1-2 second per package), is that expected behavior?

Unit tests? All tests? Hmm, they can be slow, since they set up a lot of mocks and extra things and a fake http router potentially and a kubernetes client... :D A lot of things.

I'll leave review comments in code.

@Skarlso Skarlso added the kind/feature New feature or request label Mar 17, 2022
@Skarlso Skarlso requested a review from a team March 17, 2022 11:27
Copy link
Contributor

@Skarlso Skarlso left a comment

Choose a reason for hiding this comment

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

Add tests and code to check unsorted groups are equal.

Copy link
Contributor

@Skarlso Skarlso left a comment

Choose a reason for hiding this comment

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

LGTM

@Skarlso Skarlso requested a review from a team March 17, 2022 20:26
Copy link
Contributor

@aclevername aclevername left a comment

Choose a reason for hiding this comment

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

excellent tests ✨ lgtm!

@Skarlso Skarlso enabled auto-merge (squash) April 6, 2022 09:29
@Skarlso Skarlso merged commit d847830 into eksctl-io:main Apr 6, 2022
@@ -133,6 +137,15 @@ func doCreateIAMIdentityMapping(cmd *cmdutils.Cmd, options iamIdentityMappingOpt
for _, identity := range identities {
arn := identity.ARN()

if iam.CompareIdentity(id, identity) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @DameonSmith!

This check here, should have been behind the below if, right? :D :D

I think we missed that. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or rather, I think this also needs the && options.NoDuplicateArns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check was to just ignore any duplicated identity entirely. Regardless of whether or not the duplicate arn flags was set.
I was trying to avoid having this kind of pollution:

arn: arn1, namespace: default, groups: [group1, group2]
arn: arn1, namespace: default, groups: [group1, group2]
arn: arn1, namespace: default, groups: [group2, group1]
etc...

The context was specifically using eskctl in pipelines and IaC to create default roles and users for a cluster. The pipeline was run multiple times and would just input the same config over and over again. My assumption was that if a record was in the aws_auth config map it should just be ignored without an error as there's no functional difference.

The NoDuplicateArns flag was meant to prevent silent shadowing of existing roles with different permissions. I wanted to ability to have better visibility on something like the "ReadOnlyUsers" role accidentally got the masters group added to it.

Hopefully that makes sense, and there's not something about my assumptions that were mistaken. Let me know if I need to fix something.

Copy link
Contributor

Choose a reason for hiding this comment

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

But we specifically allow duplicate entries. We even have an integration test for it that was now failing. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I didn't realize that was a feature, Is there a reason to allow duplicates?

Either way I can add that flag as a requirement if that's what you'd like. Should I open another PR or is there some way to open this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah opened one here #5080 :)

SlevinWasAlreadyTaken pushed a commit to SlevinWasAlreadyTaken/eksctl that referenced this pull request Apr 11, 2022
…y Mappings (eksctl-io#4963)

* Adding functionality to compare when iam Identity values are equal.

* Adding check to skip identitcal iam Identities when creating identity mapping.

* Added a the flag '--no-shadow' to throw error when trying to create two auth records with the same Arn

* Updating Identity comparison function to verify that unsorted groups with same elements are identical.

* Fixing formatting recommended in PR.

* Changing name of --no-shadow flag to --no-duplicate-arns

Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@hspencer77 hspencer77 mentioned this pull request Jul 8, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants