Skip to content

Commit 05fe94a

Browse files
authored
Fix check-arns workflow (#130)
1 parent ac6934c commit 05fe94a

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

.github/workflows/check-arns.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,41 @@ jobs:
1313
run: |
1414
# Find files containing ARN patterns with actual account IDs
1515
# 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 ""
1848
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"
2150
exit 1
2251
fi
2352
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

Comments
 (0)