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

fix(iam): Error for addToPolicy and addToPrincipalPolicy in User.fromUserName corrected... #11046

Closed
wants to merge 16 commits into from

Conversation

ariain
Copy link

@ariain ariain commented Oct 22, 2020

iam.User.fromUserName addToPolicy and addToPrincipalPolicy fixed

Error is corrected to Cannot add policy to imported User for both functions...
fixes #10913


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 22, 2020

@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@ariain ariain changed the title fix(iam): error for addToPolicy and addToPrincipalPolicy in iam.User.fromUserName corrected... fix(iam): Error for addToPolicy and addToPrincipalPolicy in iam.User.fromUserName corrected... Oct 22, 2020
@ariain ariain changed the title fix(iam): Error for addToPolicy and addToPrincipalPolicy in iam.User.fromUserName corrected... fix(aws-iam): Error for addToPolicy and addToPrincipalPolicy in iam.User.fromUserName corrected... Oct 22, 2020
@ariain ariain changed the title fix(aws-iam): Error for addToPolicy and addToPrincipalPolicy in iam.User.fromUserName corrected... fix(iam): Error for addToPolicy and addToPrincipalPolicy in User.fromUserName corrected... Oct 22, 2020
@ariain
Copy link
Author

ariain commented Oct 22, 2020

@wtho can you help me with these errors??

@wtho
Copy link
Contributor

wtho commented Oct 23, 2020

Just go through the list of checks at the end of this PR

  • PR Linter / validate-pr -> Click on Details and read the error
  • AWS CodeBuild -> Click on the AWS CodeBuild Report that was posted as a comment, open the Build Logs and search for the block of exclamation marks (!!!!!!!!!), some lines above the block you can find the error message. Probably you changed some code and did not update the tests accordingly. To run the tests I would recommend opening the project in GitPod, but I had some issues pushing changes from GitPod back to the branch, you might have to do it from git installed on your machine.
  • Semantic Pull Request -> Read the message: PR has only one non-merge commit and it's not semantic and learn more about semantic commit messages, as described in the contribution guide in this repository, and compare it to the commit message you pushed

@ariain
Copy link
Author

ariain commented Oct 23, 2020

@wtho who will review and merge these changes now??

@wtho
Copy link
Contributor

wtho commented Oct 23, 2020

Haha, just wait till someone from aws assignes a reviewer, it usually takes 2-4 days.

@ariain
Copy link
Author

ariain commented Oct 23, 2020

Okay, thanks for guiding me @wtho ...

@ariain
Copy link
Author

ariain commented Oct 29, 2020

@rix0rrr please review these changes...

rix0rrr
rix0rrr previously requested changes Nov 9, 2020
packages/@aws-cdk/aws-iam/lib/user.ts Show resolved Hide resolved
this.defaultPolicy.addStatements(statement);
return { statementAdded: true, policyDependable: this.defaultPolicy };
public addToPrincipalPolicy(_statement: PolicyStatement): AddToPrincipalPolicyResult {
throw new Error('Cannot add imported User to principal policy');
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message is the wrong way around.

Cannot add policy to imported User principal makes more sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sort of fine having this throw an error, but as discussed in #10913 this could just be made to work.

If you add an AWS::IAM::Policy and you give it the right UserName, it becomes possible to add an identity policy to an existing identity, as far as I can tell.

Why don't we just do that?

Maybe the correct fix is to figure out where the exception that was mentioned in #10913 is thrown, and make sure that error isn't thrown anymore. Because the content of addToPrincipalPolicy mostly seems correct, except it probably throws when attachToUser is called... (?)

Copy link
Author

Choose a reason for hiding this comment

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

The error message will be common with addToPolicy function so maybe we can throw this message Cannot add policy to imported User.
If we don't want to throw an error then there are several problems here if we try to correct the functionality because its not like other functions are working. The attachToUser will call to attachInlinePolicy which will throw an error, I can try to fix that function...

Copy link
Author

Choose a reason for hiding this comment

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

So, should I check for the correct functionality or throw an error instead??

@mergify mergify bot dismissed rix0rrr’s stale review November 11, 2020 15:19

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 5364cf8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 16, 2020

@ariain, see #11493.

I ended up doing the same implementation of attachInlinePolicy for imported Users as was in User itself.

@mergify mergify bot closed this in #11493 Nov 18, 2020
mergify bot pushed a commit that referenced this pull request Nov 18, 2020
It was not possible to attach policies to imported `User` objects.

This can be made to work though, as the underlying CloudFormation
resource allows doing so.

Make this work in the class library.

Fixes #10913, closes #11046, closes #10527.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

[aws-iam] User.fromUserName incorrectly implemented addToPolicy
4 participants