@@ -13,12 +13,41 @@ jobs:
13
13
run : |
14
14
# Find files containing ARN patterns with actual account IDs
15
15
# Exclude .git directory, markdown files, and this workflow file itself
16
- if grep -r --include="*" --exclude="*.md" --exclude-dir=".git" --exclude=".github/workflows/check-arns.yml" -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' .; then
17
- echo "ERROR: Found unsanitized ARNs in the repository"
16
+ # Allow test account ID 123456789012 in test resource directories
17
+
18
+ exposed_arns_found=false
19
+
20
+ # Check all files except excluded ones
21
+ while IFS= read -r -d '' file; do
22
+ # Skip if file is in src/test/resources directory
23
+ if [[ "$file" == *"/src/test/resources/"* ]]; then
24
+ # In test resources, only flag ARNs that are NOT using the test account ID
25
+ # First find all ARNs, then filter out the test account ID
26
+ if grep -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' "$file" | grep -v '123456789012' | grep -q .; then
27
+ echo "ERROR: Found non-test ARN in test resources file: $file"
28
+ echo "Non-test ARNs found:"
29
+ grep -n -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' "$file" | grep -v '123456789012'
30
+ exposed_arns_found=true
31
+ fi
32
+ else
33
+ # In non-test files, flag any ARN with any account ID
34
+ if grep -q -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' "$file"; then
35
+ echo "ERROR: Found unsanitized ARN in file: $file"
36
+ grep -n -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' "$file"
37
+ exposed_arns_found=true
38
+ fi
39
+ fi
40
+ done < <(find . -type f \
41
+ -not -path "./.git/*" \
42
+ -not -name "*.md" \
43
+ -not -path "./.github/workflows/check-arns.yml" \
44
+ -print0)
45
+
46
+ if [ "$exposed_arns_found" = true ]; then
47
+ echo ""
18
48
echo "Please replace account IDs with a placeholder such as <account-id>"
19
- echo "Files with exposed ARNs:"
20
- grep -r --include="*" --exclude="*.md" --exclude-dir=".git" --exclude=".github/workflows/check-arns.yml" -l -E 'arn:aws:[^:]+:[^:]+:[0-9]{12}:' .
49
+ echo "Note: Test account ID 123456789012 is allowed in src/test/resources directories"
21
50
exit 1
22
51
fi
23
52
24
- echo "All files checked - no exposed ARNs found"
53
+ echo "All files checked - no exposed ARNs found (test account ID 123456789012 allowed in test resources) "
0 commit comments