Skip to content

Commit

Permalink
Samples: Scan dependencies with Trivy
Browse files Browse the repository at this point in the history
but currently only on Linux x64 and arm64
because Trivy Docker images are not available for arm32 or Windows
  • Loading branch information
olljanat committed Dec 12, 2021
1 parent 24ccb9c commit 7ff6d88
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 19 deletions.
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.alpine-arm64
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-musl-arm64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-musl-arm64 --self-contained false --no-restore
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.alpine-x64
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-musl-x64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained false --no-restore
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.alpine-x64-slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.debian-arm64
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-arm64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-arm64 --self-contained false --no-restore
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.debian-x64
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-x64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-x64 --self-contained false --no-restore
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.debian-x64-slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.ubuntu-x64
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-x64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-x64 --self-contained false --no-restore
Expand Down
13 changes: 12 additions & 1 deletion samples/aspnetapp/Dockerfile.ubuntu-x64-slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy everything else and build app
FROM restore AS build
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
Expand Down
1 change: 1 addition & 0 deletions samples/aspnetapp/aspnetapp/aspnetapp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>57393389627611478466</UserSecretsId>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

</Project>
13 changes: 12 additions & 1 deletion samples/complexapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
Expand All @@ -8,7 +8,18 @@ COPY libfoo/*.csproj libfoo/
COPY libbar/*.csproj libbar/
RUN dotnet restore complexapp/complexapp.csproj

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and build app and libraries
FROM restore AS build
COPY complexapp/ complexapp/
COPY libfoo/ libfoo/
COPY libbar/ libbar/
Expand Down
1 change: 1 addition & 0 deletions samples/complexapp/complexapp/complexapp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app --no-restore

Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile.alpine-arm64
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r linux-musl-arm64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app -r linux-musl-arm64 --self-contained false --no-restore

Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile.alpine-x64
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r linux-musl-x64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained false --no-restore

Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile.alpine-x64-slim
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true

Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile.debian-arm64
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r linux-arm64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app -r linux-arm64 --self-contained false --no-restore

Expand Down
13 changes: 12 additions & 1 deletion samples/dotnetapp/Dockerfile.debian-x64
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS restore
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r linux-x64

# dependencies vulnerability scan
FROM aquasec/trivy AS trivy
COPY --from=restore /source /source
RUN trivy fs \
--exit-code 1 \
--no-progress \
--ignore-unfixed \
--severity "HIGH,CRITICAL" \
--security-checks vuln /source

# copy and publish app and libraries
FROM restore AS build
COPY . .
RUN dotnet publish -c release -o /app -r linux-x64 --self-contained false --no-restore

Expand Down
Loading

0 comments on commit 7ff6d88

Please sign in to comment.