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

iam.ServicePrincipal injects region into Principal string #2622

Closed
KingOfPoptart opened this issue May 23, 2019 · 7 comments
Closed

iam.ServicePrincipal injects region into Principal string #2622

KingOfPoptart opened this issue May 23, 2019 · 7 comments
Labels
bug This issue is a bug.

Comments

@KingOfPoptart
Copy link
Contributor

KingOfPoptart commented May 23, 2019

Describe the bug
When using new iam.ServicePrincipal() - the CloudFormation that is output injects the region into the Principal and there doesn't seem to be an option to disable this behavior.

To Reproduce

# Create a service principal, point it to "codedeploy.amazonaws.com"
new iam.Role(this, 'IamRoleWithServicePrincipal', {
    assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com'),
    managedPolicyArns: ['arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole',
        'arn:aws:iam::aws:policy/AWSCodeDeployRoleForECS'],
    roleName: 'myrole'
});
# This is what gets output from cdk synth - Note that `Ref: AWS::Region` 
# gets included as part of the Service Principal
Resources:
  myroleD153DA9E:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                Fn::Join:
                  - ""
                  - - codedeploy.
                    - Ref: AWS::Region
                    - "."
                    - Ref: AWS::URLSuffix
        Version: "2012-10-17"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole
        - arn:aws:iam::aws:policy/AWSCodeDeployRoleForECS
      RoleName: myrole

Expected behavior
The default should be to not inject the region into the principal in the properties passed into new iam.ServicePrincipal(). An option to add that in might be useful for some cases, but I don't think it should be the default.

Version:

  • OS: OSX
  • Programming Language: Typescript
  • CDK Version: 0.31.0
@KingOfPoptart KingOfPoptart added the bug This issue is a bug. label May 23, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 10, 2019

What region or what workflow is this breaking for you?

@KingOfPoptart
Copy link
Contributor Author

This was breaking setting up codedeploy in the console - i couldn't set the role created in CDK as the instance profile role in the console since it didn't expect it to be regionalized

@RomainMuller
Copy link
Contributor

But are you able to use the role properly, say when you're deploying everything via CloudFormation?

I'm wondering if this is a console issue instead of a CDK issue :)

@KingOfPoptart
Copy link
Contributor Author

KingOfPoptart commented Jun 20, 2019 via email

@RomainMuller
Copy link
Contributor

@KingOfPoptart - I'm not sure I agree here. One of our tenets is to issue least-privilege permissions only, and tightening the role down to the region where it's supposed to operate seems to be the right thing to do here.

If you have a concrete use-case where you need to grant the "region-global" principal permissions here... Then that'd be a feature request, not a bug.

@KingOfPoptart
Copy link
Contributor Author

Sure - I'm happy to switch this to a feature request instead. By default, I agree, it should be locked down. But having the option to open it up is also valid.

@KingOfPoptart
Copy link
Contributor Author

KingOfPoptart commented Jun 21, 2019

Opened #2999

Going to close this issue.

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

No branches or pull requests

3 participants