-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_next.sh
More file actions
202 lines (184 loc) · 6.08 KB
/
Copy pathsetup_next.sh
File metadata and controls
202 lines (184 loc) · 6.08 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
#!/bin/bash
set -e # Exit immediately if a command fails
echo "🚀 Starting DevSecOps upgrades for Ai-hack-simulation..."
# --- 1. Backup existing CI ---
cp .github/workflows/ci.yml .github/workflows/ci.yml.bak
echo "✅ Backed up existing ci.yml"
# --- 2. Overwrite ci.yml with FULL pipeline (includes CodeQL) ---
cat > .github/workflows/ci.yml <<'EOF'
name: CI - Full Security & Quality Pipeline
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main ]
permissions:
contents: read
security-events: write
jobs:
lint-and-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: '3.11' }
- run: pip install -r requirements.txt bandit flake8 black pip-audit
- run: pip-audit --desc --strict
- run: black --check src/ examples/
- run: flake8 src/ examples/ --count --max-complexity=10 --statistics
- name: Bandit Scan
run: bandit -r src/ -f json -o bandit-report.json || true
- name: Fail on High/Critical Bandit issues
run: |
if grep -q '"severity": "HIGH"' bandit-report.json || grep -q '"severity": "CRITICAL"' bandit-report.json; then
echo "❌ Failing due to high/critical issues."
cat bandit-report.json
exit 1
fi
- uses: actions/upload-artifact@v4
with: { name: bandit-report, path: bandit-report.json }
test-simulation:
runs-on: ubuntu-latest
needs: lint-and-audit
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: '3.11' }
- run: pip install -r requirements.txt
- run: python src/agent.py
- name: Run integration tests
run: |
python src/vulnerable_server.py &
sleep 3
python examples/payload_demo.py
scan-secrets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: 🔑 Gitleaks
uses: gitleaks/gitleaks-action@v2
env: { GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} }
# --- 🆕 NEW: GitHub CodeQL (Deep SAST) ---
codeql-analyze:
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
queries: security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
output: sarif-results
upload: false
- name: Upload CodeQL SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sarif-results/python.sarif
category: /language:python
docker-build-and-scan:
runs-on: ubuntu-latest
needs: [ test-simulation, scan-secrets, codeql-analyze ]
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
push: false
tags: ai-hacking-simulator:latest
load: true
provenance: false
- name: Trivy Scan
uses: aquasecurity/trivy-action@master
with:
image-ref: 'ai-hacking-simulator:latest'
format: 'table'
exit-code: '1'
severity: 'CRITICAL,HIGH'
- name: Generate SBOM (Syft)
uses: anchore/sbom-action@v0
with:
image: ai-hacking-simulator:latest
format: spdx-json
output-file: sbom.spdx.json
- uses: actions/upload-artifact@v4
with:
name: sbom
path: sbom.spdx.json
EOF
echo "✅ Updated ci.yml with CodeQL"
# --- 3. Create Release Please workflow (Auto-versioning) ---
mkdir -p .github/workflows
cat > .github/workflows/release-please.yml <<'EOF'
name: Release Please
on:
push:
branches: [ main ]
permissions:
contents: write
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: python
package-name: ai-hack-simulation
changelog-types: '[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"docs","section":"Documentation"},{"type":"security","section":"Security"}]'
EOF
echo "✅ Added Release Please"
# --- 4. Create GitPod configuration (One-click dev environment) ---
cat > .gitpod.yml <<'EOF'
tasks:
- name: Setup Lab
init: |
pip install -r requirements.txt
echo "💡 Use 'make run-agent' or 'make run-server'"
command: |
echo "🚀 AI Hacking Simulation ready!"
echo "Try: make run-agent"
ports:
- port: 5000
onOpen: open-browser
visibility: public
vscode:
extensions:
- ms-python.python
- GitHub.copilot
EOF
echo "✅ Added GitPod config"
# --- 5. Update README with badges ---
if ! grep -q "GitPod" README.md; then
cat >> README.md <<'EOF'
## 🚀 Try it in 1 Click (No Setup!)
[](https://gitpod.io/#https://github.com/devops2626/Ai-hack-simulation)
[](https://github.com/devops2626/Ai-hack-simulation/releases)
EOF
echo "✅ Added badges to README"
else
echo "ℹ️ Badges already exist in README"
fi
echo ""
echo "🎉 All upgrades applied successfully!"
echo ""
echo "📦 Next steps:"
echo " 1. Review changes: git diff"
echo " 2. Commit and push:"
echo " git add ."
echo " git commit -m 'feat(devops): add CodeQL, Release Please, and GitPod'"
echo " git push origin main"
echo ""
echo "🔍 After pushing:"
echo " - Security → Code scanning: CodeQL findings will appear."
echo " - Actions → 'Release Please' will auto-create a PR for versioning."
echo " - Go to https://gitpod.io/#https://github.com/devops2626/Ai-hack-simulation to launch."