使用 OWASP ZAP 的 Jenkins 管道

问题描述 投票:0回答:1

我有一个 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。

jenkins jenkins-pipeline owasp
1个回答
0
投票

--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
© www.soinside.com 2019 - 2024. All rights reserved.