-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: multi-container support (#22)
* check all container in loop * fix error messages * refactor: moved common logic to functions, fixed no pubkey logic * chore: added function documentation * refactor: validate container moved to function * chore: removed .test folder * chore: simplification of dockerfile * feat: makefile & testcases * refactor: verification of container image only * feat: added support for init containers * fix: fixed logging on server shutdown * chore: added test-cases and first draft of e2e tests * chore: added makefile to support local e2e tests * feat: first e2e test draft with signed container & deployment * feat: first working deployment test * feat: end2end.yaml should work now * fix: ephemeral key generation will work now * fix: typo in e2e tests * chore: install cosing for e2e * fix: changed key location * chore: build action runs on main branch only * feat: happy path e2e tests * feat: failing deployments E2E tested * chore: docs & verbose tests to find failure * refactor: WaitForDeployment works with deployment * fix: replaced latest with first to be more explicit * chore: removed old yaml test cases * chore: simplification of dockerfile * feat: makefile & testcases * refactor: verification of container image only * feat: added support for init containers * fix: fixed logging on server shutdown * chore: added test-cases and first draft of e2e tests * chore: added makefile to support local e2e tests * feat: first e2e test draft with signed container & deployment * feat: first working deployment test * feat: end2end.yaml should work now * fix: ephemeral key generation will work now * fix: typo in e2e tests * chore: install cosing for e2e * fix: changed key location * chore: build action runs on main branch only * feat: happy path e2e tests * feat: failing deployments E2E tested * chore: docs & verbose tests to find failure * refactor: WaitForDeployment works with deployment * fix: replaced latest with first to be more explicit * chore: removed old yaml test cases --------- Co-authored-by: Frank Kloeker <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,976 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
cosignwebhook | ||
grumpywebhook | ||
chart/caas-values.yaml | ||
vendor/ | ||
|
||
# the keypair used for test-signing of the webhook | ||
*.key | ||
*.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
############# | ||
### TESTS ### | ||
############# | ||
.PHONY: test-e2e | ||
test-e2e: | ||
@echo "Running e2e tests..." | ||
@go test -v -race -count 1 ./test/ | ||
|
||
test-cleanup: | ||
@echo "Cleaning up..." | ||
@helm uninstall cosignwebhook -n cosignwebhook | ||
@k3d registry delete k3d-registry.localhost | ||
@k3d cluster delete cosign-tests | ||
|
||
.PHONY: test-unit | ||
test-unit: | ||
@echo "Running unit tests..." | ||
@go test -v -race -count 1 ./webhook/ | ||
|
||
########### | ||
### E2E ### | ||
########### | ||
|
||
e2e-cluster: | ||
@echo "Creating registry..." | ||
@k3d registry create registry.localhost --port 5000 | ||
@echo "Adding registry to cluster..." | ||
@k3d cluster create cosign-tests --registry-use k3d-registry.localhost:5000 | ||
@echo "Create test namespace..." | ||
@kubectl create namespace test-cases | ||
|
||
e2e-keys: | ||
@echo "Generating cosign keys..." | ||
@export COSIGN_PASSWORD="" && \ | ||
cosign generate-key-pair && \ | ||
cosign generate-key-pair --output-key-prefix second | ||
|
||
e2e-images: | ||
@echo "Checking for cosign.key..." | ||
@test -f cosign.key || (echo "cosign.key not found. Run 'make generate-key' to generate one." && exit 1) | ||
@echo "Building test image..." | ||
@docker build -t k3d-registry.localhost:5000/cosignwebhook:dev . | ||
@echo "Pushing test image..." | ||
@docker push k3d-registry.localhost:5000/cosignwebhook:dev | ||
@echo "Signing test image..." | ||
@export COSIGN_PASSWORD="" && \ | ||
cosign sign --tlog-upload=false --key cosign.key k3d-registry.localhost:5000/cosignwebhook:dev | ||
@echo "Importing test image to cluster..." | ||
@k3d image import k3d-registry.localhost:5000/cosignwebhook:dev --cluster cosign-tests | ||
@echo "Building busybox image..." | ||
@docker pull busybox:latest | ||
@echo "Tagging & pushing busybox images..." | ||
@docker tag busybox:latest k3d-registry.localhost:5000/busybox:first | ||
@docker tag busybox:latest k3d-registry.localhost:5000/busybox:second | ||
@docker push k3d-registry.localhost:5000/busybox --all-tags | ||
@echo "Signing busybox images..." | ||
@export COSIGN_PASSWORD="" && \ | ||
cosign sign --tlog-upload=false --key cosign.key k3d-registry.localhost:5000/busybox:first && \ | ||
cosign sign --tlog-upload=false --key second.key k3d-registry.localhost:5000/busybox:second | ||
|
||
e2e-deploy: | ||
@echo "Deploying test image..." | ||
@helm upgrade -i cosignwebhook chart -n cosignwebhook --create-namespace \ | ||
--set image.repository=k3d-registry.localhost:5000/cosignwebhook \ | ||
--set image.tag=dev \ | ||
--set-file cosign.scwebhook.key=cosign.pub \ | ||
--set logLevel=debug \ | ||
--wait --debug | ||
|
||
e2e-prep: e2e-cluster e2e-keys e2e-images e2e-deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ kubectl -n cosignwebhook apply -f manifests/manifest.yaml | |
|
||
## Cert generation | ||
|
||
Run the generate-certs script in the `hack` folder to generate the TLS key pair and the CA certificate for the webhook: | ||
|
||
```bash | ||
generate-certs.sh --service cosignwebhook --webhook cosignwebhook --namespace cosignwebhook --secret cosignwebhook | ||
``` | ||
|
@@ -101,17 +103,29 @@ public key used to sign the image you're deploying. | |
|
||
# Test | ||
|
||
Based on the signed image and the corresponding key, the demo app should appear or denied (check event log) | ||
To test the webhook, you may run the following command(s): | ||
|
||
```bash | ||
kubectl create namespace cosignwebhook | ||
kubectl -n cosignwebhook apply -f manifests/demoapp.yaml | ||
# unit tests | ||
make test-unit | ||
# E2E tests | ||
make e2e-prep | ||
make test-e2e | ||
``` | ||
|
||
## E2E tests | ||
|
||
The E2E tests require a running kubernetes cluster. Currently, the namespace and webhook are deployed via helper make targets. To run the tests the following is required: | ||
|
||
- docker | ||
- cosign (v2) | ||
|
||
# TODO | ||
|
||
* [x] Support private images | ||
* [x] Support multiple container/keys | ||
* [ ] Support COSING_REPOSITORY | ||
|
||
# Local build | ||
|
||
|
@@ -122,6 +136,7 @@ CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cosignw | |
## Credits | ||
|
||
Frank Kloeker [email protected] | ||
Bruno Bressi, [email protected] | ||
|
||
Life is for sharing. If you have an issue with the code or want to improve it, feel free to open an issue or an pull | ||
request. | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.