-
Notifications
You must be signed in to change notification settings - Fork 4k
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
aws-ecr: RepositoryPolicyText should error if includes Resource #24314
Comments
Thanks for reaching out @ahammond . It would be really helpful if you could share the code for reproducing this error |
Write literally any PolicyStatement that includes the traditional resources: ['*'] And you'll see it. I can provide a snippet if necessary, but this is pretty easy to repro. |
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Repository } from 'aws-cdk-lib/aws-ecr';
import { AnyPrincipal, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { Construct } from 'constructs';
export class EcrStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const r = new Repository(this, 'MyEcrRepo');
r.addToResourcePolicy(new PolicyStatement({
actions: ['ecr:GetDownloadUrlForLayer'],
principals: [new AnyPrincipal()],
// Every other resource policy I've ever written requires a resource.
// They're really only good for limiting access within a resource.
// I understand why they're allowed, but not why they're required.
// Strangely, not only does Cfn for ECR not allow
// us to specify a resource policy for a specific image,
// it will straight up fail if a resource section is present at all.
resources: ['*'], // This will break, so CDK should warn. At least until Cfn (and possibly ECR) is fixed.
}));
}
}
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const app = new App();
new EcrStack(app, 'MyEcrStack', { env: devEnv });
app.synth(); |
I just checked the doc for ECR resource policy and yes 'resource' is not required while in other resource types such as cloudwatch logs resource policy or s3 bucket policy, the Yes I think we should add a check to avoid this error. I am making it as a p2 feature request and any PR submission will be highly appreciated. |
The implementation of |
@TheRealAmazonKendra I agree it shouldn't allow providing a |
You're totally right and we'd certainly accept a PR with that as a stopgap. Since this is a P2, however, we don't have the capacity to make the change. |
Is there any workaround to this? |
What I did was
So... sure. The workaround is finding this issue and knowing to not put a |
ECR does not allow resource to be included in private repository resource policies. CFN largely swallows the error message. Most resources require or at least allow a resource in their policies, so we should at least warn. See issue aws#24314
ECR does not allow resource to be included in private repository resource policies. CFN largely swallows the error message. Most resources require or at least allow a resource in their policies, so we should at least warn. See issue aws#24314
ECR does not allow resource to be included in private repository resource policies. CFN largely swallows the error message. Most resources require or at least allow a resource in their policies, so we should at least warn. See issue aws#24314
ECR does not allow resource to be included in private repository resource policies. CFN largely swallows the error message. Most resources require or at least allow a resource in their policies, so we should at least warn. See issue #24314
Closed by #24401 |
|
Describe the feature
When adding a resource policy to an ECR repo, if your
PolicyStatment
includes aResource
, it will successfully synth, but then fail to deploy.CDK should detect the presence of the
Resource
key and issue an Error.Use Case
I spent an entire day staring at a perfectly legal looking resource policy. Only to find out that my bug was this illegal resource key. Error message from Cfn wasn't very helpful:
Proposed Solution
When calling
myRepo.addToResourcePolicy()
, check the inputPolicyStatement
to confirm it doesn't have aresources:
key.Other Information
No response
Acknowledgements
CDK version used
2.27.0
Environment details (OS name and version, etc.)
MacOS, pretty recent. Node 16
The text was updated successfully, but these errors were encountered: