Skip to content
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

Cosign integration. Docker images signature and validation in github actions #492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Install Cosign
uses: sigstore/[email protected]

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
Expand All @@ -31,16 +34,14 @@ jobs:
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'

- name: Validate source code formatting
run: make lint

- name: Build without tests
run: |
make install
Expand All @@ -57,3 +58,19 @@ jobs:
run: |
rm -rf ~/.m2/repository/org/geoserver
find ~/.m2/repository -name "*SNAPSHOT*" -type d | xargs rm -rf {}
- name: Sign images
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
run: |
make sign-image
- name: Verify image signatures
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
COSIGN_PUB_KEY: ${{ secrets.COSIGN_PUB_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
run: |
make verify-image
33 changes: 32 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
all: install test build-image

TAG=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
COSIGN_PASSWORD := $(COSIGN_PASSWORD)

clean:
./mvnw clean
Expand All @@ -17,7 +18,6 @@ install:
test:
./mvnw verify -ntp -T4


build-base-images:
./mvnw clean package -f src/apps/base-images -DksipTests -T4 && \
COMPOSE_DOCKER_CLI_BUILD=1 \
Expand Down Expand Up @@ -47,3 +47,34 @@ push-image:
-f docker-build/infrastructure.yml \
-f docker-build/geoserver.yml \
push

.PHONY: sign-image
sign-image:
@bash -c '\
images=$$(docker images --format "{{.Repository}}@{{.Digest}}" | grep "geoserver-cloud-"); \
for image in $$images; do \
echo "Signing $$image"; \
output=$$(cosign sign --yes --key env://COSIGN_KEY --recursive $$image 2>&1); \
if [ $$? -ne 0 ]; then \
echo "Error occurred: $$output"; \
exit 1; \
else \
echo "Signing successful: $$output"; \
fi; \
done'

.PHONY: verify-image
verify-image:
@bash -c '\
images=$$(docker images --format "{{.Repository}}@{{.Digest}}" | grep "geoserver-cloud-"); \
for image in $$images; do \
echo "Verifying $$image"; \
output=$$(cosign verify --key env://COSIGN_PUB_KEY $$image 2>&1); \
if [ $$? -ne 0 ]; then \
echo "Error occurred: $$output"; \
exit 1; \
else \
echo "Verification successful: $$output"; \
fi; \
done'

Loading