Compare commits

...

46 Commits

Author SHA1 Message Date
Stefan Reimer 6de66df1a9 Merge pull request 'chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 38484c0' (#7) from renovate/jenkins-inbound-agent-alpine-jdk17 into master
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
Reviewed-on: #7
2024-04-15 15:09:09 +00:00
Stefan Reimer dbdc24fe53 fix: Ensure only traces are sent via OTEL for now
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2024-04-15 14:51:31 +00:00
Renovate Bot bda8c643c6 chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 38484c0
ZeroDownTime/jenkins-podman/pipeline/pr-master This commit looks good Details
2024-04-03 03:05:51 +00:00
Stefan Reimer 4161f32529 fix: subuid cleanup
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
ZeroDownTime/jenkins-podman/pipeline/tag This commit looks good Details
2024-03-12 15:58:19 +00:00
Stefan Reimer d504595922 Merge pull request 'chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 1787182' (#6) from renovate/jenkins-inbound-agent-alpine-jdk17 into master
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
Reviewed-on: #6
2024-03-12 15:57:25 +00:00
Renovate Bot a270f8481e chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 1787182
ZeroDownTime/jenkins-podman/pipeline/pr-master This commit looks good Details
2024-03-12 03:19:02 +00:00
Stefan Reimer c7bc209fd8 Merge pull request 'chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 3452960' (#5) from renovate/jenkins-inbound-agent-alpine-jdk17 into master
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
ZeroDownTime/jenkins-podman/pipeline/tag This commit looks good Details
Reviewed-on: #5
2023-12-14 12:53:41 +00:00
Renovate Bot 1c02becff6 chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 3452960
ZeroDownTime/jenkins-podman/pipeline/pr-master This commit looks good Details
2023-12-05 03:09:08 +00:00
Stefan Reimer 2a2081b01b Merge latest ci-tools-lib
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-11-23 12:31:40 +00:00
Stefan Reimer ab32348082 Squashed '.ci/' changes from 7144a42..2c44e4f
2c44e4f Disable concurrent builds

git-subtree-dir: .ci
git-subtree-split: 2c44e4fd8550d30fba503a2bcccec8e0bac1c151
2023-11-23 12:31:40 +00:00
Stefan Reimer aa92aa43c1 Merge pull request 'chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to d261fad' (#4) from renovate/jenkins-inbound-agent-alpine-jdk17 into master
ZeroDownTime/jenkins-podman/pipeline/head There was a failure building this commit Details
Reviewed-on: #4
2023-11-23 12:29:05 +00:00
Renovate Bot 1ec7cd94e2 chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to d261fad
ZeroDownTime/jenkins-podman/pipeline/pr-master This commit looks good Details
2023-11-14 03:10:33 +00:00
Stefan Reimer 76d259c9fd Add fuse-overlayfs
ZeroDownTime/jenkins-podman/pipeline/tag There was a failure building this commit Details
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-10-02 11:20:48 +00:00
Stefan Reimer 7b7b2ca3b5 Squashed '.ci/' changes from c1a48a6..7144a42
7144a42 Improve Trivy scanning logic

git-subtree-dir: .ci
git-subtree-split: 7144a42a3c436996722f1e67c3cce5c87fdbf464
2023-10-02 11:20:21 +00:00
Stefan Reimer 752977effe Merge latest ci-tools-lib 2023-10-02 11:20:21 +00:00
Stefan Reimer ab2f4423a1 Update trivy template
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-10-02 10:54:33 +00:00
Stefan Reimer 0c3f7306d9 Merge pull request 'chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 4f78d48' (#3) from renovate/jenkins-inbound-agent-alpine-jdk17 into master
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
Reviewed-on: #3
2023-09-28 13:30:24 +00:00
Renovate Bot ddff588aa5 chore(deps): update jenkins/inbound-agent:alpine-jdk17 docker digest to 4f78d48
ZeroDownTime/jenkins-podman/pipeline/pr-master This commit looks good Details
2023-09-28 03:05:00 +00:00
Stefan Reimer 9485a52765 Squashed '.ci/' changes from 5819ded..c1a48a6
c1a48a6 Remove auto stash push / pop as being too dangerous
318c19e Add merge comment for subtree
22ed100 Fix custom branch docker tags
227e39f Allow custom GIT_TAG
38a9cda Debug CI pipeline
3efcc81 Debug CI pipeline
5023473 Make branch detection work for tagged commits
cdc32e0 Improve cleanup flow
8df60af Fix derp
748a4bd Migrate to :: to allow custom make steps, add generic stubs
955afa7 Apply pep8

git-subtree-dir: .ci
git-subtree-split: c1a48a6aede4a08ad1e230121bf8b085ce9ef9e6
2023-09-15 11:59:53 +00:00
Stefan Reimer 69b2522187 Merge commit '9485a52765d37c030572834ae50b17b9c64f8bc5'
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-09-15 11:59:53 +00:00
Stefan Reimer 6c14bc7602 Squashed '.ci/' changes from 5d4e4ad..5819ded
5819ded Improve ECR public lifecycle handling via python script

git-subtree-dir: .ci
git-subtree-split: 5819ded812103aa008fd29b7bb98121e9353cec0
2023-08-11 12:38:13 +00:00
Stefan Reimer b0cadc63d0 Merge commit '6c14bc7602cab6ae0c139265dd216c04ff4c90ea'
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-08-11 12:38:13 +00:00
Stefan Reimer 677265037d Add py-boto3 for advanced build tools
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
ZeroDownTime/jenkins-podman/pipeline/tag This commit looks good Details
2023-08-11 12:31:24 +00:00
Stefan Reimer dde944be55 Add jq
ZeroDownTime/jenkins-podman/pipeline/tag This commit looks good Details
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-08-08 11:06:05 +00:00
Stefan Reimer 5e8acc37e0 Pin upstream Docker image to allow renovate to track
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-08-08 11:00:47 +00:00
Stefan Reimer 68020d36f8 Squashed '.ci/' changes from f00e541..5d4e4ad
5d4e4ad Make rm-remote-untagged less noisy

git-subtree-dir: .ci
git-subtree-split: 5d4e4adce020398a515b5edf73cede0e0f81087b
2023-08-08 11:00:07 +00:00
Stefan Reimer 0d605e2f80 Merge commit '68020d36f8876bae1295e3b35c023eb1d59b1216' 2023-08-08 11:00:07 +00:00
Stefan Reimer d8b6e1daf9 Squashed '.ci/' changes from 0821e91..f00e541
f00e541 Add cleanup step to remove untagged images by default

git-subtree-dir: .ci
git-subtree-split: f00e54179893bcaa915ddbf5c65c28adef70433a
2023-08-08 10:43:40 +00:00
Stefan Reimer 205881747d Merge commit 'd8b6e1daf998761102843e093215a409dbeb524c' 2023-08-08 10:43:40 +00:00
Stefan Reimer 3ce9d5497f Merge pull request 'Configure Renovate' (#1) from renovate/configure into master
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
Reviewed-on: #1
2023-08-07 22:02:52 +00:00
Stefan Reimer c476640823 Squashed '.ci/' changes from 79eebe4..0821e91
0821e91 Ensure tag names are valid for remote branches like PRs

git-subtree-dir: .ci
git-subtree-split: 0821e910f5ea6bbf6645c9b10ea4540d51d3f15f
2023-08-07 21:55:28 +00:00
Stefan Reimer 4fedfc9266 Merge commit 'c476640823d9aef8e10f04630f498c84b48c7a11'
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-08-07 21:55:28 +00:00
Renovate Bot 2edae95107 chore(deps): add renovate.json
ZeroDownTime/jenkins-podman/pipeline/pr-master There was a failure building this commit Details
2023-08-07 13:37:38 +00:00
Stefan Reimer cfbf550484 Squashed '.ci/' changes from a49cc0c..79eebe4
79eebe4 add ARCH support for tests
aea1ccc Only add branch name to tags, if not part of actual tag
a5875db Make EXTRA_TAGS work again
63421d1 fix: prevent branch_name equals tag
47140c2 feat: append branch into tags if not main
4b62ada chore: improve messaging

git-subtree-dir: .ci
git-subtree-split: 79eebe4d3de843d921994db20e20dda801272934
2023-06-05 12:27:06 +00:00
Stefan Reimer 25aeec5c58 Merge commit 'cfbf5504847d76e57ad33ad0a7342ed6b370a1b4'
ZeroDownTime/jenkins-podman/pipeline/tag This commit looks good Details
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2023-06-05 12:27:06 +00:00
Stefan Reimer a0d5ad8179 Squashed '.ci/' changes from 8fb40c7..a49cc0c
a49cc0c chore: improve messaging
194afb4 chore: get ci working again
8ec9769 chore: get ci working again
fef4968 fix: do NOT push PRs to registry, other fixes
50a6d67 feat: ensure ARCH is only set to defined values

git-subtree-dir: .ci
git-subtree-split: a49cc0c90b179c05b824084bafc1d97c28969bc4
2022-12-21 13:12:34 +00:00
Stefan Reimer 5b4fa361b0 Merge commit 'a0d5ad81792b596ee1ae02774d06362b18b77796' 2022-12-21 13:12:34 +00:00
Stefan Reimer 143939ffee ci: add gitignore to never push report.html again
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2022-11-18 21:18:11 +01:00
Stefan Reimer ac3c63e488 chore: remove sample report.html
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2022-11-18 21:17:35 +01:00
Stefan Reimer 6f07c768f0 chore: remove detect-secrets as trivy can do that now just as good
ZeroDownTime/jenkins-podman/pipeline/head This commit looks good Details
2022-11-18 21:12:32 +01:00
Stefan Reimer d175bf3e08 fix: set HOME to actual jenkins home
ZeroDownTime/jenkins-podman/pipeline/head Something is wrong with the build of this commit Details
2022-11-18 14:15:08 +01:00
Stefan Reimer 632076a98d Squashed '.ci/' changes from 7378ea9..8fb40c7
8fb40c7 fix: adjust trivy call to local podman

git-subtree-dir: .ci
git-subtree-split: 8fb40c7f153e86df15baf1477e29370e1693f4bd
2022-11-18 14:06:38 +01:00
Stefan Reimer d56b907116 Merge commit '632076a98dcc50c67a52089b66f762988dbb5ec3' 2022-11-18 14:06:38 +01:00
Stefan Reimer ac7a5eec79 chore: Update templates
ZeroDownTime/jenkins-podman/pipeline/head There was a failure building this commit Details
2022-11-18 13:36:14 +01:00
Stefan Reimer c25e2a4322 Squashed '.ci/' changes from 80dabc2..7378ea9
7378ea9 fix: fix trivy scan task to match new flow, add BRANCH env to Makefile
38cf7ab fix: more podman/buildah cleanups
aece7fc fix: Improve multi-arch manifest handling

git-subtree-dir: .ci
git-subtree-split: 7378ea9a24bb8ac6b9dd8e7838dfb242c560aa79
2022-11-18 13:35:55 +01:00
Stefan Reimer e6758a0e25 Merge commit 'c25e2a43227eaa67489b9e2941e4ad045206547a' 2022-11-18 13:35:55 +01:00
10 changed files with 215 additions and 349 deletions

63
.ci/ecr_public_lifecycle.py Executable file
View File

@ -0,0 +1,63 @@
#!/usr/bin/env python3
import argparse
import boto3
parser = argparse.ArgumentParser(
description='Implement basic public ECR lifecycle policy')
parser.add_argument('--repo', dest='repositoryName', action='store', required=True,
help='Name of the public ECR repository')
parser.add_argument('--keep', dest='keep', action='store', default=10, type=int,
help='number of tagged images to keep, default 10')
parser.add_argument('--dev', dest='delete_dev', action='store_true',
help='also delete in-development images only having tags like v0.1.1-commitNr-githash')
args = parser.parse_args()
client = boto3.client('ecr-public', region_name='us-east-1')
images = client.describe_images(repositoryName=args.repositoryName)[
"imageDetails"]
untagged = []
kept = 0
# actual Image
# imageManifestMediaType: 'application/vnd.oci.image.manifest.v1+json'
# image Index
# imageManifestMediaType: 'application/vnd.oci.image.index.v1+json'
# Sort by date uploaded
for image in sorted(images, key=lambda d: d['imagePushedAt'], reverse=True):
# Remove all untagged
# if registry uses image index all actual images will be untagged anyways
if 'imageTags' not in image:
untagged.append({"imageDigest": image['imageDigest']})
# print("Delete untagged image {}".format(image["imageDigest"]))
continue
# check for dev tags
if args.delete_dev:
_delete = True
for tag in image["imageTags"]:
# Look for at least one tag NOT beign a SemVer dev tag
if "-" not in tag:
_delete = False
if _delete:
print("Deleting development image {}".format(image["imageTags"]))
untagged.append({"imageDigest": image['imageDigest']})
continue
if kept < args.keep:
kept = kept+1
print("Keeping tagged image {}".format(image["imageTags"]))
continue
else:
print("Deleting tagged image {}".format(image["imageTags"]))
untagged.append({"imageDigest": image['imageDigest']})
deleted_images = client.batch_delete_image(
repositoryName=args.repositoryName, imageIds=untagged)
if deleted_images["imageIds"]:
print("Deleted images: {}".format(deleted_images["imageIds"]))

View File

@ -1,12 +1,26 @@
# Parse version from latest git semver tag
GTAG=$(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
TAG ?= $(shell echo $(GTAG) | awk -F '-' '{ print $$1 "-" $$2 }' | sed -e 's/-$$//')
ARCH := amd64
GIT_TAG ?= $(shell git describe --tags --match v*.*.* 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
# EXTRA_TAGS supposed to be set at the caller, eg. $(shell echo $(TAG) | awk -F '.' '{ print $$1 "." $$2 }')
TAG ::= $(GIT_TAG)
# append branch name to tag if NOT main nor master
ifeq (,$(filter main master, $(GIT_BRANCH)))
# If branch is substring of tag, omit branch name
ifeq ($(findstring $(GIT_BRANCH), $(GIT_TAG)),)
# only append branch name if not equal tag
ifneq ($(GIT_TAG), $(GIT_BRANCH))
# Sanitize GIT_BRANCH to allowed Docker tag character set
TAG = $(GIT_TAG)-$(shell echo $$GIT_BRANCH | sed -e 's/[^a-zA-Z0-9]/-/g')
endif
endif
endif
ARCH ::= amd64
ALL_ARCHS ::= amd64 arm64
_ARCH = $(or $(filter $(ARCH),$(ALL_ARCHS)),$(error $$ARCH [$(ARCH)] must be exactly one of "$(ALL_ARCHS)"))
ifneq ($(TRIVY_REMOTE),)
TRIVY_OPTS := --server $(TRIVY_REMOTE)
TRIVY_OPTS ::= --server $(TRIVY_REMOTE)
endif
.SILENT: ; # no need for @
@ -19,51 +33,52 @@ endif
help: ## Show Help
grep -E '^[a-zA-Z_-]+:.*?## .*$$' .ci/podman.mk | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
build: ## Build the app
docker build --rm -t $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH) --build-arg TAG=$(TAG) --build-arg ARCH=$(ARCH) --platform linux/$(ARCH) .
prepare:: ## custom step on the build agent before building
test: rm-test-image ## Execute Dockerfile.test
test -f Dockerfile.test && \
{ docker build --rm -t $(REGISTRY)/$(IMAGE):$(TAG)-test --from=$(REGISTRY)/$(IMAGE):$(TAG) -f Dockerfile.test --platform linux/$(ARCH) . && \
docker run --rm --env-host -t $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH)-test; } || \
echo "No Dockerfile.test found, skipping test"
fmt:: ## auto format source
lint:: ## Lint source
build: ## Build the app
buildah build --rm --layers -t $(IMAGE):$(TAG)-$(_ARCH) --build-arg TAG=$(TAG) --build-arg ARCH=$(_ARCH) --platform linux/$(_ARCH) .
test:: ## test built artificats
scan: ## Scan image using trivy
echo "Scanning $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH) using Trivy $(TRIVY_REMOTE)"
trivy image $(TRIVY_OPTS) $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH)
echo "Scanning $(IMAGE):$(TAG)-$(_ARCH) using Trivy $(TRIVY_REMOTE)"
trivy image $(TRIVY_OPTS) --quiet --no-progress localhost/$(IMAGE):$(TAG)-$(_ARCH)
# We create new manifest and add TAG-ARCH image
# if manigest exists already, get it and add TAG-ARCH to eg. add arm64 to existing amd64
push: ## push images to registry
for t in $(TAG) latest $(EXTRA_TAGS); \
do echo "creating and pushing: $$t"; \
docker tag $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH) $(REGISTRY)/$(IMAGE):$${t}-$(ARCH) && \
docker push $(REGISTRY)/$(IMAGE):$${t}-$(ARCH); \
podman manifest exists $(IMAGE):$$t || podman manifest create $(IMAGE):$$t; \
buildah manifest add $(IMAGE):$$t $(REGISTRY)/$(IMAGE):$(TAG)-$(ARCH) && docker manifest push $(IMAGE):$$t $(REGISTRY)/$(IMAGE):$$t; \
# first tag and push all actual images
# create new manifest for each tag and add all available TAG-ARCH before pushing
push: ecr-login ## push images to registry
for t in $(TAG) latest $(EXTRA_TAGS); do \
echo "Tagging image with $(REGISTRY)/$(IMAGE):$${t}-$(ARCH)"
buildah tag $(IMAGE):$(TAG)-$(_ARCH) $(REGISTRY)/$(IMAGE):$${t}-$(_ARCH); \
buildah manifest rm $(IMAGE):$$t || true; \
buildah manifest create $(IMAGE):$$t; \
for a in $(ALL_ARCHS); do \
buildah manifest add $(IMAGE):$$t $(REGISTRY)/$(IMAGE):$(TAG)-$$a; \
done; \
echo "Pushing manifest $(IMAGE):$$t"
buildah manifest push --all $(IMAGE):$$t docker://$(REGISTRY)/$(IMAGE):$$t; \
done
ecr-login: ## log into AWS ECR public
aws ecr-public get-login-password --region $(REGION) | docker login --username AWS --password-stdin $(REGISTRY)
aws ecr-public get-login-password --region $(REGION) | podman login --username AWS --password-stdin $(REGISTRY)
clean: rm-test-image rm-image ## delete local built container and test images
rm-remote-untagged: ## delete all remote untagged and in-dev images, keep 10 tagged
echo "Removing all untagged and in-dev images from $(IMAGE) in $(REGION)"
.ci/ecr_public_lifecycle.py --repo $(IMAGE) --dev
rm-remote-untagged: ## delete all remote untagged images
echo "Removing all untagged images from $(IMAGE) in $(REGION)"
IMAGE_IDS=$$(for image in $$(aws ecr-public describe-images --repository-name $(IMAGE) --region $(REGION) --output json | jq -r '.imageDetails[] | select(.imageTags | not ).imageDigest'); do echo -n "imageDigest=$$image "; done) ; \
[ -n "$$IMAGE_IDS" ] && aws ecr-public batch-delete-image --repository-name $(IMAGE) --region $(REGION) --image-ids $$IMAGE_IDS || echo "No image to remove"
clean:: ## clean up source folder
rm-image:
test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(ARCH))" || docker image rm -f $(IMAGE):$(TAG)-$(ARCH) > /dev/null
test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(ARCH))" || echo "Error: Removing image failed"
# Ensure we run the tests by removing any previous runs
rm-test-image:
test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(ARCH)-test)" || docker image rm -f $(IMAGE):$(TAG)-$(ARCH)-test > /dev/null
test -z "$$(docker image ls -q $(IMAGE):$(TAG)-$(ARCH)-test)" || echo "Error: Removing test image failed"
test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || podman image rm -f $(IMAGE):$(TAG)-$(_ARCH) > /dev/null
test -z "$$(podman image ls -q $(IMAGE):$(TAG)-$(_ARCH))" || echo "Error: Removing image failed"
## some useful tasks during development
ci-pull-upstream: ## pull latest shared .ci subtree
git stash && git subtree pull --prefix .ci ssh://git@git.zero-downtime.net/ZeroDownTime/ci-tools-lib.git master --squash && git stash pop
git subtree pull --prefix .ci ssh://git@git.zero-downtime.net/ZeroDownTime/ci-tools-lib.git master --squash -m "Merge latest ci-tools-lib"
create-repo: ## create new AWS ECR public repository
aws ecr-public create-repository --repository-name $(IMAGE) --region $(REGION)

View File

@ -2,24 +2,33 @@
def call(Map config=[:]) {
pipeline {
options {
disableConcurrentBuilds()
}
agent {
node {
label 'podman-aws-trivy'
}
}
stages {
stage('Prepare') {
// get tags
steps {
sh 'git fetch -q --tags ${GIT_URL} +refs/heads/${BRANCH_NAME}:refs/remotes/origin/${BRANCH_NAME}'
sh 'mkdir -p reports'
// we set pull tags as project adv. options
// pull tags
//withCredentials([gitUsernamePassword(credentialsId: 'gitea-jenkins-user')]) {
// sh 'git fetch -q --tags ${GIT_URL}'
//}
// Optional project specific preparations
sh 'make prepare'
}
}
// Build using rootless podman
stage('Build') {
steps {
sh 'make build'
sh 'make build GIT_BRANCH=$GIT_BRANCH'
}
}
@ -31,13 +40,13 @@ def call(Map config=[:]) {
// Scan via trivy
stage('Scan') {
environment {
TRIVY_FORMAT = "template"
TRIVY_OUTPUT = "reports/trivy.html"
}
steps {
sh 'mkdir -p reports'
sh 'make scan'
// we always scan and create the full json report
sh 'TRIVY_FORMAT=json TRIVY_OUTPUT="reports/trivy.json" make scan'
// render custom full html report
sh 'trivy convert -f template -t @/home/jenkins/html.tpl -o reports/trivy.html reports/trivy.json'
publishHTML target: [
allowMissing: true,
alwaysLinkToLastBuild: true,
@ -47,25 +56,33 @@ def call(Map config=[:]) {
reportName: 'TrivyScan',
reportTitles: 'TrivyScan'
]
sh 'echo "Trivy report at: $BUILD_URL/TrivyScan"'
// Scan again and fail on CRITICAL vulns, if not overridden
// fail build if issues found above trivy threshold
script {
if (config.trivyFail == 'NONE') {
echo 'trivyFail == NONE, review Trivy report manually. Proceeding ...'
} else {
sh "TRIVY_EXIT_CODE=1 TRIVY_SEVERITY=${config.trivyFail} make scan"
if ( config.trivyFail ) {
sh "TRIVY_SEVERITY=${config.trivyFail} trivy convert --report summary --exit-code 1 reports/trivy.json"
}
}
}
}
// Push to ECR
// Push to container registry if not PR
// incl. basic registry retention removing any untagged images
stage('Push') {
when { not { changeRequest() } }
steps {
sh 'make ecr-login push'
sh 'make push'
sh 'make rm-remote-untagged'
}
}
// generic clean
stage('cleanup') {
steps {
sh 'make clean'
}
}
}
}
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
report.html

View File

@ -1,9 +1,8 @@
# https://github.com/containers/podman/blob/main/contrib/podmanimage/stable/Containerfile
# https://hub.docker.com/r/jenkins/inbound-agent/tags
ARG BASE="alpine-jdk17"
FROM jenkins/inbound-agent:${BASE}
FROM jenkins/inbound-agent:alpine-jdk17@sha256:38484c0f035a57b3cab5838468fb6c5c2b3f3051e7a2c8b39c99a30823f393ce
ARG BUILDUSER=jenkins
@ -13,11 +12,13 @@ RUN echo "@edge-testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /e
apk add --no-cache \
tini \
make \
jq \
yq \
strace \
fuse-overlayfs \
podman \
buildah \
py3-pip \
py-boto3 \
aws-cli \
trivy@edge-testing
@ -31,8 +32,8 @@ ADD entrypoint.sh /usr/local/bin/entrypoint.sh
# conf/registries.conf will be mounted RO at runtime to inherit worker settings incl. caching proxies
ADD --chown=$BUILDUSER:$BUILDUSER conf/containers.conf conf/storage.conf /home/$BUILDUSER/.config/containers
RUN echo -e "$BUILDUSER:1:999\n$BUILDUSER:1001:64535" > /etc/subuid && \
echo -e "$BUILDUSER:1:999\n$BUILDUSER:1001:64535" > /etc/subgid && \
RUN echo -e "$BUILDUSER:100000:65535" > /etc/subuid && \
echo -e "$BUILDUSER:100000:65535" > /etc/subgid && \
cd /usr/bin && ln -s podman docker && \
chown $BUILDUSER:$BUILDUSER -R /home/$BUILDUSER
@ -42,12 +43,12 @@ RUN sed -i -e 's/exec \$JAVA_BIN/podman system service -t0\&\n exec \$JAV
ENV XDG_RUNTIME_DIR=/home/$BUILDUSER/agent/xdg-run
ENV BUILDAH_ISOLATION=chroot
ENV _CONTAINERS_USERNS_CONFIGURED=""
ENV TRIVY_TEMPLATE="@/home/jenkins/html.tpl"
ENV HOME=/home/$BUILDUSER
# Until we setup the logging and metrics pipelines in OTEL
ENV OTEL_LOGS_EXPORTER=none
ENV OTEL_METRICS_EXPORTER=none
USER $BUILDUSER
# Install detect-secrets
ENV PATH=$PATH:/home/${BUILDUSER}/.local/bin
RUN pip install detect-secrets --user
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"]

View File

@ -1,4 +1,4 @@
#!/bin/sh
mkdir -p $HOME/agent/xdg-run
mkdir -p $HOME/agent/xdg-run $HOME/agent/containers/run $HOME/agent/containers/storage
/usr/local/bin/jenkins-agent

View File

@ -20,6 +20,7 @@
table, th, td {
border: 1px solid black;
border-collapse: collapse;
white-space: nowrap;
padding: .3em;
}
table {
@ -39,7 +40,7 @@
.severity-MEDIUM { background-color: #e9c60060; }
.severity-HIGH { background-color: #ff880060; }
.severity-CRITICAL { background-color: #e4000060; }
.severity-UNKNOWN { background-color: #74747430; }
.severity-UNKNOWN { background-color: #74747460; }
table tr td:first-of-type {
font-weight: bold;
}
@ -82,11 +83,13 @@
</script>
</head>
<body>
<h1><img src="https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png" style="padding-right:10px";>
Trivy Report - {{ now | date "2006-01-02 15:04:05 -0700" }}</h1>
<table>
<tr><td colspan="7">
<h1><img src="https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png" style="padding:10px;float:left";>
{{- escapeXML ( index . 0 ).Target }}<br/>Trivy Report - {{ now | date "2006-01-02 15:04:05 -0700" }}</h1>
</td></tr>
{{- range . }}
<tr class="group-header"><th colspan="7">{{ escapeXML .Target }}({{ escapeXML .Type }})</th></tr>
<tr class="group-header"><th colspan="7">{{ escapeXML .Target }} ({{ .Type | toString | escapeXML }})</th></tr>
{{- if (eq (len .Vulnerabilities) 0) }}
<tr><th colspan="7">No Vulnerabilities found</th></tr>
{{- else }}
@ -100,10 +103,10 @@
<th>Links</th>
</tr>
{{- range .Vulnerabilities }}
<tr class="severity-{{ escapeXML .Vulnerability.Severity }}">
<tr class="severity-{{ escapeXML .Severity }}">
<td class="pkg-name">{{ escapeXML .PkgName }}</td>
<td>{{ escapeXML .VulnerabilityID }}</td>
<td class="severity">{{ escapeXML .Vulnerability.Severity }}</td>
<td class="severity">{{ escapeXML .Severity }}</td>
<td class="pkg-version">{{ escapeXML .InstalledVersion }}</td>
<td>{{ escapeXML .FixedVersion }}</td>
<td>{{ escapeXML .Title }}</td>
@ -144,6 +147,26 @@
</tr>
{{- end }}
{{- end }}
{{- if (eq (len .Secrets) 0) }}
<tr><th colspan="7">No Secrets found</th></tr>
{{- else }}
<tr class="sub-header">
<th colspan="2">Rule ID</th>
<th>Severity</th>
<th>Category</th>
<th colspan="2">Title</th>
<th>Lines</th>
</tr>
{{- range .Secrets }}
<tr class="severity-{{ escapeXML .Severity }}">
<td colspan="2">{{ escapeXML .RuleID }}</td>
<td class="severity">{{ escapeXML .Severity }}</td>
<td>{{ .Category | toString | escapeXML }}</td>
<td colspan="2">{{ escapeXML .Title }}</td>
<td>{{ .StartLine | toString }} - {{ .EndLine | toString }}</td>
</tr>
{{- end }}
{{- end }}
{{- end }}
</table>
{{- else }}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<testsuites>
<testsuites name="trivy">
{{- range . -}}
{{- $failures := len .Vulnerabilities }}
<testsuite tests="{{ $failures }}" failures="{{ $failures }}" name="{{ .Target }}" errors="0" skipped="0" time="">
@ -14,5 +14,18 @@
</testcase>
{{- end }}
</testsuite>
{{- $failures := len .Misconfigurations }}
<testsuite tests="{{ $failures }}" failures="{{ $failures }}" name="{{ .Target }}" errors="0" skipped="0" time="">
{{- if not (eq .Type "") }}
<properties>
<property name="type" value="{{ .Type }}"></property>
</properties>
{{- end -}}
{{ range .Misconfigurations }}
<testcase classname="{{ .Type }}" name="[{{ .Severity }}] {{ .ID }}" time="">
<failure message="{{ escapeXML .Title }}" type="description">{{ escapeXML .Description }}</failure>
</testcase>
{{- end }}
</testsuite>
{{- end }}
</testsuites>
</testsuites>

9
renovate.json Normal file
View File

@ -0,0 +1,9 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
":label(renovate)",
":semanticCommits"
],
"prHourlyLimit": 0
}

View File

@ -1,276 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
* {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
text-align: center;
}
.group-header th {
font-size: 200%;
background-color: #E4E4E4;
}
.sub-header th {
font-size: 150%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: .3em;
}
table {
margin: 0 auto;
}
.severity {
text-align: center;
font-weight: bold;
color: #fafafa;
}
.severity-LOW .severity { background-color: #5fbb31; }
.severity-MEDIUM .severity { background-color: #e9c600; }
.severity-HIGH .severity { background-color: #ff8800; }
.severity-CRITICAL .severity { background-color: #e40000; }
.severity-UNKNOWN .severity { background-color: #747474; }
.severity-LOW { background-color: #5fbb3160; }
.severity-MEDIUM { background-color: #e9c60060; }
.severity-HIGH { background-color: #ff880060; }
.severity-CRITICAL { background-color: #e4000060; }
.severity-UNKNOWN { background-color: #74747430; }
table tr td:first-of-type {
font-weight: bold;
}
.links a,
.links[data-more-links=on] a {
display: block;
}
.links[data-more-links=off] a:nth-of-type(1n+5) {
display: none;
}
a.toggle-more-links { cursor: pointer; }
</style>
<title>localhost/jenkins-podman:v0.2.4-3 (alpine 3.15.0) - Trivy Report - 2022-01-25T13:58:07.832142733Z</title>
<script>
window.onload = function() {
document.querySelectorAll('td.links').forEach(function(linkCell) {
var links = [].concat.apply([], linkCell.querySelectorAll('a'));
[].sort.apply(links, function(a, b) {
return a.href > b.href ? 1 : -1;
});
links.forEach(function(link, idx) {
if (links.length > 3 && 3 === idx) {
var toggleLink = document.createElement('a');
toggleLink.innerText = "Toggle more links";
toggleLink.href = "#toggleMore";
toggleLink.setAttribute("class", "toggle-more-links");
linkCell.appendChild(toggleLink);
}
linkCell.appendChild(link);
});
});
document.querySelectorAll('a.toggle-more-links').forEach(function(toggleLink) {
toggleLink.onclick = function() {
var expanded = toggleLink.parentElement.getAttribute("data-more-links");
toggleLink.parentElement.setAttribute("data-more-links", "on" === expanded ? "off" : "on");
return false;
};
});
};
</script>
</head>
<body>
<h1><img src="https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png" style="padding-right:10px";>
Trivy Report - 2022-01-25T13:58:07.832152637Z</h1>
<table>
<tr class="group-header"><th colspan="7">localhost/jenkins-podman:v0.2.4-3 (alpine 3.15.0)(alpine)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">Java(jar)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/bin/buildah(gobinary)</th></tr>
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
<th>Severity</th>
<th>Installed Version</th>
<th>Fixed Version</th>
<th>Title</th>
<th>Links</th>
</tr>
<tr class="severity-HIGH">
<td class="pkg-name">github.com/containerd/containerd</td>
<td>CVE-2021-41103</td>
<td class="severity">HIGH</td>
<td class="pkg-version">v1.5.5</td>
<td>v1.4.11, v1.5.7</td>
<td>containerd: insufficiently restricted permissions on container root and plugin directories</td>
<td class="links" data-more-links="off">
<a href="https://avd.aquasec.com/nvd/cve-2021-41103" target="_blank" rel="noopener noreferrer">https://avd.aquasec.com/nvd/cve-2021-41103</a>
</td>
</tr>
<tr class="severity-UNKNOWN">
<td class="pkg-name">github.com/opencontainers/image-spec</td>
<td>GMS-2021-101</td>
<td class="severity">UNKNOWN</td>
<td class="pkg-version">v1.0.2-0.20210819154149-5ad6f50d6283</td>
<td>1.0.2</td>
<td>Clarify `mediaType` handling</td>
<td class="links" data-more-links="off">
<a href="https://github.com/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/advisories/GHSA-77vh-xpmg-72qh</a>
<a href="https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m</a>
<a href="https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c</a>
<a href="https://github.com/opencontainers/image-spec/releases/tag/v1.0.2" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/releases/tag/v1.0.2</a>
<a href="https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh</a>
</td>
</tr>
<tr class="severity-UNKNOWN">
<td class="pkg-name">golang.org/x/text</td>
<td>CVE-2021-38561</td>
<td class="severity">UNKNOWN</td>
<td class="pkg-version">v0.3.6</td>
<td>0.3.7</td>
<td></td>
<td class="links" data-more-links="off">
<a href="https://avd.aquasec.com/nvd/cve-2021-38561" target="_blank" rel="noopener noreferrer">https://avd.aquasec.com/nvd/cve-2021-38561</a>
</td>
</tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/bin/git-lfs(gobinary)</th></tr>
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
<th>Severity</th>
<th>Installed Version</th>
<th>Fixed Version</th>
<th>Title</th>
<th>Links</th>
</tr>
<tr class="severity-HIGH">
<td class="pkg-name">golang.org/x/crypto</td>
<td>CVE-2020-29652</td>
<td class="severity">HIGH</td>
<td class="pkg-version">v0.0.0-20201112155050-0c6587e931a9</td>
<td>v0.0.0-20201216223049-8b5274cf687f</td>
<td>golang: crypto/ssh: crafted authentication request can lead to nil pointer dereference</td>
<td class="links" data-more-links="off">
<a href="https://avd.aquasec.com/nvd/cve-2020-29652" target="_blank" rel="noopener noreferrer">https://avd.aquasec.com/nvd/cve-2020-29652</a>
</td>
</tr>
<tr class="severity-UNKNOWN">
<td class="pkg-name">golang.org/x/text</td>
<td>CVE-2021-38561</td>
<td class="severity">UNKNOWN</td>
<td class="pkg-version">v0.3.5</td>
<td>0.3.7</td>
<td></td>
<td class="links" data-more-links="off">
<a href="https://avd.aquasec.com/nvd/cve-2021-38561" target="_blank" rel="noopener noreferrer">https://avd.aquasec.com/nvd/cve-2021-38561</a>
</td>
</tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/bin/podman(gobinary)</th></tr>
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
<th>Severity</th>
<th>Installed Version</th>
<th>Fixed Version</th>
<th>Title</th>
<th>Links</th>
</tr>
<tr class="severity-UNKNOWN">
<td class="pkg-name">github.com/opencontainers/image-spec</td>
<td>GMS-2021-101</td>
<td class="severity">UNKNOWN</td>
<td class="pkg-version">v1.0.2-0.20210819154149-5ad6f50d6283</td>
<td>1.0.2</td>
<td>Clarify `mediaType` handling</td>
<td class="links" data-more-links="off">
<a href="https://github.com/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/advisories/GHSA-77vh-xpmg-72qh</a>
<a href="https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m</a>
<a href="https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c</a>
<a href="https://github.com/opencontainers/image-spec/releases/tag/v1.0.2" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/releases/tag/v1.0.2</a>
<a href="https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh</a>
</td>
</tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/bin/trivy(gobinary)</th></tr>
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
<th>Severity</th>
<th>Installed Version</th>
<th>Fixed Version</th>
<th>Title</th>
<th>Links</th>
</tr>
<tr class="severity-UNKNOWN">
<td class="pkg-name">github.com/opencontainers/image-spec</td>
<td>GMS-2021-101</td>
<td class="severity">UNKNOWN</td>
<td class="pkg-version">v1.0.2-0.20190823105129-775207bd45b6</td>
<td>1.0.2</td>
<td>Clarify `mediaType` handling</td>
<td class="links" data-more-links="off">
<a href="https://github.com/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/advisories/GHSA-77vh-xpmg-72qh</a>
<a href="https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/distribution-spec/security/advisories/GHSA-mc8v-mgrf-8f4m</a>
<a href="https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/commit/693428a734f5bab1a84bd2f990d92ef1111cd60c</a>
<a href="https://github.com/opencontainers/image-spec/releases/tag/v1.0.2" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/releases/tag/v1.0.2</a>
<a href="https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh" target="_blank" rel="noopener noreferrer">https://github.com/opencontainers/image-spec/security/advisories/GHSA-77vh-xpmg-72qh</a>
</td>
</tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/bandwidth(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/bridge(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/dhcp(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/firewall(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/host-device(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/host-local(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/ipvlan(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/loopback(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/macvlan(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/portmap(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/ptp(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/sbr(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/static(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/tuning(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/vlan(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
<tr class="group-header"><th colspan="7">usr/libexec/cni/vrf(gobinary)</th></tr>
<tr><th colspan="7">No Vulnerabilities found</th></tr>
<tr><th colspan="7">No Misconfigurations found</th></tr>
</table>
</body>
</html>