Lab setup for devsecops pipeline
write a workflow for below requirements. build devsecops pipeline for in github actions
- this is python project
- use workflow dispatch
- use this for docker image https://hub.docker.com/r/we45/vul_flask/
- SAST we are using GHAS - it should be enabled in security
Approach - 1
- Dev pushes the code
- push will trigger the workflow
- SAST (SCA + SAST)
- DAST via owasp CLI
- building docker
- pushes to any artifact (gcp + azure)
Approach - 2
-
Developer pushes the code
-
Building docker
-
SAST via GHAS for (codescanning, secrets and dependancy issue)
-
DAST via owasp cli
-
pushes the code to any cloud artifact
- name: Authenticate to Google Cloud uses: google/cloud/deploy-gcloud-auth-action@v2 with: credentials: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}-
name: Deploy to Cloud Run run: | gcloud run deploy ${SERVICE_NAME}
--image ghcr.io/<your_username>/<image_name>:
--platform=REGION
--region=${REGION} -
name: Verify deployment run: | gcloud run services describe ${SERVICE_NAME}
-
name: Clean up (optional) if: always() run: | gcloud run services delete ${SERVICE_NAME}
Main Approach
-
Pipeline approach for sample python program
- Dev pushes the code -> 1.1 secret scan -> 1.2 SAST (GHAS) -> 1.3 Build -> 1.4 docker push -> 1.5 github registry
name: Build and Push Docker Image
on: push: branches: [ main ]
jobs: build-and-push: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install Python dependencies
run: |
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- name: Write Python Hello World program
run: |
echo "print('Hello, World!')" > hello_world.py
- name: Build Docker image
run: |
docker build -t <your_username>/<image_name>:<tag> .
- name: Login to GitHub Container Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io
- name: Push Docker image to GitHub Container Registry
run: |
docker push ghcr.io/<your_username>/<image_name>:<tag>
env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
objectivec for lab
- Github repo python hello world program should be there
- whenever code changes happen our on push workflow shopuld trigger
- then start the SCA and SAST scan
- build docker image for the hello world python program
- then pushes to ghcr.io
Error - 15/12/2023
- Not able to push the docker image to ghcr.io
- Need to add sast workflow to the ci.yml file