- Newest
- Most votes
- Most comments
The issue you're experiencing is due to the StringLike condition operator in IAM policies not supporting regular expressions.
The StringLike operator only supports simple pattern matching with the * and ? wildcards. It performs a case-insensitive match where * represents any number of characters (including zero) and ? represents exactly one character.
For your specific use case, where you want to match a string containing only digits between 0-9 and exactly 9 characters long, AWS IAM doesn't provide an appropriate operator. It doesn't support a syntax that would allow specifying ranges of characters (such as [0-9]) to match. The length condition alone could be enforced with the ? wildcard, such that "?????????" would match exactly nine characters, but it would allow any characters, not just digits 0-9.
The principle is that IAM policies are designed for access control, not for complex data validation. For intricate tag format requirements, it's often better to enforce these rules at the point where tags are created or modified, rather than trying to do so through IAM policies.
Sources
IAM JSON policy elements: Condition operators - AWS Identity and Access Management
IAM JSON policy elements: Condition - AWS Identity and Access Management
Relevant content
asked 2 years ago
