Repository navigation
246 lines (214 loc) · 7.91 KB
/
Copy pathsecurity.yml
File metadata and controls
246 lines (214 loc) · 7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Security Checks
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run security checks weekly on Monday at 00:00 UTC
- cron: '0 0 * * 1'
permissions:
contents: read
security-events: write
jobs:
secret-scanning:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for initial commit (Push)
if: github.event_name == 'push'
id: check_initial
run: |
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
echo "is_initial=true" >> $GITHUB_OUTPUT
FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD)
echo "first_commit=$FIRST_COMMIT" >> $GITHUB_OUTPUT
else
echo "is_initial=false" >> $GITHUB_OUTPUT
fi
- name: TruffleHog OSS (Push - Initial Commit)
if: github.event_name == 'push' && steps.check_initial.outputs.is_initial == 'true'
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ steps.check_initial.outputs.first_commit }}
head: ${{ github.sha }}
extra_args: --only-verified
- name: TruffleHog OSS (Push - Regular)
if: github.event_name == 'push' && steps.check_initial.outputs.is_initial == 'false'
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.before }}
head: ${{ github.sha }}
extra_args: --only-verified
- name: TruffleHog OSS (Pull Request)
if: github.event_name == 'pull_request'
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
extra_args: --only-verified
- name: TruffleHog OSS (Scheduled)
if: github.event_name == 'schedule'
uses: trufflesecurity/trufflehog@main
with:
path: ./
extra_args: --only-verified
license-check:
name: License Compliance
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v5
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-home-cache-cleanup: true
- name: Check license headers with Spotless
run: |
echo "Checking for Apache License headers using Spotless..."
./gradlew spotlessCheck --no-daemon
if [ $? -eq 0 ]; then
echo "✅ All Java files have proper license headers and formatting"
else
echo "❌ Spotless check failed!"
echo ""
echo "Some files are missing license headers or need formatting."
echo "To fix, run locally:"
echo " ./gradlew spotlessApply"
echo "Then commit and push the changes."
exit 1
fi
- name: Verify required files exist
run: |
echo "Checking for required legal files..."
required_files=(
"LICENSE"
"NOTICE"
"SECURITY.md"
"CODE_OF_CONDUCT.md"
"CONTRIBUTING.md"
)
missing=0
for file in "${required_files[@]}"; do
if [ ! -f "$file" ]; then
echo "❌ Missing required file: $file"
missing=$((missing + 1))
else
echo "✅ Found: $file"
fi
done
if [ $missing -gt 0 ]; then
echo "⚠️ Missing $missing required file(s)"
exit 1
fi
sensitive-data-check:
name: Sensitive Data Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Check for accidentally committed secrets
run: |
echo "Checking for sensitive files that should not be committed..."
sensitive_patterns=(
"config.json"
"service-account.json"
"*.key"
"*.pem"
"*.p12"
".env"
"id_rsa"
"id_dsa"
"*.ppk"
"database.properties"
"oauth-secrets.json"
"client_secret*.json"
)
found_sensitive=0
for pattern in "${sensitive_patterns[@]}"; do
files=$(find . -name "$pattern" -not -path "*/build/*" -not -path "*/.gradle/*" 2>/dev/null || true)
if [ -n "$files" ]; then
echo "⚠️ Found potentially sensitive file(s) matching pattern: $pattern"
echo "$files"
found_sensitive=1
fi
done
if [ $found_sensitive -eq 1 ]; then
echo ""
echo "❌ Sensitive files detected in repository!"
echo "These files should be in .gitignore and removed from git history"
echo "If these files were committed, they should be removed and credentials rotated"
exit 1
else
echo "✅ No sensitive files detected in repository"
fi
- name: Check for hardcoded secrets in code
run: |
echo "Checking for potential hardcoded secrets..."
# Search for common secret patterns
secrets_found=0
# Discord bot tokens
if grep -r "discord.*token.*=.*[\"'][A-Za-z0-9._-]\{50,\}[\"']" --include="*.java" --exclude-dir="build" . ; then
echo "⚠️ Possible Discord token found in code"
secrets_found=1
fi
# Database passwords
if grep -r "password.*=.*[\"'][^\"']\{8,\}[\"']" --include="*.java" --include="*.properties" --exclude-dir="build" . | grep -v "example" | grep -v "your_password"; then
echo "⚠️ Possible hardcoded password found"
secrets_found=1
fi
# API keys
if grep -r "api[_-]key.*=.*[\"'][A-Za-z0-9]\{20,\}[\"']" --include="*.java" --exclude-dir="build" . ; then
echo "⚠️ Possible API key found in code"
secrets_found=1
fi
if [ $secrets_found -eq 1 ]; then
echo ""
echo "❌ Potential secrets detected in code!"
echo "Please use environment variables or config files (that are gitignored)"
exit 1
else
echo "✅ No obvious hardcoded secrets detected"
fi
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [secret-scanning, license-check, sensitive-data-check]
if: always()
steps:
- name: Check results
run: |
echo "🔒 Security scan completed"
echo ""
echo "Results:"
echo "- Secret Scanning: ${{ needs.secret-scanning.result }}"
echo "- License Compliance: ${{ needs.license-check.result }}"
echo "- Sensitive Data Check: ${{ needs.sensitive-data-check.result }}"
echo ""
if [ "${{ needs.secret-scanning.result }}" == "failure" ] || \
[ "${{ needs.license-check.result }}" == "failure" ] || \
[ "${{ needs.sensitive-data-check.result }}" == "failure" ]; then
echo "❌ Security checks failed! Please review and fix issues."
exit 1
else
echo "✅ All critical security checks passed!"
fi
echo ""
echo "ℹ️ Note: Dependency security is handled by GitHub's Dependabot and Dependency Review Action"