-
Notifications
You must be signed in to change notification settings - Fork 0
359 lines (309 loc) · 11 KB
/
validate.yml
File metadata and controls
359 lines (309 loc) · 11 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
name: Validate Splunk App
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install splunk-appinspect xmlschema jsonschema pyyaml
- name: Validate JSON files
run: |
echo "Validating app.manifest..."
python -c "import json; json.load(open('app.manifest'))"
echo "✓ app.manifest is valid JSON"
- name: Validate XML files
run: |
echo "Validating XML files..."
for file in $(find default/data/ui -name "*.xml"); do
echo "Checking $file..."
python -c "import xml.etree.ElementTree as ET; ET.parse('$file')"
done
echo "✓ All XML files are well-formed"
- name: Check version consistency
run: |
echo "Checking version consistency..."
MANIFEST_VERSION=$(python -c "import json; print(json.load(open('app.manifest'))['info']['id']['version'])")
APP_CONF_VERSION=$(grep -E "^version\s*=" default/app.conf | sed 's/.*=\s*//' | tr -d ' ')
echo "app.manifest version: $MANIFEST_VERSION"
echo "app.conf version: $APP_CONF_VERSION"
if [ "$MANIFEST_VERSION" != "$APP_CONF_VERSION" ]; then
echo "❌ Version mismatch between app.manifest and app.conf"
exit 1
fi
echo "✓ Versions are consistent"
- name: Check app ID consistency
run: |
echo "Checking app ID consistency..."
MANIFEST_ID=$(python -c "import json; print(json.load(open('app.manifest'))['info']['id']['name'])")
APP_CONF_ID=$(grep -E "^id\s*=" default/app.conf | sed 's/.*=\s*//' | tr -d ' ')
echo "app.manifest id: $MANIFEST_ID"
echo "app.conf id: $APP_CONF_ID"
if [ "$MANIFEST_ID" != "$APP_CONF_ID" ]; then
echo "❌ App ID mismatch between app.manifest and app.conf"
exit 1
fi
echo "✓ App IDs are consistent"
- name: Validate .conf file syntax
run: |
echo "Validating .conf files..."
python << 'EOF'
import re
import sys
from pathlib import Path
errors = []
conf_files = list(Path('default').glob('*.conf'))
for conf_file in conf_files:
print(f"Checking {conf_file}...")
with open(conf_file, 'r', encoding='utf-8') as f:
lines = f.readlines()
in_stanza = False
for i, line in enumerate(lines, 1):
line = line.strip()
if not line or line.startswith('#'):
continue
if line.startswith('[') and line.endswith(']'):
in_stanza = True
continue
if in_stanza and '=' in line:
key, value = line.split('=', 1)
if not key.strip():
errors.append(f"{conf_file}:{i} - Empty key in key=value pair")
if errors:
print("❌ Configuration file errors:")
for error in errors:
print(f" {error}")
sys.exit(1)
else:
print("✓ All .conf files have valid syntax")
EOF
- name: Check for sensitive data
run: |
echo "Scanning for potential sensitive data..."
python << 'EOF'
import re
import sys
from pathlib import Path
patterns = [
(r'password\s*=\s*[^\s]+', 'Potential hardcoded password'),
(r'token\s*=\s*[^\s]+', 'Potential hardcoded token'),
(r'api[_-]?key\s*=\s*[^\s]+', 'Potential hardcoded API key'),
(r'secret\s*=\s*[^\s]+', 'Potential hardcoded secret'),
]
issues = []
for conf_file in Path('default').glob('*.conf'):
with open(conf_file, 'r', encoding='utf-8') as f:
for i, line in enumerate(f, 1):
if line.strip().startswith('#'):
continue
for pattern, message in patterns:
if re.search(pattern, line, re.IGNORECASE):
issues.append(f"{conf_file}:{i} - {message}")
if issues:
print("⚠️ Warning: Potential sensitive data found:")
for issue in issues:
print(f" {issue}")
# Don't fail build, just warn
else:
print("✓ No obvious sensitive data detected")
EOF
- name: Validate lookup definitions
run: |
echo "Validating lookup tables..."
python << 'EOF'
import re
import sys
from pathlib import Path
# Parse transforms.conf for lookup definitions
transforms_file = Path('default/transforms.conf')
lookups_defined = set()
if transforms_file.exists():
with open(transforms_file, 'r') as f:
for line in f:
match = re.match(r'^\[([^\]]+)\]', line.strip())
if match:
lookups_defined.add(match.group(1))
# Check if CSV files exist
lookups_dir = Path('lookups')
errors = []
if lookups_dir.exists():
for lookup_def in lookups_defined:
# Extract CSV filename from definition name (common pattern)
csv_file = lookups_dir / f"{lookup_def}.csv"
if not csv_file.exists():
# Try without prefix if it has one
parts = lookup_def.split('_', 1)
if len(parts) > 1:
csv_file = lookups_dir / f"{parts[1]}.csv"
if not csv_file.exists():
errors.append(f"Lookup '{lookup_def}' defined but CSV not found in lookups/")
if errors:
print("⚠️ Lookup warnings:")
for error in errors:
print(f" {error}")
else:
print(f"✓ Found {len(lookups_defined)} lookup definitions")
EOF
- name: Check required files
run: |
echo "Checking for required files..."
REQUIRED_FILES=(
"app.manifest"
"default/app.conf"
"README.md"
"LICENSE"
"metadata/default.meta"
)
MISSING=()
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$file" ]; then
MISSING+=("$file")
fi
done
if [ ${#MISSING[@]} -ne 0 ]; then
echo "❌ Missing required files:"
printf ' %s\n' "${MISSING[@]}"
exit 1
fi
echo "✓ All required files present"
- name: Run Splunk AppInspect
run: |
echo "Running Splunk AppInspect..."
# Create a temporary package directory
PACKAGE_DIR="caca"
mkdir -p "$PACKAGE_DIR"
# Copy app files excluding development files
rsync -av \
--exclude='.git*' \
--exclude='local/' \
--exclude='devnotes/' \
--exclude='*.pyc' \
--exclude='__pycache__/' \
--exclude='.DS_Store' \
--exclude='.venv/' \
--exclude='.pytest_cache/' \
--exclude='.pre-commit-config.yaml' \
--exclude='.bandit.yml' \
--exclude='CI-CD-SETUP.md' \
--exclude='scripts/' \
--exclude='appinspect_report.json' \
./ "$PACKAGE_DIR/"
# Run AppInspect
splunk-appinspect inspect "$PACKAGE_DIR" \
--mode precert \
--included-tags cloud \
--output-file appinspect_report.json || true
# Check if report was generated
if [ -f appinspect_report.json ]; then
echo "✓ AppInspect completed - see artifact for results"
else
echo "⚠️ AppInspect report not generated"
fi
- name: Upload AppInspect Report
if: always()
uses: actions/upload-artifact@v4
with:
name: appinspect-report
path: appinspect_report.json
if-no-files-found: ignore
- name: Check AppInspect Results
if: always()
run: |
if [ -f appinspect_report.json ]; then
python << 'EOF'
import json
import sys
with open('appinspect_report.json', 'r') as f:
report = json.load(f)
summary = report.get('summary', {})
failure = summary.get('failure', 0)
error = summary.get('error', 0)
warning = summary.get('warning', 0)
print(f"\nAppInspect Summary:")
print(f" Failures: {failure}")
print(f" Errors: {error}")
print(f" Warnings: {warning}")
if failure > 0 or error > 0:
print("\n❌ AppInspect found failures or errors")
sys.exit(1)
elif warning > 0:
print("\n⚠️ AppInspect found warnings (not failing build)")
else:
print("\n✓ AppInspect passed with no issues")
EOF
else
echo "No AppInspect report to check"
fi
package-validation:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for unwanted files in package
run: |
echo "Checking for files that should not be in package..."
UNWANTED_PATTERNS=(
".git"
".github"
"local/"
"__pycache__"
"*.pyc"
".DS_Store"
".vscode"
"*.swp"
"*.swo"
)
FOUND=()
for pattern in "${UNWANTED_PATTERNS[@]}"; do
if compgen -G "$pattern" > /dev/null 2>&1; then
FOUND+=("$pattern")
fi
done
# Check local/ specifically (it might exist but should be in .gitignore)
if [ -d "local" ] && [ "$(ls -A local)" ]; then
echo "⚠️ Warning: local/ directory exists and is not empty"
fi
if [ ${#FOUND[@]} -ne 0 ]; then
echo "⚠️ Warning: Found unwanted patterns (ensure they're in .gitignore):"
printf ' %s\n' "${FOUND[@]}"
else
echo "✓ No unwanted files found"
fi
- name: Validate .gitignore coverage
run: |
echo "Checking .gitignore coverage..."
SHOULD_IGNORE=(
"local/"
"*.pyc"
"__pycache__/"
".DS_Store"
"*.log"
)
if [ ! -f .gitignore ]; then
echo "⚠️ Warning: No .gitignore file found"
exit 0
fi
MISSING=()
for pattern in "${SHOULD_IGNORE[@]}"; do
if ! grep -q "^${pattern}$" .gitignore; then
MISSING+=("$pattern")
fi
done
if [ ${#MISSING[@]} -ne 0 ]; then
echo "⚠️ Recommended patterns not in .gitignore:"
printf ' %s\n' "${MISSING[@]}"
else
echo "✓ .gitignore covers recommended patterns"
fi