Repository navigation
test: add an end-to-end check of a deployment - #114
Conversation
tests/e2e/check.sh checks a deployed Pubgrade from outside: it sets up a test Deployment with a Pubgrade-Sidecar in a namespace of the current kubectl context, registers a repository, a user and a subscription, publishes a prebuilt image and checks that the sidecar rolls it out. It removes everything it created, also on failure, and names anything left behind. Credentials come from the environment and never reach an argument list (curl reads headers and bodies from private files). tests/e2e/check-local.sh runs it against Pubgrade on a throwaway k3s cluster, from outside with a kubeconfig and Pubgrade's URL, in the new CI job "Deployment check". The deployment guide says how to run it. Closes #113 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
A namespace given by CHECK_NAMESPACE must exist and is never created or deleted; CHECK_NAME sets a fixed prefix, so that a Route or Ingress can lead to the sidecar of a Pubgrade outside the cluster. The default repository URL can't be cloned, so that a Pubgrade with builds on refuses the build instead of building a real repository. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
- Create the test objects instead of applying them: existing objects of the same names fail the check instead of being taken over and deleted, and no last-applied annotation copies the sidecar's token. - curl ignores ~/.curlrc (--disable) and has time limits. - A second interrupt doesn't stop the cleanup halfway. - Fail if the sidecar's Service doesn't route to it, instead of a confusing failed notification later. - Set the identifiers only once their headers are written, for the cleanup. - Docs: the rights needed, Pod Security, prerequisites, wrapping. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Reviewer's GuideAPIAdd the operator-facing check that provisions a test Deployment and sidecar, registers and verifies a user and subscription, publishes a prebuilt image, verifies notification and rollout, and cleans up created resources.
ConfigurationAdd the local-cluster harness and CI job for running the deployment check, and require its result in the publish and aggregate gates.
DocumentationDocument how operators configure and run the deployment check, its permissions and network requirements, and how developers run it locally.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #114 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 1545 1545
=========================================
Hits 1545 1545 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 06b1031 #113 test: add an end-to-end check of a deployment · 3 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/e2e/check.sh" line_range="59" />
<code_context>
+namespace="${CHECK_NAMESPACE:-pubgrade-check-${run_id}}"
+target="${name}-target"
+sidecar="${name}-sidecar"
+callback_url="${CHECK_CALLBACK_URL:-http://${sidecar}.${namespace}.svc:8080/deployment}"
+sidecar_image="${CHECK_SIDECAR_IMAGE:-elixircloud/pubgrade-sidecar:0.2.0}"
+image="${CHECK_IMAGE:-rancher/mirrored-pause}"
</code_context>
<issue_to_address>
**Callback setting enables SSRF**
When an untrusted caller can set `CHECK_CALLBACK_URL` for a run that has the required Pubgrade credentials, `CHECK_CALLBACK_URL` is stored in the subscription and the subsequent build triggers Pubgrade to send an authenticated PUT to that URL. A caller who can influence this setting when the check runs can make Pubgrade issue requests to hosts reachable from its network, including internal services.
Restrict callback destinations to explicitly trusted hosts or networks before registering the subscription.
</issue_to_address>
### Comment 2
<location path="tests/e2e/check.sh" line_range="54" />
<code_context>
+done
+
+api_url="${PUBGRADE_URL%/}"
+run_id="$(od -An -N4 -tx1 /dev/urandom | tr -d ' \n')"
+name="${CHECK_NAME:-pubgrade-check-${run_id}}"
+namespace="${CHECK_NAMESPACE:-pubgrade-check-${run_id}}"
</code_context>
<issue_to_address>
**A run collision deletes another check**
When two concurrent checks use the same existing `CHECK_NAMESPACE`, omit `CHECK_NAME`, and happen to generate the same 32-bit run ID, the second run’s create fails on the first existing object, then `cleanup` selects the colliding `pubgrade-check` label and deletes the first run’s objects from the shared namespace. The first check loses its Deployment and sidecar.
Use a substantially larger random run ID for names and labels so concurrent runs cannot realistically share an ownership selector.
Also at `tests/e2e/check.sh:147`.
</issue_to_address>
### Comment 3
<location path="tests/e2e/check.sh" line_range="182" />
<code_context>
+# deleted), and no last-applied annotation copies the token
+if [ -z "${CHECK_NAMESPACE:-}" ]; then
+ "${KUBECTL}" create namespace "${namespace}" > /dev/null
+ created_namespace=1
+fi
+created_objects=1
</code_context>
<issue_to_address>
**Created resources escape cleanup**
When the Kubernetes API or Pubgrade commits a create but the response is lost or times out, `create namespace` or `api` returns nonzero before the cleanup flag or resource ID is recorded, so `cleanup` skips deleting the namespace, repository, user, or subscription and leaves it behind.
Make create handling recover and record the created resource for cleanup even when the response is lost.
Also at `tests/e2e/check.sh:308-312`, `tests/e2e/check.sh:315-319`, `tests/e2e/check.sh:331`.
</issue_to_address>
### Comment 4
<location path="tests/e2e/check.sh" line_range="98" />
<code_context>
+ # `--disable` first: no ~/.curlrc, which could log or forward the headers.
+ # The build's POST waits for the notifications
+ local -a args=(--disable --silent --show-error --connect-timeout 10
+ --max-time 120 --request "${method}" --output "${work}/response" --write-out '%{http_code}')
+ if [ -n "${headers}" ]; then
+ args+=(--header "@${headers}")
</code_context>
<issue_to_address>
**Long notifications fail the check**
When pubgrade's configured notification timeout allows a notification request to remain open beyond 120 seconds, `api` stops waiting after 120 seconds and returns a transport error before Pubgrade finishes processing or reports the notification result, so the check reports failure even when the rollout succeeds.
Set the request timeout to cover Pubgrade's configured notification wait, including its additional response margin.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and the check creates a subscription and posts a test build, which causes Pubgrade to send a notification to CHECK_CALLBACK_URL; cleanup can remove the test records and cluster objects, but it cannot recall a notification already sent. The check also uses an admin token to verify its temporary test user.
Blocking findings: tests/e2e/check.sh:59, tests/e2e/check.sh:54, tests/e2e/check.sh:182, tests/e2e/check.sh:98
- Run IDs have 48 bits instead of 32, so that concurrent checks in one namespace don't share a label. - The namespace is recorded before it is created, and deleted with --ignore-not-found, so that a create whose answer got lost is still cleaned up. - Calls to Pubgrade wait up to CHECK_TIMEOUT, as the build's POST waits for the notifications. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary
Adds an end-to-end check of a deployed Pubgrade for operators, and runs it in CI.
tests/e2e/check.sh, run against a Pubgrade URL with the current kubectl context:rancher/mirrored-pause:3.9) and a Pubgrade-Sidecar (elixircloud/pubgrade-sidecar:0.2.0) with rights on that Deployment only, in a new namespace (or in a named, existing one);PUT /deploymentto tag3.10;3.10as a prebuilt image, the way a repository's CI does with builds off (the default). Pubgrade's real flow with builds off is this prebuilt path; with builds on, Pubgrade would build the repository instead, so the default repository URL can't be cloned and the check fails rather than building something;deliveredand that the Deployment rolls out3.10;PUBGRADE_URL,PUBGRADE_ADMIN_ID,PUBGRADE_ADMIN_TOKEN. No token reaches any argv incheck.sh:--header @file, and--disableso~/.curlrcis ignored);kubectl createon stdin;OK:line per step and anERROR:with the reason on failure, with a non-zero exit. Example: when the callback is unreachable, it prints the notification result and hints at NetworkPolicies or builds being on.CHECK_*variables cover the namespace, name prefix, callback URL (for a Pubgrade outside the cluster, through a Route or Ingress), images, tags and timeout.tests/e2e/check-local.shrunscheck.shagainst Pubgrade from its chart on the throwaway k3s cluster oftests/e2e/cluster.sh, from outside, with a kubeconfig and Pubgrade's URL. That is the same way an operator runs it. It runs in the new CI jobcheck/ "Deployment check", which the gateCI passedneeds. The ruleset needs no change.docs/deployment.mdgets the new section "Checking a deployment": how to run it, the variables, the rights needed, network and Pod Security notes.docs/development.mdcoverscheck-local.shand CI.The chart is untouched. #112 changes a different part of
docs/deployment.md, so the two shouldn't conflict.Closes #113
Verification
check.shlocally against Pubgrade from the chart on a k3s cluster (thecluster.shsetup) from outside, through the kubeconfig and a port-forward. Cases:GET /repositoriesreturns[]);CHECK_NAMESPACE=pubgrade CHECK_NAME=pubgrade-check: passed, no labelled objects left, namespace kept;ERROR: PUT /users/<id>/verify: status 401, cleanup ran, exit 1;CHECK_CALLBACK_URL:notification ... failed, expected delivered (build status FAILED), cleanup ran, exit 1;AlreadyExists, exit 1, and the existing Service was kept unchanged.check-local.shend to end locally. Pullingmongo:7.0inside k3s over this machine's network takes over 4 minutes, longer thancluster.sh's 180 s rollout wait. I ran its steps with MongoDB preloaded (the runs above); CI runs the script itself.mkdocs build --strictpassed. shellcheck (koalaman/shellcheck:stable -x) passed, apart from the info SC2119 thatupgrade.shhas too.check-local.shend to end (1m32s): every stepOK, rollout after 2 s,Check passed. Upgrade, smoke, tests, chart, docs and scans also passed.Declined review findings
upgrade.sh(quality, medium):check.shmust run on its own for operators, without the repository's other scripts.cluster.sh'sapiruns inside the cluster, so it doesn't fit.docs/development.mdsays to keep the defaults in line withupgrade.sh.0.2.0will go stale (quality, low): it is pinned on purpose, like any default, andCHECK_SIDECAR_IMAGEoverrides it. A bump goes with the next sidecar release.cluster.shputs the throwaway admin token of the local cluster intodocker execargv (adversarial, low): this is existing code, local only, and the token is throwaway. The "no argv" guarantee applies tocheck.sh, which operators run.Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary by Sourcery
Add and require an operator-style end-to-end deployment check for validating a deployed Pubgrade installation.
New Features:
Enhancements:
CI:
Documentation:
Tests: