Skip to content

Commit a80f4c0

Browse files
update trivy (#330)
1 parent 3daea4c commit a80f4c0

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

.github/workflows/publish.yml

+34-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ env:
1515
REGISTRY_NAME: k8scc01covidacr
1616
# Dev Registry cannot be used in 2.0 since we don't have access to the acrdev
1717
DEV_REGISTRY_NAME: k8scc01covidacrdev
18-
TRIVY_VERSION: "v0.43.1"
18+
TRIVY_VERSION: "v0.57.0"
19+
TRIVY_DATABASES: '"ghcr.io/aquasecurity/trivy-db:2","public.ecr.aws/aquasecurity/trivy-db"'
20+
TRIVY_JAVA_DATABASES: '"ghcr.io/aquasecurity/trivy-java-db:1","public.ecr.aws/aquasecurity/trivy-java-db"'
21+
TRIVY_MAX_RETRIES: 5
22+
TRIVY_RETRY_DELAY: 20
1923
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
2024
HADOLINT_VERSION: "2.12.0"
2125

@@ -78,10 +82,38 @@ jobs:
7882
docker push localhost:5000/jupyter-apis-aaw2:${{ github.sha }}
7983
docker image prune
8084
85+
# Scan image for vulnerabilities
8186
- name: Aqua Security Trivy image scan
8287
run: |
8388
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin ${{ env.TRIVY_VERSION }}
84-
trivy image localhost:5000/jupyter-apis-aaw2:${{ github.sha }} --exit-code 1 --timeout=20m --security-checks vuln --severity CRITICAL
89+
90+
set +e # Lets trivy return an error without it being fatal
91+
92+
for ((i=0; i<${{ env.TRIVY_MAX_RETRIES }}; i++)); do
93+
echo "Attempt $((i + 1)) of ${{ env.TRIVY_MAX_RETRIES }}..."
94+
95+
trivy image \
96+
--db-repository ${{ env.TRIVY_DATABASES }} \
97+
--java-db-repository ${{ env.TRIVY_JAVA_DATABASES }} \
98+
localhost:5000/jupyter-apis-aaw2:${{ github.sha }} \
99+
--exit-code 10 --timeout=20m --scanners vuln --severity CRITICAL \
100+
--skip-dirs /usr/local/SASHome
101+
EXIT_CODE=$?
102+
103+
if [[ $EXIT_CODE -eq 0 ]]; then
104+
echo "Trivy scan completed successfully."
105+
exit 0
106+
elif [[ $EXIT_CODE -eq 10 ]]; then
107+
echo "Trivy scan completed successfully. Some vulnerabilities were found."
108+
exit 10
109+
elif [[ $i -lt $(( ${{ env.TRIVY_MAX_RETRIES }} - 1)) ]]; then
110+
echo "Encountered unexpected error. Retrying in ${{ env.TRIVY_RETRY_DELAY }} seconds..."
111+
sleep ${{ env.TRIVY_RETRY_DELAY }}
112+
else
113+
echo "Unexpected error persists after ${{ env.TRIVY_MAX_RETRIES }} attempts. Exiting."
114+
exit 1
115+
fi
116+
done
85117
86118
# Container build and push to a Azure Container registry (ACR)
87119
- name: Push to ACR if necessary

0 commit comments

Comments
 (0)