我有一个 Jenkins 管道,可以在本地环境中持续构建 Python 应用程序。这是代码:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'master', url: 'https://github.com/ibon-castro/full-stack-py.git'
}
}
stage('Install dependencies') {
steps {
sh '''
python3 -m venv venv
bash -c "source venv/bin/activate && pip3 install -r requirements.txt"
'''
}
}
stage('SAST with Bandit') {
steps {
sh '''
# Install Bandit
bash -c "source venv/bin/activate && pip3 install bandit"
# Run Bandit
bash -c "source venv/bin/activate && bandit app.py"
'''
}
}
stage('SCA with Safety') {
steps {
sh '''
bash -c "source venv/bin/activate && pip3 install safety"
bash -c "source venv/bin/activate && safety check -r requirements.txt"
'''
}
}
stage('Deploy') {
steps {
sh '''
# Run the application in the background
bash -c "source venv/bin/activate && python3 app.py &"
bash -c "source venv/bin/activate && docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t http://localhost:5000"
'''
}
}
stage('Archive ZAP Report') {
steps {
archiveArtifacts artifacts: 'zap-report.html', allowEmptyArchive: true
}
}
}
}
使用 OWASP ZAP 执行 DAST 时会出现问题。我总是遇到同样的错误:自动化计划失败: 作业蜘蛛无法访问 URL http://localhost:5000 :连接到 http://localhost:5000 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] 失败:连接被拒绝(连接被拒绝) 2024-09-19 12:42:30,258 无法访问摘要文件 /home/zap/zap_out.json
我也(不成功)尝试使用独立的 zap。
将
--add-host=host.docker.internal:host-gateway
添加到您的 docker 命令并使用 host.docker.internal
而不是 localhost
docker run -t --add-host=host.docker.internal:host-gateway ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t http://host.docker.internal:5000