-
Notifications
You must be signed in to change notification settings - Fork 20
[ADMINAPI-776] Analyze Docker images with docker #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9c2e18b
46016b4
343077b
e196062
a0a499a
ce9aae3
7cdc481
80e2499
68062b8
a72958f
d635a2f
0e4d00b
9acbee4
cc68215
20a0a5d
1d5daee
2e802fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,6 @@ on: | |
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - ".github/workflows/on-pullrequest-dockerfile.yml" | ||
| - "Docker/*" | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
@@ -20,25 +17,90 @@ on: | |
| - "Docker/*" | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} | ||
| DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
|
||
| jobs: | ||
| docker-testing: | ||
| docker-analysis: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| pull-requests: write | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| dockerfile: [ | ||
| { name: "ApiDatabase", path: "Docker/Settings/DB-Admin/pgsql/Dockerfile" }, | ||
| { name: "Postgres", path: "Docker/pgsql.Dockerfile" }, | ||
| { name: "Sql", path: "Docker/mssql.Dockerfile" }, | ||
| { name: "Database", path: "Docker/dbadmin.Dockerfile" }, | ||
| { name: "Development", path: "Docker/dev.Dockerfile" }, | ||
| dockerfile: | ||
| [ | ||
| { name: "api-database", path: "Docker/Settings/DB-Admin/pgsql/Dockerfile", type: "published" }, | ||
| { name: "postgres", path: "Docker/Dockerfile", type: "published" }, | ||
| { name: "database", path: "Docker/dbadmin.Dockerfile", type: "local" }, | ||
| { name: "development", path: "Docker/dev.Dockerfile", type: "local" }, | ||
| ] | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
| uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | ||
| with: | ||
| fetch-depth: 0w | ||
|
|
||
| - name: Copy application folder to docker context | ||
| if: ${{ matrix.dockerfile.type == 'local' }} | ||
| run: | | ||
| mkdir Docker/Application | ||
| cp -r ./Application/EdFi.Ods.AdminApi ./Docker/Application | ||
| cp ./Application/NuGet.Config ./Docker/Application | ||
|
|
||
| - name: Set Version Numbers | ||
| if: ${{ matrix.dockerfile.type == 'published' }} | ||
| id: versions | ||
| run: | | ||
| tag=$(git describe --tags $(git rev-list --tags --max-count=1)) | ||
|
|
||
| if [[ $tag =~ "Pre-Release" ]] | ||
| then | ||
| # Remove Pre-Release prefix | ||
| prefix="Pre-Release-" | ||
| package=${tag#"$prefix"} | ||
| else | ||
| package=${tag} | ||
| fi | ||
|
|
||
| SEMVERSION=${package:1} # strip off the leading 'v' | ||
| echo "Current version: $SEMVERSION" | ||
| echo "VERSION=$SEMVERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0 | ||
| name: Run Linter on ${{ matrix.dockerfile.name }} Dockerfile | ||
| with: | ||
| dockerfile: ${{ matrix.dockerfile.path }} | ||
| failure-threshold: error | ||
| failure-threshold: error | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | ||
| with: | ||
| username: ${{ env.DOCKER_USERNAME }} | ||
| password: ${{ env.DOCKER_HUB_TOKEN }} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docker Scout requires authorization? I suppose that means we get only a few (was it 3?) free repositories this way. Are we able to just run
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried it and did not work. Must have Docker Hub login. Please help me understand what we get for free and what we would need to pay for.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was confusing for me too, basically, to use Docker Scout we need to be logged in but does not count into the 3 allowed repositories. The limit is only for the website enabled ones (that provides some graphs and additional information). This repo is running for 4 containers, and none of those containers are enabled in docker scout and two of those not even exist in docker hub. |
||
|
|
||
| - name: Build | ||
| run: | | ||
| path=${{matrix.dockerfile.path}} | ||
| folder=${path%/*} | ||
| cd $folder | ||
| dockerfile=$(echo ${{matrix.dockerfile.path}} | awk -F"/" '{print $NF}') | ||
|
|
||
| docker build -f $dockerfile -t ${{ matrix.dockerfile.name }} --build-arg="VERSION=${{ steps.versions.outputs.VERSION }}" . | ||
|
|
||
| - name: Analyze | ||
| uses: docker/scout-action@7c61653c2736d21969dd4593fde76c670d4a86cb # v1.2.0 | ||
| with: | ||
| command: cves | ||
| image: local://${{ matrix.dockerfile.name }} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding |
||
| sarif-file: sarif-${{ matrix.dockerfile.name }}.output.json | ||
| summary: true | ||
|
|
||
| - name: Upload SARIF result | ||
| id: upload-sarif | ||
| if: ${{ github.event_name != 'pull_request_target' }} | ||
| uses: github/codeql-action/upload-sarif@df32e399139a3050671466d7d9b3cbacc1cfd034 #codeql-bundle-v2.15.2 | ||
| with: | ||
| sarif_file: sarif-${{ matrix.dockerfile.name }}.output.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,22 +3,24 @@ | |
| # The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| # See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| #tag 6.0-alpine | ||
| #tag 6.0-alpine | ||
| FROM mcr.microsoft.com/dotnet/aspnet@sha256:201cedd60cb295b2ebea7184561a45c5c0ee337e37300ea0f25cff5a2c762538 | ||
| LABEL maintainer="Ed-Fi Alliance, LLC and Contributors <techsupport@ed-fi.org>" | ||
| ARG VERSION=latest | ||
| ARG DB=pgsql | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default value for the DB is pgsql, can be changed to mssql |
||
|
|
||
| # Alpine image does not contain Globalization Cultures library so we need to install ICU library to get for LINQ expression to work | ||
| # Disable the globaliztion invariant mode (set in base image) | ||
| ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY Settings/mssql/appsettings.template.json /app/appsettings.template.json | ||
| COPY Settings/mssql/run.sh /app/run.sh | ||
| COPY Settings/mssql/log4net.config /app/log4net.txt | ||
| COPY Settings/"${DB}"/appsettings.template.json /app/appsettings.template.json | ||
| COPY Settings/"${DB}"/run.sh /app/run.sh | ||
| COPY Settings/"${DB}"/log4net.config /app/log4net.txt | ||
|
|
||
| RUN apk --no-cache add curl=~8 unzip=~6 dos2unix=~7 bash=~5 gettext=~0 jq=~1 icu=~72 && \ | ||
| if [ "$DB" = "pgsql" ]; then apk --no-cache add postgresql13-client=~13; fi && \ | ||
| wget -nv -O /app/AdminApi.zip https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_apis/packaging/feeds/EdFi/nuget/packages/EdFi.Suite3.ODS.AdminApi/versions/${VERSION}/content && \ | ||
| unzip /app/AdminApi.zip AdminApi/* -d /app/ && \ | ||
| cp -r /app/AdminApi/. /app/ && \ | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This work is being triggered only when the PR includes a change into the Dockerfiles or the action, the issue with this is that it can cause the analysis to go without running for a while, therefore, if there are new vulnerabilities it can go unnoticed.
I'm adding this run after merging the PRs to avoid adding noise to the PR itself since current behavior only shows the status, it does not forces or fails the build when new vulnerabilities appear.