diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.assets.json new file mode 100644 index 0000000000000..654cf0e4402cf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.assets.json @@ -0,0 +1,20 @@ +{ + "version": "48.0.0", + "files": { + "3244467e225c11bce46a22c4242fb41c63757d5c330e437fffb48613c4492d54": { + "displayName": "aws-ecr-tag-mutability-exclusion-stack Template", + "source": { + "path": "aws-ecr-tag-mutability-exclusion-stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region-c4d8a01c": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "3244467e225c11bce46a22c4242fb41c63757d5c330e437fffb48613c4492d54.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.template.json new file mode 100644 index 0000000000000..3c4fddb624615 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/aws-ecr-tag-mutability-exclusion-stack.template.json @@ -0,0 +1,76 @@ +{ + "Resources": { + "ImmutableRepoWithExclusions905B5191": { + "Type": "AWS::ECR::Repository", + "Properties": { + "EmptyOnDelete": true, + "ImageTagMutability": "IMMUTABLE_WITH_EXCLUSION", + "ImageTagMutabilityExclusionFilters": [ + { + "ImageTagMutabilityExclusionFilterType": "WILDCARD", + "ImageTagMutabilityExclusionFilterValue": "dev-*" + }, + { + "ImageTagMutabilityExclusionFilterType": "WILDCARD", + "ImageTagMutabilityExclusionFilterValue": "test-*" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "MutableRepoWithExclusions16D45AB8": { + "Type": "AWS::ECR::Repository", + "Properties": { + "EmptyOnDelete": true, + "ImageTagMutability": "MUTABLE_WITH_EXCLUSION", + "ImageTagMutabilityExclusionFilters": [ + { + "ImageTagMutabilityExclusionFilterType": "WILDCARD", + "ImageTagMutabilityExclusionFilterValue": "prod-*" + }, + { + "ImageTagMutabilityExclusionFilterType": "WILDCARD", + "ImageTagMutabilityExclusionFilterValue": "release-v*" + } + ] + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdk.out new file mode 100644 index 0000000000000..523a9aac37cbf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"48.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets.json new file mode 100644 index 0000000000000..e56f81f28e008 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets.json @@ -0,0 +1,20 @@ +{ + "version": "48.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "displayName": "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1 Template", + "source": { + "path": "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region-d8d86b35": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/integ.json new file mode 100644 index 0000000000000..b0a5b03b2c5ac --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/integ.json @@ -0,0 +1,13 @@ +{ + "version": "48.0.0", + "testCases": { + "cdk-ecr-tag-mutability-exclusion-test/DefaultTest": { + "stacks": [ + "aws-ecr-tag-mutability-exclusion-stack" + ], + "assertionStack": "cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert", + "assertionStackName": "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1" + } + }, + "minimumCliVersion": "2.1027.0" +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/manifest.json new file mode 100644 index 0000000000000..572fa4baf161a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/manifest.json @@ -0,0 +1,621 @@ +{ + "version": "48.0.0", + "artifacts": { + "aws-ecr-tag-mutability-exclusion-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-ecr-tag-mutability-exclusion-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-ecr-tag-mutability-exclusion-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-ecr-tag-mutability-exclusion-stack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3244467e225c11bce46a22c4242fb41c63757d5c330e437fffb48613c4492d54.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-ecr-tag-mutability-exclusion-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-ecr-tag-mutability-exclusion-stack.assets" + ], + "metadata": { + "/aws-ecr-tag-mutability-exclusion-stack/ImmutableRepoWithExclusions": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/aws-ecr-tag-mutability-exclusion-stack/ImmutableRepoWithExclusions/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ImmutableRepoWithExclusions905B5191" + } + ], + "/aws-ecr-tag-mutability-exclusion-stack/MutableRepoWithExclusions": [ + { + "type": "aws:cdk:analytics:construct", + "data": "*" + } + ], + "/aws-ecr-tag-mutability-exclusion-stack/MutableRepoWithExclusions/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MutableRepoWithExclusions16D45AB8" + } + ], + "/aws-ecr-tag-mutability-exclusion-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-ecr-tag-mutability-exclusion-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-ecr-tag-mutability-exclusion-stack" + }, + "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "cdkecrtagmutabilityexclusiontestDefaultTestDeployAssertD78326B1.assets" + ], + "metadata": { + "/cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "aws-cdk-lib/feature-flag-report": { + "type": "cdk:feature-flag-report", + "properties": { + "module": "aws-cdk-lib", + "flags": { + "@aws-cdk/aws-signer:signingProfileNamePassedToCfn": { + "recommendedValue": true, + "explanation": "Pass signingProfileName to CfnSigningProfile" + }, + "@aws-cdk/core:newStyleStackSynthesis": { + "recommendedValue": true, + "explanation": "Switch to new stack synthesis method which enables CI/CD", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:stackRelativeExports": { + "recommendedValue": true, + "explanation": "Name exports based on the construct paths relative to the stack, rather than the global construct path", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": { + "recommendedValue": true, + "explanation": "Disable implicit openListener when custom security groups are provided" + }, + "@aws-cdk/aws-rds:lowercaseDbIdentifier": { + "recommendedValue": true, + "explanation": "Force lowercasing of RDS Cluster names in CDK", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": { + "recommendedValue": true, + "explanation": "Allow adding/removing multiple UsagePlanKeys independently", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeVersionProps": { + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-lambda:recognizeLayerVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to opt in to the updated logical id calculation for Lambda Version created using the `fn.currentVersion`." + }, + "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": { + "recommendedValue": true, + "explanation": "Enable this feature flag to have cloudfront distributions use the security policy TLSv1.2_2021 by default.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:checkSecretUsage": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this flag to make it impossible to accidentally use SecretValues in unsafe locations" + }, + "@aws-cdk/core:target-partitions": { + "recommendedValue": [ + "aws", + "aws-cn" + ], + "explanation": "What regions to include in lookup tables of environment agnostic stacks" + }, + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": { + "userValue": true, + "recommendedValue": true, + "explanation": "ECS extensions will automatically add an `awslogs` driver if no logging is specified" + }, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to have Launch Templates generated by the `InstanceRequireImdsv2Aspect` use unique names." + }, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": { + "userValue": true, + "recommendedValue": true, + "explanation": "ARN format used by ECS. In the new ARN format, the cluster name is part of the resource ID." + }, + "@aws-cdk/aws-iam:minimizePolicies": { + "userValue": true, + "recommendedValue": true, + "explanation": "Minimize IAM policies by combining Statements" + }, + "@aws-cdk/core:validateSnapshotRemovalPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Error on snapshot removal policies on resources that do not support it." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate key aliases that include the stack name" + }, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature flag to create an S3 bucket policy by default in cases where an AWS service would automatically create the Policy if one does not exist." + }, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict KMS key policy for encrypted Queues a bit more" + }, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make default CloudWatch Role behavior safe for multiple API Gateways in one environment" + }, + "@aws-cdk/core:enablePartitionLiterals": { + "userValue": true, + "recommendedValue": true, + "explanation": "Make ARNs concrete if AWS partition is known" + }, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": { + "userValue": true, + "recommendedValue": true, + "explanation": "Event Rules may only push to encrypted SQS queues in the same account" + }, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": { + "userValue": true, + "recommendedValue": true, + "explanation": "Avoid setting the \"ECS\" deployment controller when adding a circuit breaker" + }, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable this feature to by default create default policy names for imported roles that depend on the stack the role is in." + }, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use S3 Bucket Policy instead of ACLs for Server Access Logging" + }, + "@aws-cdk/aws-route53-patters:useCertificate": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use the official `Certificate` resource instead of `DnsValidatedCertificate`" + }, + "@aws-cdk/customresources:installLatestAwsSdkDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "Whether to install the latest SDK by default in AwsCustomResource" + }, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": { + "userValue": true, + "recommendedValue": true, + "explanation": "Use unique resource name for Database Proxy" + }, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Remove CloudWatch alarms from deployment group" + }, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include authorizer configuration in the calculation of the API deployment logical ID." + }, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": { + "userValue": true, + "recommendedValue": true, + "explanation": "Define user data for a launch template by default when a machine image is provided." + }, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": { + "userValue": true, + "recommendedValue": true, + "explanation": "SecretTargetAttachments uses the ResourcePolicy of the attached Secret." + }, + "@aws-cdk/aws-redshift:columnId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Whether to use an ID to track Redshift column changes" + }, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable AmazonEMRServicePolicy_v2 managed policies" + }, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "Restrict access to the VPC default security group" + }, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a unique id for each RequestValidator added to a method" + }, + "@aws-cdk/aws-kms:aliasNameRef": { + "userValue": true, + "recommendedValue": true, + "explanation": "KMS Alias name and keyArn will have implicit reference to KMS Key" + }, + "@aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enable grant methods on Aliases imported by name to use kms:ResourceAliases condition" + }, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": { + "userValue": true, + "recommendedValue": true, + "explanation": "Generate a launch template when creating an AutoScalingGroup" + }, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": { + "userValue": true, + "recommendedValue": true, + "explanation": "Include the stack prefix in the stack name generation process" + }, + "@aws-cdk/aws-efs:denyAnonymousAccess": { + "userValue": true, + "recommendedValue": true, + "explanation": "EFS denies anonymous clients accesses" + }, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables support for Multi-AZ with Standby deployment for opensearch domains" + }, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables aws-lambda-nodejs.Function to use the latest available NodeJs runtime as the default" + }, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, mount targets will have a stable logicalId that is linked to the associated subnet." + }, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change." + }, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, will always use the arn for identifiers for CfnSourceApiAssociation in the GraphqlApi construct rather than id." + }, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials." + }, + "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the CodeCommit source action is using the default branch name 'main'." + }, + "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID." + }, + "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default value for crossAccountKeys to false." + }, + "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "Enables Pipeline to set the default pipeline type to V2." + }, + "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, IAM Policy created from KMS key grant will reduce the resource scope to this key only." + }, + "@aws-cdk/pipelines:reduceAssetRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from PipelineAssetsFileRole trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-eks:nodegroupNameAttribute": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, nodegroupName attribute of the provisioned EKS NodeGroup will not have the cluster name prefix." + }, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default volume type of the EBS volume will be GP3" + }, + "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, remove default deployment alarm settings" + }, + "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, the custom resource used for `AwsCustomResource` will configure the `logApiResponseData` property as true by default" + }, + "@aws-cdk/aws-s3:keepNotificationInImportedBucket": { + "userValue": false, + "recommendedValue": false, + "explanation": "When enabled, Adding notifications to a bucket in the current stack will not remove notification from imported stack." + }, + "@aws-cdk/aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask": { + "recommendedValue": true, + "explanation": "When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/core:explicitStackTags": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, stack tags need to be assigned explicitly on a Stack." + }, + "@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": { + "userValue": false, + "recommendedValue": false, + "explanation": "When set to true along with canContainersAccessInstanceRole=false in ECS cluster, new updated commands will be added to UserData to block container accessing IMDS. **Applicable to Linux only. IMPORTANT: See [details.](#aws-cdkaws-ecsenableImdsBlockingDeprecatedFeature)**" + }, + "@aws-cdk/aws-ecs:disableEcsImdsBlocking": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, CDK synth will throw exception if canContainersAccessInstanceRole is false. **IMPORTANT: See [details.](#aws-cdkaws-ecsdisableEcsImdsBlocking)**" + }, + "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, we will only grant the necessary permissions when users specify cloudwatch log group through logConfiguration" + }, + "@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled will allow you to specify a resource policy per replica, and not copy the source table policy to all replicas" + }, + "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, initOptions.timeout and resourceSignalTimeout values will be summed together." + }, + "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, a Lambda authorizer Permission created when using GraphqlApi will be properly scoped with a SourceArn." + }, + "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the value of property `instanceResourceId` in construct `DatabaseInstanceReadReplica` will be set to the correct value which is `DbiResourceId` instead of currently `DbInstanceArn`" + }, + "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CFN templates added with `cfn-include` will error if the template contains Resource Update or Create policies with CFN Intrinsics that include non-primitive values." + }, + "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, both `@aws-sdk` and `@smithy` packages will be excluded from the Lambda Node.js 18.x runtime to prevent version mismatches in bundled applications." + }, + "@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resource of IAM Run Ecs policy generated by SFN EcsRunTask will reference the definition, instead of constructing ARN." + }, + "@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the BastionHost construct will use the latest Amazon Linux 2023 AMI, instead of Amazon Linux 2." + }, + "@aws-cdk/core:aspectStabilization": { + "recommendedValue": true, + "explanation": "When enabled, a stabilization loop will be run when invoking Aspects during synthesis.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, use a new method for DNS Name of user pool domain target without creating a custom resource." + }, + "@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default security group ingress rules will allow IPv6 ingress from anywhere" + }, + "@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the default behaviour of OIDC provider will reject unauthorized connections" + }, + "@aws-cdk/core:enableAdditionalMetadataCollection": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will expand the scope of usage data collected to better inform CDK development and improve communication for security concerns and emerging issues." + }, + "@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy": { + "userValue": false, + "recommendedValue": false, + "explanation": "[Deprecated] When enabled, Lambda will create new inline policies with AddToRolePolicy instead of adding to the Default Policy Statement" + }, + "@aws-cdk/aws-s3:setUniqueReplicationRoleName": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK will automatically generate a unique role name that is used for s3 object replication." + }, + "@aws-cdk/pipelines:reduceStageRoleTrustScope": { + "recommendedValue": true, + "explanation": "Remove the root account principal from Stage addActions trust policy", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-events:requireEventBusPolicySid": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, grantPutEventsTo() will use resource policies with Statement IDs for service principals." + }, + "@aws-cdk/core:aspectPrioritiesMutating": { + "userValue": true, + "recommendedValue": true, + "explanation": "When set to true, Aspects added by the construct library on your behalf will be given a priority of MUTATING." + }, + "@aws-cdk/aws-dynamodb:retainTableReplica": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, table replica will be default to the removal policy of source table unless specified otherwise." + }, + "@aws-cdk/cognito:logUserPoolClientSecretValue": { + "recommendedValue": false, + "explanation": "When disabled, the value of the user pool client secret will not be logged in the custom resource lambda function logs." + }, + "@aws-cdk/pipelines:reduceCrossAccountActionRoleTrustScope": { + "recommendedValue": true, + "explanation": "When enabled, scopes down the trust policy for the cross-account action role", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-stepfunctions:useDistributedMapResultWriterV2": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the resultWriterV2 property of DistributedMap will be used insted of resultWriter" + }, + "@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": { + "userValue": true, + "recommendedValue": true, + "explanation": "Add an S3 trust policy to a KMS key resource policy for SNS subscriptions." + }, + "@aws-cdk/aws-ec2:requirePrivateSubnetsForEgressOnlyInternetGateway": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, the EgressOnlyGateway resource is only created if private subnets are defined in the dual-stack VPC." + }, + "@aws-cdk/aws-ec2-alpha:useResourceIdForVpcV2Migration": { + "recommendedValue": false, + "explanation": "When enabled, use resource IDs for VPC V2 migration" + }, + "@aws-cdk/aws-s3:publicAccessBlockedByDefault": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, setting any combination of options for BlockPublicAccess will automatically set true for any options not defined." + }, + "@aws-cdk/aws-lambda:useCdkManagedLogGroup": { + "userValue": true, + "recommendedValue": true, + "explanation": "When enabled, CDK creates and manages loggroup for the lambda function" + }, + "@aws-cdk/aws-stepfunctions-tasks:httpInvokeDynamicJsonPathEndpoint": { + "recommendedValue": true, + "explanation": "When enabled, allows using a dynamic apiEndpoint with JSONPath format in HttpInvoke tasks.", + "unconfiguredBehavesLike": { + "v2": true + } + }, + "@aws-cdk/aws-ecs-patterns:uniqueTargetGroupId": { + "recommendedValue": true, + "explanation": "When enabled, ECS patterns will generate unique target group IDs to prevent conflicts during load balancer replacement" + } + } + } + } + }, + "minimumCliVersion": "2.1027.0" +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/tree.json new file mode 100644 index 0000000000000..26f7eb46082ca --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.js.snapshot/tree.json @@ -0,0 +1 @@ +{"version":"tree-0.1","tree":{"id":"App","path":"","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"},"children":{"aws-ecr-tag-mutability-exclusion-stack":{"id":"aws-ecr-tag-mutability-exclusion-stack","path":"aws-ecr-tag-mutability-exclusion-stack","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"},"children":{"ImmutableRepoWithExclusions":{"id":"ImmutableRepoWithExclusions","path":"aws-ecr-tag-mutability-exclusion-stack/ImmutableRepoWithExclusions","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*"]},"children":{"Resource":{"id":"Resource","path":"aws-ecr-tag-mutability-exclusion-stack/ImmutableRepoWithExclusions/Resource","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"},"attributes":{"aws:cdk:cloudformation:type":"AWS::ECR::Repository","aws:cdk:cloudformation:props":{"emptyOnDelete":true,"imageTagMutability":"IMMUTABLE_WITH_EXCLUSION","imageTagMutabilityExclusionFilters":[{"imageTagMutabilityExclusionFilterType":"WILDCARD","imageTagMutabilityExclusionFilterValue":"dev-*"},{"imageTagMutabilityExclusionFilterType":"WILDCARD","imageTagMutabilityExclusionFilterValue":"test-*"}]}}}}},"MutableRepoWithExclusions":{"id":"MutableRepoWithExclusions","path":"aws-ecr-tag-mutability-exclusion-stack/MutableRepoWithExclusions","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2","metadata":["*"]},"children":{"Resource":{"id":"Resource","path":"aws-ecr-tag-mutability-exclusion-stack/MutableRepoWithExclusions/Resource","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"},"attributes":{"aws:cdk:cloudformation:type":"AWS::ECR::Repository","aws:cdk:cloudformation:props":{"emptyOnDelete":true,"imageTagMutability":"MUTABLE_WITH_EXCLUSION","imageTagMutabilityExclusionFilters":[{"imageTagMutabilityExclusionFilterType":"WILDCARD","imageTagMutabilityExclusionFilterValue":"prod-*"},{"imageTagMutabilityExclusionFilterType":"WILDCARD","imageTagMutabilityExclusionFilterValue":"release-v*"}]}}}}},"BootstrapVersion":{"id":"BootstrapVersion","path":"aws-ecr-tag-mutability-exclusion-stack/BootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"aws-ecr-tag-mutability-exclusion-stack/CheckBootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}}},"cdk-ecr-tag-mutability-exclusion-test":{"id":"cdk-ecr-tag-mutability-exclusion-test","path":"cdk-ecr-tag-mutability-exclusion-test","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTest","version":"0.0.0"},"children":{"DefaultTest":{"id":"DefaultTest","path":"cdk-ecr-tag-mutability-exclusion-test/DefaultTest","constructInfo":{"fqn":"@aws-cdk/integ-tests-alpha.IntegTestCase","version":"0.0.0"},"children":{"Default":{"id":"Default","path":"cdk-ecr-tag-mutability-exclusion-test/DefaultTest/Default","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"DeployAssert":{"id":"DeployAssert","path":"cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"},"children":{"BootstrapVersion":{"id":"BootstrapVersion","path":"cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert/BootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}},"CheckBootstrapVersion":{"id":"CheckBootstrapVersion","path":"cdk-ecr-tag-mutability-exclusion-test/DefaultTest/DeployAssert/CheckBootstrapVersion","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}}}}}}},"Tree":{"id":"Tree","path":"Tree","constructInfo":{"fqn":"constructs.Construct","version":"10.4.2"}}}}} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.ts new file mode 100644 index 0000000000000..83034aa01e25f --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecr/test/integ.tag-mutability-exclusion.ts @@ -0,0 +1,30 @@ +import * as cdk from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import * as ecr from 'aws-cdk-lib/aws-ecr'; + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'aws-ecr-tag-mutability-exclusion-stack'); + +new ecr.Repository(stack, 'ImmutableRepoWithExclusions', { + imageTagMutability: ecr.TagMutability.IMMUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('dev-*'), + ecr.ImageTagMutabilityExclusionFilter.wildcard('test-*'), + ], + removalPolicy: cdk.RemovalPolicy.DESTROY, + emptyOnDelete: true, +}); + +new ecr.Repository(stack, 'MutableRepoWithExclusions', { + imageTagMutability: ecr.TagMutability.MUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('prod-*'), + ecr.ImageTagMutabilityExclusionFilter.wildcard('release-v*'), + ], + removalPolicy: cdk.RemovalPolicy.DESTROY, + emptyOnDelete: true, +}); + +new IntegTest(app, 'cdk-ecr-tag-mutability-exclusion-test', { + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-ecr/README.md b/packages/aws-cdk-lib/aws-ecr/README.md index dcbbedf879b17..a0ea018f5c51c 100644 --- a/packages/aws-cdk-lib/aws-ecr/README.md +++ b/packages/aws-cdk-lib/aws-ecr/README.md @@ -121,12 +121,51 @@ By using these methods, you can grant specific operational permissions on the EC ### Image tag immutability -You can set tag immutability on images in our repository using the `imageTagMutability` construct prop. +You can set tag immutability on images in your repository using the `imageTagMutability` construct prop. ```ts new ecr.Repository(this, 'Repo', { imageTagMutability: ecr.TagMutability.IMMUTABLE }); ``` +#### Image tag mutability with exclusion filters + +ECR supports more granular control over image tag mutability by allowing you to specify exclusion filters. This enables you to make your repository immutable while allowing specific tag patterns to remain mutable (or vice versa). + +There are two new mutability options that work with exclusion filters: + +- `MUTABLE_WITH_EXCLUSION`: Tags are mutable by default, except those matching the exclusion filters +- `IMMUTABLE_WITH_EXCLUSION`: Tags are immutable by default, except those matching the exclusion filters + +Use `ImageTagMutabilityExclusionFilter.wildcard()` to create filters with wildcard patterns: + +```ts +// Make all tags immutable except for those starting with 'dev-' or 'test-' +new ecr.Repository(this, 'Repo', { + imageTagMutability: ecr.TagMutability.IMMUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('dev-*'), + ecr.ImageTagMutabilityExclusionFilter.wildcard('test-*'), + ], +}); +``` + +```ts +// Make all tags mutable except for production releases +new ecr.Repository(this, 'Repo', { + imageTagMutability: ecr.TagMutability.MUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('prod-*'), + ecr.ImageTagMutabilityExclusionFilter.wildcard('release-v*'), + ], +}); +``` + +##### Exclusion filter pattern rules + +- Patterns can contain alphanumeric characters, dots (.), underscores (_), hyphens (-), and asterisks (*) as wildcards +- Maximum pattern length is 128 characters +- You can specify up to 5 exclusion filters per repository + ### Encryption By default, Amazon ECR uses server-side encryption with Amazon S3-managed encryption keys which encrypts your data at rest using an AES-256 encryption algorithm. For more control over the encryption for your Amazon ECR repositories, you can use server-side encryption with KMS keys stored in AWS Key Management Service (AWS KMS). Read more about this feature in the [ECR Developer Guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/encryption-at-rest.html). diff --git a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts index 5caafeb851f1f..07d13f66c30bc 100644 --- a/packages/aws-cdk-lib/aws-ecr/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-ecr/lib/repository.ts @@ -586,6 +586,16 @@ export interface RepositoryProps { */ readonly imageTagMutability?: TagMutability; + /** + * The image tag mutability exclusion filters for the repository. + * + * These filters specify which image tags can override the repository's default image tag mutability setting. + * + * @default undefined - AWS ECR default is no exclusion filters + * @see https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-tag-mutability.html + */ + readonly imageTagMutabilityExclusionFilters?: ImageTagMutabilityExclusionFilter[]; + /** * Whether all images should be automatically deleted when the repository is * removed from the stack or when the stack is deleted. @@ -804,6 +814,7 @@ export class Repository extends RepositoryBase { addConstructMetadata(this, props); Repository.validateRepositoryName(this.physicalName); + this.validateTagMutability(props.imageTagMutability, props.imageTagMutabilityExclusionFilters); const resource = new CfnRepository(this, 'Resource', { repositoryName: this.physicalName, @@ -811,7 +822,10 @@ export class Repository extends RepositoryBase { repositoryPolicyText: Lazy.any({ produce: () => this.policyDocument }), lifecyclePolicy: Lazy.any({ produce: () => this.renderLifecyclePolicy() }), imageScanningConfiguration: props.imageScanOnPush !== undefined ? { scanOnPush: props.imageScanOnPush } : undefined, - imageTagMutability: props.imageTagMutability || undefined, + imageTagMutability: props.imageTagMutability, + imageTagMutabilityExclusionFilters: props.imageTagMutabilityExclusionFilters?.map( + filter => filter._render(), + ), encryptionConfiguration: this.parseEncryption(props), emptyOnDelete: props.emptyOnDelete, }); @@ -906,6 +920,36 @@ export class Repository extends RepositoryBase { this.lifecycleRules.push({ ...rule }); } + private validateTagMutability(tagMutability?: TagMutability, exclusionFilters?: ImageTagMutabilityExclusionFilter[]): void { + const EXCLUSION_REQUIRED_TAG_MUTABILITY = [ + TagMutability.IMMUTABLE_WITH_EXCLUSION, + TagMutability.MUTABLE_WITH_EXCLUSION, + ]; + + const requiresExclusion = tagMutability && EXCLUSION_REQUIRED_TAG_MUTABILITY.includes(tagMutability); + const hasExclusionFilters = !!exclusionFilters; + + if (hasExclusionFilters && !requiresExclusion) { + throw new ValidationError( + `imageTagMutability must be 'IMMUTABLE_WITH_EXCLUSION' or 'MUTABLE_WITH_EXCLUSION' when imageTagMutabilityExclusionFilters is provided, got: ${tagMutability}.`, + this, + ); + } + + const filterCount = exclusionFilters?.length; + + if (filterCount !== undefined && (filterCount < 1 || filterCount > 5)) { + throw new ValidationError(`imageTagMutabilityExclusionFilters must contain between 1 and 5 filters, got ${filterCount}.`, this); + } + + if (requiresExclusion && !hasExclusionFilters) { + throw new ValidationError( + `imageTagMutabilityExclusionFilters must be specified when imageTagMutability is '${tagMutability}'.`, + this, + ); + } + } + /** * Render the life cycle policy object */ @@ -1102,6 +1146,45 @@ export enum TagMutability { MUTABLE_WITH_EXCLUSION = 'MUTABLE_WITH_EXCLUSION', } +/** + * Represents an image tag mutability exclusion filter for ECR repository + */ +export class ImageTagMutabilityExclusionFilter { + /** + * Creates a wildcard filter for image tag mutability exclusion + * @param pattern The wildcard pattern to match image tags (e.g., 'dev-*', 'release-v*') + */ + public static wildcard(pattern: string): ImageTagMutabilityExclusionFilter { + return new ImageTagMutabilityExclusionFilter('WILDCARD', pattern); + } + + private constructor( + private readonly filterType: string, + private readonly filterValue: string, + ) { + if (!filterValue) { + throw new UnscopedValidationError('Pattern cannot be empty'); + } + if (filterValue.length > 128) { + throw new UnscopedValidationError(`Pattern cannot exceed 128 characters, got: ${filterValue.length} characters.`); + } + if (!/^[0-9a-zA-Z._*-]+$/.test(filterValue)) { + throw new UnscopedValidationError(`Pattern '${filterValue}' contains invalid characters. Only alphanumeric characters, dots, underscores, asterisks, and hyphens are allowed.`); + } + } + + /** + * Renders the filter to CloudFormation properties + * @internal + */ + public _render(): CfnRepository.ImageTagMutabilityExclusionFilterProperty { + return { + imageTagMutabilityExclusionFilterType: this.filterType, + imageTagMutabilityExclusionFilterValue: this.filterValue, + }; + } +} + /** * Indicates whether server-side encryption is enabled for the object, and whether that encryption is * from the AWS Key Management Service (AWS KMS) or from Amazon S3 managed encryption (SSE-S3). diff --git a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts index 4647b92696121..f49bf655016c2 100644 --- a/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts +++ b/packages/aws-cdk-lib/aws-ecr/test/repository.test.ts @@ -1372,4 +1372,140 @@ describe('repository', () => { }, }); }); + + describe('image tag mutability exclusion filters', () => { + describe('ImageTagMutabilityExclusionFilter class', () => { + test.each([ + 'v1.0.*', + '*-snapshot', + 'a'.repeat(128), + 'abc-123_v1.0*', + ])('accepts valid pattern: %s', (pattern) => { + const filter = ecr.ImageTagMutabilityExclusionFilter.wildcard(pattern); + expect(filter._render()).toEqual({ + imageTagMutabilityExclusionFilterType: 'WILDCARD', + imageTagMutabilityExclusionFilterValue: pattern, + }); + }); + + test('validates pattern is not empty', () => { + expect(() => { + ecr.ImageTagMutabilityExclusionFilter.wildcard(''); + }).toThrow('Pattern cannot be empty'); + }); + + test('validates pattern length does not exceed 128 characters', () => { + const longPattern = 'a'.repeat(129); + expect(() => { + ecr.ImageTagMutabilityExclusionFilter.wildcard(longPattern); + }).toThrow('Pattern cannot exceed 128 characters, got: 129 characters.'); + }); + + test.each([ + ['invalid@pattern', '@'], + ['pattern with spaces', ' '], + ['pattern/with/slash', '/'], + ['pattern\\with\\backslash', '\\'], + ])('rejects pattern with invalid character: %s (contains %s)', (pattern, _invalidChar) => { + expect(() => { + ecr.ImageTagMutabilityExclusionFilter.wildcard(pattern); + }).toThrow(`Pattern '${pattern}' contains invalid characters. Only alphanumeric characters, dots, underscores, asterisks, and hyphens are allowed.`); + }); + }); + + describe('Repository with tag mutability exclusion filters', () => { + test.each([ + [ecr.TagMutability.MUTABLE_WITH_EXCLUSION], + [ecr.TagMutability.IMMUTABLE_WITH_EXCLUSION], + ])('can set %s with filters', (mutability) => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new ecr.Repository(stack, 'Repo', { + imageTagMutability: mutability, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('dev-*'), + ecr.ImageTagMutabilityExclusionFilter.wildcard('test-*'), + ], + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECR::Repository', { + ImageTagMutability: mutability, + ImageTagMutabilityExclusionFilters: [ + { + ImageTagMutabilityExclusionFilterType: 'WILDCARD', + ImageTagMutabilityExclusionFilterValue: 'dev-*', + }, + { + ImageTagMutabilityExclusionFilterType: 'WILDCARD', + ImageTagMutabilityExclusionFilterValue: 'test-*', + }, + ], + }); + }); + + test('throws when filters provided without imageTagMutability', () => { + const stack = new cdk.Stack(); + expect(() => { + new ecr.Repository(stack, 'Repo', { + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('dev-*'), + ], + }); + }).toThrow('imageTagMutability must be \'IMMUTABLE_WITH_EXCLUSION\' or \'MUTABLE_WITH_EXCLUSION\' when imageTagMutabilityExclusionFilters is provided, got: undefined.'); + }); + + test.each([ + [ecr.TagMutability.MUTABLE], + [ecr.TagMutability.IMMUTABLE], + ])('throws when filters provided with %s', (mutability) => { + const stack = new cdk.Stack(); + expect(() => { + new ecr.Repository(stack, 'Repo', { + imageTagMutability: mutability, + imageTagMutabilityExclusionFilters: [ + ecr.ImageTagMutabilityExclusionFilter.wildcard('dev-*'), + ], + }); + }).toThrow(`imageTagMutability must be 'IMMUTABLE_WITH_EXCLUSION' or 'MUTABLE_WITH_EXCLUSION' when imageTagMutabilityExclusionFilters is provided, got: ${mutability}`); + }); + + test.each([ + [ecr.TagMutability.MUTABLE_WITH_EXCLUSION], + [ecr.TagMutability.IMMUTABLE_WITH_EXCLUSION], + ])('throws when %s is used without filters', (mutability) => { + const stack = new cdk.Stack(); + expect(() => { + new ecr.Repository(stack, 'Repo', { + imageTagMutability: mutability, + }); + }).toThrow(`imageTagMutabilityExclusionFilters must be specified when imageTagMutability is '${mutability}'`); + }); + + test('validates empty filter array', () => { + const stack = new cdk.Stack(); + expect(() => { + new ecr.Repository(stack, 'Repo', { + imageTagMutability: ecr.TagMutability.MUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: [], + }); + }).toThrow('imageTagMutabilityExclusionFilters must contain between 1 and 5 filters, got 0.'); + }); + + test('validates maximum filter count', () => { + const stack = new cdk.Stack(); + const filters = Array(6).fill(0).map((_, i) => + ecr.ImageTagMutabilityExclusionFilter.wildcard(`filter-${i}*`), + ); + expect(() => { + new ecr.Repository(stack, 'Repo', { + imageTagMutability: ecr.TagMutability.MUTABLE_WITH_EXCLUSION, + imageTagMutabilityExclusionFilters: filters, + }); + }).toThrow('imageTagMutabilityExclusionFilters must contain between 1 and 5 filters, got 6.'); + }); + }); + }); });