diff --git a/docs/rules.md b/docs/rules.md index 7d2e9ab294..3c435f8c9d 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -46,7 +46,7 @@ To include these rules, use the `-e/include-experimental` argument when running ## Rules (_This documentation is generated by running `cfn-lint --update-documentation`, do not alter this manually_) -The following **335** rules are applied by this linter: +The following **334** rules are applied by this linter: | Rule ID | Title | Description | Config
(Name:Type:Default) | Source | Tags | | -------- | ----- | ----------- | ---------- | ------ | ---- | @@ -187,7 +187,6 @@ The following **335** rules are applied by this linter: | [E3504](../src/cfnlint/rules/resources/backup/BackupPlanLifecycleRule.py) | Check minimum 90 period is met between BackupPlan cold and delete | Check that Backup plans with lifecycle rules have >= 90 days between cold and delete | | [Source](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-backup-backupplan-lifecycleresourcetype.html) | `properties`,`backup`,`plan`,`lifecycle` | | [E3505](../src/cfnlint/rules/resources/lmbd/EventSourceMappingToSqsTimeout.py) | Validate SQS 'VisibilityTimeout' is greater than a function's 'Timeout' | When attaching a Lambda function to a SQS queue to a Lambda function the SQS 'VisibilityTimeout' has to be greater than or equal to the lambda functions's 'Timeout' | | [Source](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html) | `resources`,`lambda`,`sqs` | | [E3510](../src/cfnlint/rules/resources/iam/IdentityPolicy.py) | Validate identity based IAM polices | IAM identity polices are embedded JSON in CloudFormation. This rule validates those embedded policies. | | [Source](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html) | `resources`,`iam` | -| [E3511](../src/cfnlint/rules/resources/iam/RoleArnPattern.py) | Validate IAM role arn pattern | Validate an IAM role arn pattern matches | | [Source](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) | `parameters`,`iam` | | [E3512](../src/cfnlint/rules/resources/iam/ResourcePolicy.py) | Validate resource based IAM polices | IAM resources polices are embedded JSON in CloudFormation. This rule validates those embedded policies. | | [Source](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html) | `resources`,`iam` | | [E3513](../src/cfnlint/rules/resources/iam/ResourceEcrPolicy.py) | Validate ECR repository policy | Private ECR repositories have a policy. This rule validates those policies. | | [Source](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policies.html) | `resources`,`iam`,`ecr` | | [E3514](../src/cfnlint/rules/resources/iam/ResourcePolicyResourceArn.py) | Validate IAM resource policy resource ARNs | Validates an IAM resource policy has a compliant resource ARN | | [Source](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) | `parameters`,`iam` | diff --git a/src/cfnlint/rules/resources/iam/RoleArnPattern.py b/src/cfnlint/rules/resources/iam/RoleArnPattern.py deleted file mode 100644 index 8883ed83bf..0000000000 --- a/src/cfnlint/rules/resources/iam/RoleArnPattern.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -SPDX-License-Identifier: MIT-0 -""" - -from __future__ import annotations - -from typing import Any - -import regex as re - -from cfnlint.jsonschema import ValidationError, ValidationResult, Validator -from cfnlint.rules.jsonschema.CfnLintKeyword import CfnLintKeyword - - -class RoleArnPattern(CfnLintKeyword): - """Check role arn pattern""" - - id = "E3511" - shortdesc = "Validate IAM role arn pattern" - description = "Validate an IAM role arn pattern matches" - source_url = ( - "https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html" - ) - tags = ["parameters", "iam"] - - def __init__(self) -> None: - super().__init__( - [ - "Resources/AWS::Backup::BackupSelection/Properties/BackupSelection/IamRoleArn", - "Resources/AWS::Batch::ComputeEnvironment/Properties/ComputeResources/SpotIamFleetRole", - "Resources/AWS::Batch::ComputeEnvironment/Properties/ServiceRole", - "Resources/AWS::EC2::SpotFleet/Properties/SpotFleetRequestConfigData/IamFleetRole", - "Resources/AWS::ECS::TaskDefinition/Properties/ExecutionRoleArn", - "Resources/AWS::S3::Bucket/Properties/ReplicationConfiguration/Role", - ] - ) - - # pylint: disable=unused-argument - def validate( - self, validator: Validator, aZ: Any, arn: Any, schema: dict[str, Any] - ) -> ValidationResult: - if not validator.is_type(arn, "string"): - return - - patrn = "^arn:(aws[a-zA-Z-]*)?:iam::\\d{12}:role/[a-zA-Z_0-9+=,.@\\-_/]+$" - - if not re.match(patrn, arn): - yield ValidationError( - f"{arn!r} does not match {patrn!r}", - rule=self, - ) diff --git a/test/unit/rules/resources/iam/test_role_arn_pattern.py b/test/unit/rules/resources/iam/test_role_arn_pattern.py deleted file mode 100644 index ec6ad2cbc3..0000000000 --- a/test/unit/rules/resources/iam/test_role_arn_pattern.py +++ /dev/null @@ -1,56 +0,0 @@ -""" -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -SPDX-License-Identifier: MIT-0 -""" - -import pytest - -from cfnlint.jsonschema.validators import CfnTemplateValidator -from cfnlint.rules.resources.iam.RoleArnPattern import RoleArnPattern - - -def _message_errors(name, arn, errors, **kwargs): - validator = CfnTemplateValidator().evolve(**kwargs) - - i_errors = list(RoleArnPattern().validate(validator, {}, arn, {})) - - assert len(errors) == len(i_errors), ( - f"{name}: Expected exactly {len(errors)} error, " - f"found {i_errors!r}, need {errors!r}" - ) - - err_messages = [err.message for err in i_errors] - for err in errors: - assert err in err_messages, f"{name}: expected {err} to be in {i_errors!r}" - - -@pytest.mark.parametrize( - "name,arn,errors", - [ - ( - "Invalid Arn", - "test", - [ - "'test' does not match '^arn:(aws[a-zA-Z-]*)?:" - "iam::\\\\d{12}:role/[a-zA-Z_0-9+=,.@\\\\-_/]+$'" - ], - ), - ( - "Valid but wrong type", - {}, - [], - ), - ( - "Valid Arn", - "arn:aws:iam::123456789012:role/test", - [], - ), - ( - "Valid Arn for aws-us-gov", - "arn:aws-us-gov:iam::123456789012:role/test", - [], - ), - ], -) -def test_iam_role_arn(name, arn, errors): - _message_errors(name, arn, errors)