2

So, I've been trying to write an IAM Role for CodeBuild and CodePipeline in AWS CDK.

I need it to be public so I can reference them in their own declaration.

I've also tried to generate a simple CloudFormation template out of my code and had no success in uploading it. Had the same error.

AssumeRolepolicy contained an invalid principal: "STAR":"*"

const codeBuildRoleName = `${parameters.environment}CodeBuildRole`;
const codeBuildRole = new Role(this, codeBuildRoleName, {
  assumedBy: new AnyPrincipal(),
  roleName: codeBuildRoleName,
});

const codeBuildRolePolicy = `${parameters.environment}CodeBuildRolePolicy`;
codeBuildRole.attachInlinePolicy(new Policy(this, codeBuildRolePolicy , {
  statements: [
    new PolicyStatement({
      effect: Effect.ALLOW,
      resources: ['*'],
      actions: ['iam:PassRole']
    }),
    new PolicyStatement({
      effect: Effect.ALLOW,
      resources: ['*'],
      actions: ['codebuild:*']
    }),
    new PolicyStatement({
      effect: Effect.ALLOW,
      resources: ['*'],
      actions: [
        'logs:FilterLogEvents',
        'logs:GetLogEvents',
        'logs:CreateLogStream',
        'logs:CreateLogGroup',
        'logs:PutLogEvents',
      ]
    }),
    new PolicyStatement({
      effect: Effect.ALLOW,
      resources: ['*'],
      actions: [
        'apigateway:PATCH',
        'apigateway:GET',
        'apigateway:POST',
        'iam:*',
        'cloudformation:*',
        's3:*',
        'cognito-idp:*',
      ]
    })
  ]
}));

This is the code, and I've been getting this.

AssumeRolepolicy contained an invalid principal: "STAR":"*"

And I can't deploy anything.

fedonev
  • 20,327
  • 2
  • 25
  • 34

1 Answers1

-1

When you create the Role, try passing a ServicePrincipal instead of AnyPrincipal like so:

const codeBuildRole = new Role(this, codeBuildRoleName, {
  assumedBy: new ServicePrincipal(service: "codebuild.amazonaws.com"),
  roleName: codeBuildRoleName,
});

I'm not in a position of testing this right now, but I think this should fix the issue.

Laurent Jalbert Simard
  • 5,949
  • 1
  • 28
  • 36