editing github token variable #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Container Security Lab | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| env: | |
| IMAGE_NAME: ${{ github.event.repository.name }} | |
| VERSION: 'latest' | |
| jobs: | |
| codeql: | |
| name: Run CodeQL SAST | |
| runs-on: ubuntu-latest | |
| permissions: | |
| security-events: write | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@v3 | |
| with: | |
| languages: javascript | |
| - name: Autobuild | |
| uses: github/codeql-action/autobuild@v3 | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@v3 | |
| build-push: | |
| name: Build and Push Container Image | |
| runs-on: ubuntu-latest | |
| needs: codeql | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.TOKEN }} | |
| - name: Publish container image | |
| uses: docker/build-push-action@v3 | |
| with: | |
| push: true | |
| builder: ${{ steps.buildx.outputs.name }} | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64 | |
| tags: | | |
| ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| labels: | | |
| org.opencontainers.image.title=${{ github.event.repository.name }} | |
| org.opencontainers.image.description=${{ github.event.repository.description }} | |
| org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.version=${{ env.VERSION }} | |
| trivy: | |
| name: Run Trivy Scan | |
| runs-on: ubuntu-latest | |
| needs: build-push | |
| steps: | |
| - name: Install Trivy | |
| uses: aquasecurity/[email protected] | |
| with: | |
| image-ref: 'ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}' | |
| format: 'table' | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| vuln-type: 'os,library' | |
| severity: 'CRITICAL,HIGH' | |
| sign: | |
| name: Sign Container Image with Cosign | |
| runs-on: ubuntu-latest | |
| needs: trivy | |
| steps: | |
| - name: Install Cosign | |
| uses: sigstore/cosign-installer@main | |
| - name: Sign Container Image | |
| run: | | |
| cosign sign --key env://COSIGN_KEY ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| shell: bash | |
| env: | |
| COSIGN_KEY: ${{secrets.COSIGN_PRIVATE_KEY}} | |
| COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}} | |
| validate-container: | |
| name: Validate Container Image | |
| runs-on: ubuntu-latest | |
| needs: sign | |
| steps: | |
| - name: Check images | |
| run: | | |
| docker buildx imagetools inspect ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| docker pull ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| cosign verify --key env://COSIGN_PUB_KEY ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| - uses: anchore/sbom-action@v0 | |
| with: | |
| image: ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| env: | |
| COSIGN_PUB_KEY: ${{secrets.COSIGN_PUBLIC_KEY}} | |