mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 01:32:00 +01:00
Address the #1 product-repo output constraint in signals/output-constraints.json (`PR checks (Pulse)`, 19.1m median / 44.8m p90) by removing real-clock idle waits and serial test bottlenecks across five slow backend packages on the `Backend tests (rest-*)` and `Unified Agent Native Verification` critical paths: - `internal/websocket/hub_test.go`: run `TestClientWriterRevalidatesIdleConnection` inside `testing/synctest` over an in-memory buffered `net.Conn` listener so the real production `client.writePump()` 30-second ping ticker and policy withdrawal run in virtual time (`30.00s` -> `0.00s` under `-race`). Add `t.Parallel()` to 87 verified global-free tests across 10 files (keeping `setAuditLogger`, `log.Logger`, and `SetGlobalLevel` tests serial). - `internal/truenas/transport_test.go`: run `TestAuthenticatedRPCSurvivesIdleTransportTimeout` inside `testing/synctest` over an in-memory buffered TLS `net.Conn` listener via `client.outboundDialContext` so the real 30-second keepalive ticker, 35-second idle deadline, and 40-second idle wait run in virtual time (`40.02s` -> `0.02s` under `-race`). Add `t.Parallel()` to 98 verified global-free tests across 3 files (keeping `captureRPCCloseLogs` and `t.Setenv` tests serial). - `internal/unifiedresources/*_test.go` (14 files): add `t.Parallel()` to 294 verified global-free tests across the slowest serial test files so they run concurrently and overlap with `TestRetentionLoop_RunsInitialPrune`'s 30s wait (keeping `AllocsPerRun`, `mock.SetEnabled`, and `t.Setenv` files serial). - `pkg/proxmox/*_test.go` (4 files): add `t.Parallel()` to caller-budget and context-cancellation tests and subtests (keeping `log.Logger` tests serial and leaving human-claimed `ha_status_test.go` untouched). - `scripts/installtests/*_test.go` (17 files): add `t.Parallel()` to 110 verified isolated tests (including `agent_url_admission_test.go` and its 8 subtests; leaving human-claimed `build_release_assets_test.go` / `root_install_sh_test.go`, `guidance_recipe_runner_test.go`, and serial `TestInstallSHNASBootOwnersQuiesceBeforeRecoveryErasure` untouched). Zero production code or test assertions changed. Contract-Neutral: Test-only virtual-time (testing/synctest) and t.Parallel() execution speedups; no production behavior or subsystem contract changes. Change-source: pulse-maintainer
1163 lines
49 KiB
Go
1163 lines
49 KiB
Go
package installtests
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestProviderMSPGoBuilderMatchesIntegrationMock(t *testing.T) {
|
|
t.Parallel()
|
|
// These builders use the same Go patch level and immutable image. The
|
|
// mock's build must not exercise a different compiler from the hosted
|
|
// control plane merely because Dependabot advanced one Dockerfile.
|
|
const expected = "golang:1.26.11-alpine@sha256:" + go12611AlpineBuilderDigest
|
|
pattern := regexp.MustCompile(`(?m)^FROM (?:--platform=\$BUILDPLATFORM )?(golang:[^[:space:]]+) AS builder$`)
|
|
for _, path := range [][]string{
|
|
{"deploy", "provider-msp", "Dockerfile.control-plane"},
|
|
{"tests", "integration", "mock-github-server", "Dockerfile"},
|
|
} {
|
|
content, err := os.ReadFile(repoFile(path...))
|
|
if err != nil {
|
|
t.Fatalf("read %s: %v", filepath.Join(path...), err)
|
|
}
|
|
match := pattern.FindStringSubmatch(string(content))
|
|
if len(match) != 2 || match[1] != expected {
|
|
t.Errorf("%s Go builder = %q, want %q", filepath.Join(path...), match, expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProviderMSPAlpineRuntimeMatchesIntegrationMock(t *testing.T) {
|
|
t.Parallel()
|
|
// The hosted control plane and its mock must not silently retain an older
|
|
// runtime base when the server and agent runtime images are refreshed.
|
|
for _, fixture := range []struct {
|
|
path []string
|
|
stage string
|
|
}{
|
|
{[]string{"deploy", "provider-msp", "Dockerfile.control-plane"}, " AS control-plane-runtime-foundation"},
|
|
{[]string{"tests", "integration", "mock-github-server", "Dockerfile"}, ""},
|
|
} {
|
|
contents, err := os.ReadFile(repoFile(fixture.path...))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assertContainsAll(t, string(contents), "FROM alpine:3.24@sha256:"+alpine324RuntimeDigest+fixture.stage+"\n")
|
|
}
|
|
}
|
|
|
|
func TestProviderMSPControlPlaneImageConsumesExactCandidate(t *testing.T) {
|
|
t.Parallel()
|
|
dockerfileBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "Dockerfile.control-plane"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP control-plane Dockerfile: %v", err)
|
|
}
|
|
publishBytes, err := os.ReadFile(repoFile(".github", "workflows", "publish-docker.yml"))
|
|
if err != nil {
|
|
t.Fatalf("read Docker publisher: %v", err)
|
|
}
|
|
dockerfile := string(dockerfileBytes)
|
|
publish := string(publishBytes)
|
|
assertContainsAll(t, dockerfile,
|
|
"FROM control-plane-runtime-foundation AS control_plane_prebuilt",
|
|
"COPY --from=compiled_payload /binaries/pulse-control-plane-linux-${TARGETARCH:-amd64}",
|
|
"FROM control-plane-runtime-foundation AS runtime",
|
|
)
|
|
assertContainsAll(t, publish,
|
|
"Verify exact-candidate container payload",
|
|
"target: control_plane_prebuilt",
|
|
"compiled_payload=${{ runner.temp }}/release-container-payload/payload/compiled",
|
|
)
|
|
assertNotContainsAny(t, publish,
|
|
"PULSE_LICENSE_PUBLIC_KEY",
|
|
"PULSE_UPDATE_SIGNING_KEY",
|
|
"pulse_license_public_key",
|
|
"pulse_update_signing_key",
|
|
)
|
|
}
|
|
|
|
func TestProviderMSPDeployComposeIsProviderModeAndStripeFree(t *testing.T) {
|
|
t.Parallel()
|
|
composePath := repoFile("deploy", "provider-msp", "docker-compose.yml")
|
|
composeBytes, err := os.ReadFile(composePath)
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP compose: %v", err)
|
|
}
|
|
var compose map[string]any
|
|
if err := yaml.Unmarshal(composeBytes, &compose); err != nil {
|
|
t.Fatalf("provider MSP compose must be valid YAML: %v", err)
|
|
}
|
|
text := string(composeBytes)
|
|
assertContainsAny(t, text,
|
|
"CP_CONTROL_PLANE_MODE=provider_hosted_msp",
|
|
"CP_CONTROL_PLANE_MODE=${CP_CONTROL_PLANE_MODE:-provider_hosted_msp}",
|
|
)
|
|
assertContainsAll(t, text,
|
|
"CP_DATA_DIR=${PULSE_PROVIDER_MSP_DATA_DIR:-/data}",
|
|
"CP_PROVIDER_MSP_LICENSE_FILE=${CP_PROVIDER_MSP_LICENSE_FILE:+/run/secrets/provider_msp_license}",
|
|
"CP_DOCKER_NETWORK=${PULSE_PROVIDER_MSP_DOCKER_NETWORK:-pulse-provider-msp}",
|
|
"CP_TRUSTED_PROXY_CIDRS=${CP_TRUSTED_PROXY_CIDRS}",
|
|
"DOCKER_HOST=tcp://docker-socket-proxy:2375",
|
|
"CP_STORAGE_DATA_PATH=${PULSE_PROVIDER_MSP_DATA_DIR:-/data}",
|
|
"CP_STORAGE_ROOT_PATH=/storage-root-spacecheck",
|
|
"CP_STORAGE_DOCKER_PATH=/storage-docker-spacecheck",
|
|
"${PULSE_PROVIDER_MSP_DATA_DIR:-/data}:${PULSE_PROVIDER_MSP_DATA_DIR:-/data}",
|
|
"DOCKER_SOCKET_PROXY_IMAGE",
|
|
"PING=1",
|
|
"VERSION=1",
|
|
"INFO=1",
|
|
"${PULSE_PROVIDER_MSP_DOCKER_SOCKET:-/var/run/docker.sock}:/var/run/docker.sock:ro",
|
|
"${PULSE_PROVIDER_MSP_ROOT_SPACECHECK_DIR:-/var/lib/pulse-provider-msp/spacecheck/root}:/storage-root-spacecheck:ro",
|
|
"${PULSE_PROVIDER_MSP_DOCKER_SPACECHECK_DIR:-/var/lib/docker/.pulse-provider-msp-spacecheck}:/storage-docker-spacecheck:ro",
|
|
"pulse.provider-msp.role=traefik",
|
|
"pulse.provider-msp.role=control-plane",
|
|
"provider_msp_license:",
|
|
"name: ${PULSE_PROVIDER_MSP_DOCKER_NETWORK:-pulse-provider-msp}",
|
|
"subnet: ${PULSE_PROVIDER_MSP_DOCKER_SUBNET:-172.30.0.0/24}",
|
|
)
|
|
assertNotContainsAny(t, text,
|
|
":/host-root",
|
|
":/host-var-lib-docker",
|
|
"STRIPE_",
|
|
"CP_TRIAL_SIGNUP_PRICE_ID",
|
|
"CP_MSP_STARTER_PRICE_ID",
|
|
"CP_MSP_GROWTH_PRICE_ID",
|
|
"CP_MSP_SCALE_PRICE_ID",
|
|
"CP_PUBLIC_CLOUD_SIGNUP_ENABLED",
|
|
)
|
|
}
|
|
|
|
func TestProviderMSPDeployEnvExampleMatchesBootstrapPath(t *testing.T) {
|
|
t.Parallel()
|
|
envBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", ".env.example"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP env example: %v", err)
|
|
}
|
|
text := string(envBytes)
|
|
assertContainsAll(t, text,
|
|
"CP_ENV=production",
|
|
"PULSE_PROVIDER_MSP_DATA_DIR=/data",
|
|
"PULSE_PROVIDER_MSP_DOCKER_NETWORK=pulse-provider-msp",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SUBNET=172.30.0.0/24",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SOCKET=/var/run/docker.sock",
|
|
"PULSE_PROVIDER_MSP_ROOT_SPACECHECK_DIR=/var/lib/pulse-provider-msp/spacecheck/root",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SPACECHECK_DIR=/var/lib/docker/.pulse-provider-msp-spacecheck",
|
|
"CP_TRUSTED_PROXY_CIDRS=172.30.0.0/24",
|
|
// Ships blank on purpose: blank is evaluation. The exact blank form is
|
|
// asserted in TestProviderMSPSetupScriptSupportsUnlicensedEvaluation.
|
|
"CP_PROVIDER_MSP_LICENSE_FILE=",
|
|
"CP_ENTITLEMENT_SIGNING_PRIVATE_KEY=",
|
|
"ACME_DNS_PROVIDER=cloudflare",
|
|
"sudo -E ./setup.sh",
|
|
"docker compose run --rm control-plane provider-msp bootstrap",
|
|
"docker compose run --rm control-plane provider-msp portal-link",
|
|
"CP_SESSION_TTL",
|
|
"docker compose run --rm control-plane provider-msp preflight",
|
|
"docker compose run --rm control-plane provider-msp status",
|
|
"docker compose run --rm control-plane provider-msp status --require-backup",
|
|
"./upgrade.sh --dry-run",
|
|
"./upgrade.sh",
|
|
"./upgrade.sh --rollout-tenants",
|
|
"./run-install-proof.sh",
|
|
"docker compose run --rm control-plane provider-msp install-proof",
|
|
"docker compose run --rm control-plane provider-msp recover --all-degraded --dry-run",
|
|
"docker compose run --rm control-plane provider-msp recover --all-degraded",
|
|
"docker compose run --rm control-plane provider-msp backup create",
|
|
"docker compose run --rm control-plane provider-msp backup verify",
|
|
"docker compose run --rm control-plane provider-msp backup restore",
|
|
"--target-data-dir",
|
|
"--dry-run",
|
|
"docker compose run --rm control-plane provider-msp proof",
|
|
"--account-name",
|
|
"--owner-email",
|
|
"--cleanup",
|
|
)
|
|
assertNotContainsAny(t, text,
|
|
"STRIPE_",
|
|
"CP_TRIAL_SIGNUP_PRICE_ID",
|
|
"CP_MSP_STARTER_PRICE_ID",
|
|
"CP_MSP_GROWTH_PRICE_ID",
|
|
"CP_MSP_SCALE_PRICE_ID",
|
|
"CP_PUBLIC_CLOUD_SIGNUP_ENABLED",
|
|
)
|
|
}
|
|
|
|
func TestProviderMSPSetupScriptMatchesProviderContract(t *testing.T) {
|
|
t.Parallel()
|
|
scriptPath := repoFile("deploy", "provider-msp", "setup.sh")
|
|
result := exec.Command("bash", "-n", scriptPath)
|
|
if output, err := result.CombinedOutput(); err != nil {
|
|
t.Fatalf("provider MSP setup shell syntax failed: %v\n%s", err, output)
|
|
}
|
|
scriptBytes, err := os.ReadFile(scriptPath)
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
text := string(scriptBytes)
|
|
assertContainsAll(t, text,
|
|
"PULSE_PROVIDER_MSP_INSTALL_DIR",
|
|
"PULSE_PROVIDER_MSP_DATA_DIR",
|
|
"PULSE_PROVIDER_MSP_DOCKER_NETWORK",
|
|
"PULSE_PROVIDER_MSP_BUNDLE_URL",
|
|
"docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin",
|
|
"docker-compose.yml",
|
|
"traefik-dynamic.yml",
|
|
".env.example",
|
|
"run-install-proof.sh",
|
|
"upgrade.sh",
|
|
"CP_PROVIDER_MSP_LICENSE_FILE",
|
|
"CP_ENTITLEMENT_SIGNING_PRIVATE_KEY",
|
|
"PULSE_PROVIDER_MSP_DATA_DIR",
|
|
"PULSE_PROVIDER_MSP_DOCKER_NETWORK",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SUBNET",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SOCKET",
|
|
"PULSE_PROVIDER_MSP_ROOT_SPACECHECK_DIR",
|
|
"PULSE_PROVIDER_MSP_DOCKER_SPACECHECK_DIR",
|
|
"CP_TRUSTED_PROXY_CIDRS",
|
|
"DOCKER_SOCKET_PROXY_IMAGE",
|
|
"must be an absolute path",
|
|
"must point to a reachable Docker socket",
|
|
"CP_ADMIN_KEY must be at least 32 characters",
|
|
"CP_TRUSTED_PROXY_CIDRS must include PULSE_PROVIDER_MSP_DOCKER_SUBNET",
|
|
"169.254.169.254/32",
|
|
"will be created by compose with subnet",
|
|
"must not be configured in provider-hosted MSP mode",
|
|
"CP_ALLOW_DOCKERLESS_PROVISIONING must be false",
|
|
"CP_STORAGE_GUARDRAILS_ENABLED must be true",
|
|
"docker compose config --quiet",
|
|
`docker pull "${image_ref}"`,
|
|
"PULSE_PROVIDER_MSP_ACCOUNT_NAME",
|
|
"PULSE_PROVIDER_MSP_OWNER_EMAIL",
|
|
"./run-install-proof.sh",
|
|
"Next step: create your operator account",
|
|
"provider-msp portal-link --email",
|
|
)
|
|
assertNotContainsAny(t, text, "docker network create --subnet")
|
|
}
|
|
|
|
func TestProviderMSPUpgradeRunnerMatchesComposeContract(t *testing.T) {
|
|
t.Parallel()
|
|
scriptPath := repoFile("deploy", "provider-msp", "upgrade.sh")
|
|
result := exec.Command("bash", "-n", scriptPath)
|
|
if output, err := result.CombinedOutput(); err != nil {
|
|
t.Fatalf("provider MSP upgrade runner shell syntax failed: %v\n%s", err, output)
|
|
}
|
|
scriptBytes, err := os.ReadFile(scriptPath)
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP upgrade runner: %v", err)
|
|
}
|
|
text := string(scriptBytes)
|
|
assertContainsAll(t, text,
|
|
"PROVIDER_MSP_UPGRADE_DRY_RUN",
|
|
"PROVIDER_MSP_UPGRADE_ROLLOUT_TENANTS",
|
|
"PROVIDER_MSP_UPGRADE_PRUNE_PREVIOUS",
|
|
"PROVIDER_MSP_UPGRADE_BACKUP_OUTPUT",
|
|
"PROVIDER_MSP_UPGRADE_RESTORE_TARGET",
|
|
"PROVIDER_MSP_UPGRADE_RUN_ID",
|
|
"PROVIDER_MSP_UPGRADE_HEALTH_TIMEOUT",
|
|
"docker compose config --quiet",
|
|
"docker version >/dev/null",
|
|
"provider-msp preflight",
|
|
"provider-msp status",
|
|
"provider-msp status --require-backup",
|
|
"provider-msp backup create",
|
|
"provider-msp backup verify",
|
|
"provider-msp backup restore",
|
|
"--target-data-dir",
|
|
"tenant-runtime rollout --all --image",
|
|
"tenant-runtime rollout",
|
|
"--all",
|
|
"--image",
|
|
"--run-id",
|
|
"--health-timeout",
|
|
"--prune-previous",
|
|
"docker compose pull traefik docker-socket-proxy control-plane",
|
|
"docker compose up -d traefik docker-socket-proxy control-plane",
|
|
"docker compose run --rm --no-deps control-plane",
|
|
"provider_msp_upgrade_ok=true",
|
|
"tenant_runtime_rollout_applied=true",
|
|
"tenant_runtime_rollout_applied=false",
|
|
)
|
|
assertNotContainsAny(t, text,
|
|
"STRIPE_",
|
|
"CP_PUBLIC_CLOUD_SIGNUP_ENABLED",
|
|
)
|
|
}
|
|
|
|
func TestProviderMSPInstallProofRunnerMatchesComposeContract(t *testing.T) {
|
|
t.Parallel()
|
|
scriptPath := repoFile("deploy", "provider-msp", "run-install-proof.sh")
|
|
result := exec.Command("bash", "-n", scriptPath)
|
|
if output, err := result.CombinedOutput(); err != nil {
|
|
t.Fatalf("provider MSP install-proof runner shell syntax failed: %v\n%s", err, output)
|
|
}
|
|
scriptBytes, err := os.ReadFile(scriptPath)
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP install-proof runner: %v", err)
|
|
}
|
|
text := string(scriptBytes)
|
|
assertContainsAll(t, text,
|
|
"docker compose config --quiet",
|
|
"docker version >/dev/null",
|
|
"docker compose pull traefik docker-socket-proxy control-plane",
|
|
"docker compose up -d traefik docker-socket-proxy",
|
|
"provider-msp install-proof",
|
|
"--account-name",
|
|
"--owner-email",
|
|
"--workspace-count",
|
|
"--install-type",
|
|
"--target-path",
|
|
"--skip-image-pull",
|
|
"${#extra_install_args[@]}",
|
|
"docker compose run --rm --no-deps control-plane",
|
|
"docker compose up -d traefik docker-socket-proxy control-plane",
|
|
"provider-msp status",
|
|
)
|
|
assertNotContainsAny(t, text,
|
|
"STRIPE_",
|
|
"CP_PUBLIC_CLOUD_SIGNUP_ENABLED",
|
|
)
|
|
}
|
|
|
|
// Traefik reads its static configuration from exactly one source, and a
|
|
// mounted traefik.yml beats flags and TRAEFIK_* variables. Through v6.7.0 the
|
|
// bundle mounted one carrying admin@example.com, which Let's Encrypt refuses,
|
|
// so no install obtained a certificate and ACME_EMAIL and ACME_DNS_PROVIDER
|
|
// never reached Traefik. The static configuration now lives in compose flags.
|
|
func TestProviderMSPTraefikStaticConfigComesFromComposeFlags(t *testing.T) {
|
|
t.Parallel()
|
|
if _, err := os.Stat(repoFile("deploy", "provider-msp", "traefik.yml")); !os.IsNotExist(err) {
|
|
t.Fatal("deploy/provider-msp/traefik.yml must not return: a mounted static file overrides every compose flag")
|
|
}
|
|
composeBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "docker-compose.yml"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP compose: %v", err)
|
|
}
|
|
var compose struct {
|
|
Services map[string]struct {
|
|
Command []string `yaml:"command"`
|
|
Volumes []string `yaml:"volumes"`
|
|
Environment []string `yaml:"environment"`
|
|
} `yaml:"services"`
|
|
}
|
|
if err := yaml.Unmarshal(composeBytes, &compose); err != nil {
|
|
t.Fatalf("provider MSP compose must be valid YAML: %v", err)
|
|
}
|
|
traefik := compose.Services["traefik"]
|
|
for _, volume := range traefik.Volumes {
|
|
if strings.Contains(volume, "traefik.yml") {
|
|
t.Fatalf("traefik must not mount a static config file: %s", volume)
|
|
}
|
|
}
|
|
for _, env := range traefik.Environment {
|
|
if strings.HasPrefix(env, "TRAEFIK_") {
|
|
t.Fatalf("TRAEFIK_* variables are ignored beside compose flags and must not suggest otherwise: %s", env)
|
|
}
|
|
}
|
|
assertContainsAll(t, strings.Join(traefik.Command, "\n"),
|
|
"--providers.docker.network=${PULSE_PROVIDER_MSP_DOCKER_NETWORK:-pulse-provider-msp}",
|
|
"--providers.file.filename=/etc/traefik/traefik-dynamic.yml",
|
|
"--entrypoints.websecure.http.middlewares=security-headers@file",
|
|
"--certificatesresolvers.letsencrypt.acme.email=${ACME_EMAIL:?ACME_EMAIL must be set}",
|
|
"--certificatesresolvers.letsencrypt.acme.${ACME_CHALLENGE_SETTING_1:-dnschallenge.provider=${ACME_DNS_PROVIDER:-cloudflare}}",
|
|
"--certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme/acme.json",
|
|
"--certificatesresolvers.le.acme.email=${ACME_EMAIL:?ACME_EMAIL must be set}",
|
|
"--certificatesresolvers.le.acme.${ACME_CHALLENGE_SETTING_1:-dnschallenge.provider=${ACME_DNS_PROVIDER:-cloudflare}}",
|
|
)
|
|
for _, flag := range traefik.Command {
|
|
if strings.Contains(flag, "acme.email=") && strings.Contains(flag, "example.com") {
|
|
t.Fatalf("the ACME contact must come from ACME_EMAIL, not an example.com address: %s", flag)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProviderMSPControlPlaneDockerfileBuildsReleaseLicenseBinary(t *testing.T) {
|
|
t.Parallel()
|
|
dockerfileBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "Dockerfile.control-plane"))
|
|
if err != nil {
|
|
t.Fatalf("read control-plane Dockerfile: %v", err)
|
|
}
|
|
text := string(dockerfileBytes)
|
|
assertContainsAll(t, text,
|
|
"# syntax=docker/dockerfile:1.7",
|
|
"FROM --platform=linux/amd64 node:24-alpine@sha256:"+node24Amd64FrontendDigest+" AS frontend-builder",
|
|
"npm ci",
|
|
"npm run build",
|
|
"FROM --platform=$BUILDPLATFORM golang:1.26.11-alpine@sha256:"+go12611AlpineBuilderDigest+" AS builder",
|
|
"FROM alpine:3.24@sha256:",
|
|
"ARG PULSE_LICENSE_PUBLIC_KEY_SHA256",
|
|
"ARG TARGETOS",
|
|
"ARG TARGETARCH",
|
|
"--mount=type=secret,id=pulse_license_public_key,required=false",
|
|
"PULSE_LICENSE_PUBLIC_KEY_SHA256 is required for control-plane release image builds.",
|
|
"PULSE_LICENSE_PUBLIC_KEY_SHA256 was provided but no license public key was mounted.",
|
|
`LICENSE_PUBLIC_KEY="$(tr -d '\r\n' < /run/secrets/pulse_license_public_key)"`,
|
|
"mounted license public key must decode to 32 bytes.",
|
|
"mounted license public key does not match PULSE_LICENSE_PUBLIC_KEY_SHA256.",
|
|
"COPY --from=frontend-builder /app/internal/api/frontend-modern/dist ./internal/api/frontend-modern/dist",
|
|
`TARGET_GOOS="${TARGETOS:-linux}"`,
|
|
`TARGET_GOARCH="${TARGETARCH:-$(go env GOARCH)}"`,
|
|
`./scripts/release_ldflags.sh server --version "${VERSION}" --build-time "${BUILD_TIME}" --git-commit "${GIT_COMMIT}" --license-public-key "${LICENSE_PUBLIC_KEY}"`,
|
|
`CGO_ENABLED=0 GOOS="${TARGET_GOOS}" GOARCH="${TARGET_GOARCH}" go build \`,
|
|
"-tags release",
|
|
"-buildvcs=false",
|
|
"-trimpath",
|
|
"-o /pulse-control-plane ./cmd/pulse-control-plane",
|
|
)
|
|
assertNotContainsAny(t, text,
|
|
"golang:1.25.7-alpine AS builder",
|
|
"FROM alpine:3.21",
|
|
"CGO_ENABLED=0 go build -o /pulse-control-plane ./cmd/pulse-control-plane",
|
|
)
|
|
assertDigestPinnedDockerStage(t, text, `FROM --platform=linux/amd64 node:24-alpine@sha256:`, ` AS frontend-builder`)
|
|
assertDigestPinnedDockerStage(t, text, `FROM --platform=$BUILDPLATFORM golang:1.26.11-alpine@sha256:`, ` AS builder`)
|
|
assertDigestPinnedDockerStage(t, text, `FROM alpine:3.24@sha256:`, ` AS control-plane-runtime-foundation`)
|
|
}
|
|
|
|
func assertContainsAll(t *testing.T, text string, required ...string) {
|
|
t.Helper()
|
|
for _, needle := range required {
|
|
if !strings.Contains(text, needle) {
|
|
t.Fatalf("missing %q in:\n%s", needle, text)
|
|
}
|
|
}
|
|
}
|
|
|
|
func assertContainsAny(t *testing.T, text string, allowed ...string) {
|
|
t.Helper()
|
|
for _, needle := range allowed {
|
|
if strings.Contains(text, needle) {
|
|
return
|
|
}
|
|
}
|
|
t.Fatalf("missing any of %q in:\n%s", allowed, text)
|
|
}
|
|
|
|
func assertNotContainsAny(t *testing.T, text string, forbidden ...string) {
|
|
t.Helper()
|
|
for _, needle := range forbidden {
|
|
if strings.Contains(text, needle) {
|
|
t.Fatalf("forbidden %q found in:\n%s", needle, text)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The unlicensed path is both a commercial boundary and the whole conversion
|
|
// path, so it is pinned here rather than left to whoever next edits setup.sh.
|
|
//
|
|
// Before this, setup.sh required a licence file and four hand-supplied image
|
|
// digests shipped as unfillable "<pin>" placeholders. That put two human
|
|
// round-trips in front of a provider's first screen, for no technical reason:
|
|
// all four images are public, and the control plane already ran unlicensed on
|
|
// the environment fallback.
|
|
func TestProviderMSPSetupScriptSupportsUnlicensedEvaluation(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := string(scriptBytes)
|
|
|
|
assertContainsAll(t, script,
|
|
"evaluation mode, 2 client workspaces",
|
|
"ensure_image_pins",
|
|
"default_image_ref",
|
|
"resolve_image_digest",
|
|
"buildx imagetools inspect",
|
|
`--format '{{json .Manifest}}'`,
|
|
`jq -r 'if type == "object" then .digest // empty else empty end'`,
|
|
`awk '$1 == "Digest:" {print $2; exit}'`,
|
|
"validate_compose_config\n pull_provider_images",
|
|
`docker pull "${image_ref}"`,
|
|
`if [[ "${current}" == *@sha256:*`,
|
|
`ref="${current}"`,
|
|
// Self-issue, and the three ways it must degrade instead of blocking.
|
|
"ensure_eval_license",
|
|
"/v1/provider-msp/eval-license",
|
|
"PULSE_PROVIDER_MSP_SKIP_EVAL_LICENSE",
|
|
"reusing existing evaluation license",
|
|
"license server rejected the evaluation request (HTTP ${http_status})",
|
|
"PULSE_PROVIDER_MSP_EVAL_EMAIL",
|
|
"PULSE_PROVIDER_MSP_SIGNUP_SOURCE",
|
|
`setup_stage: "images_ready"`,
|
|
"Plan in your provider portal shows whether a paid upgrade is available",
|
|
"keep within two clients until Plan confirms a higher active limit",
|
|
)
|
|
// A purchase route is shown only when available; setup must not claim that
|
|
// checkout is live or that the paid limit is already active.
|
|
assertNotContainsAny(t, script, "request an upgrade", "eval_license_id=", "to buy, request a licence bound", "checkout is by Stripe and the new limit applies within")
|
|
if strings.LastIndex(script, "pull_provider_images\n") > strings.LastIndex(script, "ensure_eval_license\n") {
|
|
t.Fatal("evaluation must be issued only after pinned provider images are reachable")
|
|
}
|
|
setupSequence := "validate_compose_config\n pull_provider_images\n # Issue the evaluation only after the host is configured and the immutable\n # images are reachable. This makes an issued evaluation a useful activation\n # signal rather than a record created before setup can succeed.\n ensure_eval_license\n validate_compose_config"
|
|
if !strings.Contains(script, setupSequence) {
|
|
t.Fatal("setup must validate compose, pull pinned images, issue the evaluation, then validate compose with the installed licence")
|
|
}
|
|
|
|
// The install must never abort because an evaluation licence could not be
|
|
// obtained. `|| true` inside the substitution does not achieve that: the
|
|
// derive helper calls die, and exit in a subshell is not a catchable
|
|
// status, so setup.sh would abort under set -e.
|
|
if strings.Contains(script, "$(derive_lease_signing_public_key 2>/dev/null || true)") {
|
|
t.Fatal("eval license key derivation uses `|| true` inside a command substitution, which cannot catch die/exit under set -e")
|
|
}
|
|
if !strings.Contains(script, "if ! public_key=\"$(derive_lease_signing_public_key 2>/dev/null)\"") {
|
|
t.Fatal("eval license key derivation must be guarded so a failure degrades to unlicensed rather than aborting setup")
|
|
}
|
|
|
|
// A blank licence path means evaluation. If it returns to the
|
|
// must-be-non-empty list, setup.sh refuses to start unlicensed again.
|
|
if strings.Contains(script, "CP_TRUSTED_PROXY_CIDRS CP_PROVIDER_MSP_LICENSE_FILE") {
|
|
t.Fatal("CP_PROVIDER_MSP_LICENSE_FILE is back in the required non-empty list; blank must mean evaluation")
|
|
}
|
|
|
|
envBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", ".env.example"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP env example: %v", err)
|
|
}
|
|
env := string(envBytes)
|
|
|
|
if strings.Contains(env, "<pin>") {
|
|
t.Fatal(".env.example still ships <pin> image placeholders; setup.sh resolves blank pins from published tags instead")
|
|
}
|
|
if !strings.Contains(env, "\nCP_PROVIDER_MSP_LICENSE_FILE=\n") {
|
|
t.Fatal(".env.example must ship a blank CP_PROVIDER_MSP_LICENSE_FILE so the shipped default is evaluation")
|
|
}
|
|
for _, key := range []string{"TRAEFIK_IMAGE", "DOCKER_SOCKET_PROXY_IMAGE", "CONTROL_PLANE_IMAGE", "CP_PULSE_IMAGE"} {
|
|
if !strings.Contains(env, "\n"+key+"=\n") {
|
|
t.Fatalf(".env.example must ship %s blank so setup.sh resolves its digest", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProviderMSPResolveImageDigestAcceptsManifestJSON(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := strings.Replace(string(scriptBytes), `main "$@"`, "", 1)
|
|
if script == string(scriptBytes) {
|
|
t.Fatal("provider MSP setup main invocation not found")
|
|
}
|
|
|
|
tempDir := t.TempDir()
|
|
digest := "sha256:" + strings.Repeat("a", 64)
|
|
fakeDocker := filepath.Join(tempDir, "docker")
|
|
if err := os.WriteFile(fakeDocker, []byte("#!/bin/sh\nprintf '%s\\n' '{\"digest\":\""+digest+"\"}'\n"), 0o755); err != nil {
|
|
t.Fatalf("write fake docker: %v", err)
|
|
}
|
|
runner := filepath.Join(tempDir, "resolve-image-digest.sh")
|
|
if err := os.WriteFile(runner, []byte(script+"\nresolve_image_digest example.invalid/provider:v1\n"), 0o755); err != nil {
|
|
t.Fatalf("write setup runner: %v", err)
|
|
}
|
|
|
|
cmd := exec.Command("bash", runner)
|
|
cmd.Env = append(os.Environ(), "PATH="+tempDir+":"+os.Getenv("PATH"))
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("resolve image digest: %v\n%s", err, output)
|
|
}
|
|
want := "example.invalid/provider@" + digest
|
|
if got := strings.TrimSpace(string(output)); got != want {
|
|
t.Fatalf("resolved image = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestProviderMSPEvaluationDocsUsePublishedSignedBundle(t *testing.T) {
|
|
t.Parallel()
|
|
repoDocBytes, err := os.ReadFile(repoFile("docs", "MSP.md"))
|
|
if err != nil {
|
|
t.Fatalf("read repo MSP guide: %v", err)
|
|
}
|
|
shippedDocBytes, err := os.ReadFile(repoFile("frontend-modern", "public", "docs", "MSP.md"))
|
|
if err != nil {
|
|
t.Fatalf("read shipped MSP guide: %v", err)
|
|
}
|
|
if string(repoDocBytes) != string(shippedDocBytes) {
|
|
t.Fatal("repo and shipped MSP guides must remain byte-synchronized")
|
|
}
|
|
|
|
doc := string(repoDocBytes)
|
|
assertContainsAll(t, doc,
|
|
"signed provider bundle published",
|
|
"with Pulse v6.9.0",
|
|
"**not** download the moving `main` branch archive",
|
|
`export PULSE_VERSION=v6.9.0`,
|
|
`PULSE_MSP_BUNDLE="pulse-provider-msp-${PULSE_VERSION}.tar.gz"`,
|
|
`releases/download/${PULSE_VERSION}`,
|
|
"ssh-keygen -Y verify",
|
|
// Chained, so a failed signature or checksum stops before tar or setup.
|
|
`-s "${PULSE_MSP_BUNDLE}.sshsig" < "${PULSE_MSP_BUNDLE}" &&`,
|
|
`sha256sum -c "${PULSE_MSP_BUNDLE}.sha256" &&`,
|
|
"tar -xzf \"${PULSE_MSP_BUNDLE}\" &&",
|
|
// The portal and client workspaces need both records, and the default
|
|
// DNS-01 token needs both permissions.
|
|
"`*.DOMAIN` (each client workspace",
|
|
"Zone / Zone / Read and Zone / DNS / Edit",
|
|
"The licence request omits an email address unless you export",
|
|
"`PULSE_PROVIDER_MSP_EVAL_EMAIL` before running `setup.sh`",
|
|
"address is included in the request",
|
|
"a setup-stage marker, and a signup-source",
|
|
"this is not a claim",
|
|
"that setup makes no other network requests",
|
|
// Paid plans are bought from Plan in the provider portal (v6.6.0), so
|
|
// the guide must send providers there rather than to a request form.
|
|
"open **Plan** in the provider portal",
|
|
"**Manage billing**",
|
|
"## Upgrading to a new release",
|
|
"sudo -E bash ./upgrade.sh --dry-run",
|
|
"sudo -E bash ./upgrade.sh --rollout-tenants",
|
|
"Without `--rollout-tenants`, client runtimes keep running their current",
|
|
// A v6.4.x control plane keeps stopping clients, which blocks the gate.
|
|
"(cd /opt/pulse-provider-msp && sudo docker compose stop control-plane)",
|
|
"sudo docker start $(sudo docker ps -aq --filter 'name=^pulse-t-[A-Z0-9]+$')",
|
|
"run the dry run again from\nthe extracted bundle directory",
|
|
"Scale, at 40 client workspaces, is the largest plan",
|
|
"sudo docker compose run --rm control-plane provider-msp bootstrap",
|
|
`sudo -E bash ./setup.sh`,
|
|
)
|
|
flat := strings.Join(strings.Fields(doc), " ")
|
|
for _, stale := range []string{"within seconds", "a custom licence is issued", "assisted upgrade path"} {
|
|
if strings.Contains(flat, stale) {
|
|
t.Fatalf("MSP guide still says %q", stale)
|
|
}
|
|
}
|
|
// Starting every pulse-t- container would also start retained .pre-<run> copies.
|
|
if strings.Contains(doc, "--filter 'name=^pulse-t-')") {
|
|
t.Fatal("MSP guide starts retained pre-rollout runtime copies")
|
|
}
|
|
assertNotContainsAny(t, doc,
|
|
// v6.8.0 setup asks up front and needs no traefik.yml edit.
|
|
"admin@example.com",
|
|
"pauses for",
|
|
"Bundles newer than",
|
|
"Pulse/archive/refs/heads/main.tar.gz",
|
|
"evaluation request is anonymous",
|
|
"assisted upgrade path",
|
|
"Send the derived public key",
|
|
"msp.html#evaluate",
|
|
"a custom licence is issued",
|
|
"credentials never leave the",
|
|
"cd Pulse-main/deploy/provider-msp",
|
|
"sudo -E ./setup.sh",
|
|
)
|
|
}
|
|
|
|
// Traefik terminates TLS at the internet edge. Handing it the whole operator
|
|
// .env put CP_ADMIN_KEY and the entitlement signing private key one edge CVE
|
|
// away from disclosure, so the compose contract pins the minimal wiring: only
|
|
// ACME/DNS material reaches the traefik container, and the DNS-01 provider is
|
|
// overridable for operators whose DNS is not on Cloudflare.
|
|
func TestProviderMSPTraefikEnvIsMinimalAndDNSProviderOverridable(t *testing.T) {
|
|
t.Parallel()
|
|
composeBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "docker-compose.yml"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP compose: %v", err)
|
|
}
|
|
var compose struct {
|
|
Services map[string]struct {
|
|
EnvFile any `yaml:"env_file"`
|
|
} `yaml:"services"`
|
|
}
|
|
if err := yaml.Unmarshal(composeBytes, &compose); err != nil {
|
|
t.Fatalf("provider MSP compose must be valid YAML: %v", err)
|
|
}
|
|
traefik, ok := compose.Services["traefik"]
|
|
if !ok {
|
|
t.Fatal("compose must define a traefik service")
|
|
}
|
|
var envFiles []string
|
|
switch v := traefik.EnvFile.(type) {
|
|
case nil:
|
|
case string:
|
|
envFiles = append(envFiles, v)
|
|
case []any:
|
|
for _, entry := range v {
|
|
switch e := entry.(type) {
|
|
case string:
|
|
envFiles = append(envFiles, e)
|
|
case map[string]any:
|
|
if p, _ := e["path"].(string); p != "" {
|
|
envFiles = append(envFiles, p)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, f := range envFiles {
|
|
if strings.HasSuffix(f, ".env") && !strings.HasSuffix(f, "dns-credentials.env") {
|
|
t.Fatalf("traefik env_file %q would leak the operator .env (CP_ADMIN_KEY, entitlement signing key) into the edge container", f)
|
|
}
|
|
}
|
|
|
|
text := string(composeBytes)
|
|
assertContainsAll(t, text,
|
|
"--certificatesresolvers.letsencrypt.acme.${ACME_CHALLENGE_SETTING_1:-dnschallenge.provider=${ACME_DNS_PROVIDER:-cloudflare}}",
|
|
"--certificatesresolvers.le.acme.${ACME_CHALLENGE_SETTING_1:-dnschallenge.provider=${ACME_DNS_PROVIDER:-cloudflare}}",
|
|
"CF_DNS_API_TOKEN=${CF_DNS_API_TOKEN:-}",
|
|
"path: ./dns-credentials.env",
|
|
"required: false",
|
|
)
|
|
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
assertContainsAll(t, string(scriptBytes),
|
|
"ensure_dns_credentials_file",
|
|
"CF_DNS_API_TOKEN is required with the default ACME_DNS_PROVIDER=cloudflare",
|
|
"put that provider's credential variables in",
|
|
)
|
|
// CF_DNS_API_TOKEN must not return to the unconditional required list; it
|
|
// is only required when ACME_DNS_PROVIDER resolves to cloudflare.
|
|
if strings.Contains(string(scriptBytes), "ACME_EMAIL CF_DNS_API_TOKEN CP_ENV") {
|
|
t.Fatal("CF_DNS_API_TOKEN is back in the unconditional required-env list; it must be required only when ACME_DNS_PROVIDER is cloudflare")
|
|
}
|
|
}
|
|
|
|
// setup.sh used to finish at "setup prepared" without starting the control
|
|
// plane, so the bootstrap sign-in link it printed as the next step answered
|
|
// 404 until the install proof or a manual compose up happened to start it.
|
|
// Setup must bring the provider services up after the final compose
|
|
// validation, wait for the control plane, and only then run the optional
|
|
// install proof and print the summary.
|
|
func TestProviderMSPSetupLeavesPlatformRunning(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := string(scriptBytes)
|
|
|
|
assertContainsAll(t, script,
|
|
"start_provider_services() {",
|
|
"docker compose up -d traefik docker-socket-proxy control-plane",
|
|
"docker compose ps --services --status running",
|
|
"grep -qx control-plane",
|
|
"control plane did not reach running state",
|
|
"Pulse Provider MSP is running.",
|
|
)
|
|
assertNotContainsAny(t, script, "Pulse Provider MSP setup prepared.")
|
|
|
|
// The closing summary points at the actual licence status in Plan, not
|
|
// portal readiness, without claiming checkout is live or asking the
|
|
// provider to carry a lease signing key to anyone. Ignore prose wrapping.
|
|
summary := script[strings.Index(script, "Pulse Provider MSP is running."):]
|
|
summary = summary[:strings.Index(summary, "EOF")]
|
|
assertContainsAll(t, strings.Join(strings.Fields(summary), " "),
|
|
"check Plan in the portal for this deployment's licence status",
|
|
"A successfully issued evaluation covers two clients",
|
|
"a running portal alone does not confirm active client MSP capabilities",
|
|
"Keep within two clients until Plan confirms a higher active limit",
|
|
"Manage billing",
|
|
)
|
|
assertNotContainsAny(t, summary, "Plan: the evaluation covers two clients", "must bind this key", "derive_lease_signing_public_key", "checkout is by Stripe", "applies within\nseconds")
|
|
|
|
sequence := " ensure_eval_license\n validate_compose_config\n start_provider_services\n check_portal_readiness\n run_install_proof_if_requested\n print_summary\n"
|
|
if !strings.Contains(script, sequence) {
|
|
t.Fatal("setup must start provider services after the licensed compose validation and before the install proof and summary")
|
|
}
|
|
|
|
// The first-run prompt names only what a provider must supply.
|
|
first := script[strings.Index(script, "Edit it now and set"):]
|
|
first = first[:strings.Index(first, "EOF")]
|
|
for _, generatedOrDefaulted := range []string{"TRAEFIK_IMAGE", "CP_PULSE_IMAGE", "PULSE_PROVIDER_MSP_DOCKER_SUBNET", "CP_TRUSTED_PROXY_CIDRS"} {
|
|
if strings.Contains(first, " - "+generatedOrDefaulted) {
|
|
t.Fatalf("first-run prompt still lists %s as a value the provider must set", generatedOrDefaulted)
|
|
}
|
|
}
|
|
assertContainsAll(t, first, "DOMAIN", "ACME_EMAIL", "CF_DNS_API_TOKEN")
|
|
}
|
|
|
|
// Setup used to stop after installing Docker and ask the provider to edit a
|
|
// root-only .env from a second session. It now asks for the three values a
|
|
// provider must supply before installing anything, keeps the token off the
|
|
// screen, accepts them from the environment for unattended runs, names the
|
|
// two DNS records the certificate needs, and prints day-2 commands with sudo
|
|
// because .env is readable by root only.
|
|
func TestProviderMSPSetupAsksForFirstRunValuesUpFront(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := string(scriptBytes)
|
|
|
|
if !strings.Contains(script, " collect_first_run_values\n apt_install apt-transport-https\n") {
|
|
t.Fatal("setup must collect first-run values before installing packages")
|
|
}
|
|
assertContainsAll(t, script,
|
|
`PULSE_PROVIDER_MSP_DOMAIN="${PULSE_PROVIDER_MSP_DOMAIN:-}"`,
|
|
`PULSE_PROVIDER_MSP_ACME_EMAIL="${PULSE_PROVIDER_MSP_ACME_EMAIL:-}"`,
|
|
`PULSE_PROVIDER_MSP_CF_DNS_API_TOKEN="${PULSE_PROVIDER_MSP_CF_DNS_API_TOKEN:-}"`,
|
|
`read -r -s -p "Cloudflare API token`,
|
|
`read -r -p "Domain, e.g. pulse.example.com (Enter for a trial address): "`,
|
|
`[[ -f "${PULSE_PROVIDER_MSP_INSTALL_DIR}/.env" ]] && return 0`,
|
|
`die "${key} is not valid; check it and run setup.sh again"`,
|
|
`(umask 077 && cp -n "${PULSE_PROVIDER_MSP_INSTALL_DIR}/.env.example" "${env_path}")`,
|
|
`set_env_value "${key}" "${!var}" "${env_path}"`,
|
|
" ${PULSE_PROVIDER_MSP_DOMAIN} the portal",
|
|
" *.${PULSE_PROVIDER_MSP_DOMAIN} one address per client",
|
|
)
|
|
// Values reach .env unquoted, so the token pattern must exclude every
|
|
// character compose or awk -v would interpret.
|
|
assertContainsAll(t, script, `local token_re='^[A-Za-z0-9_.+/=-]{20,255}$'`)
|
|
|
|
summary := script[strings.Index(script, "Pulse Provider MSP is running."):]
|
|
summary = summary[:strings.Index(summary, "EOF")]
|
|
assertContainsAll(t, summary,
|
|
" sudo docker compose run --rm control-plane provider-msp bootstrap",
|
|
" sudo ./run-install-proof.sh",
|
|
" sudo docker compose run --rm control-plane provider-msp portal-link",
|
|
"choose Add client, and follow Install agents",
|
|
)
|
|
assertNotContainsAny(t, summary, "\n docker compose run", "\n ./run-install-proof.sh")
|
|
}
|
|
|
|
// On a fresh host setup printed "Pulse Provider MSP is running." while the
|
|
// portal refused every TLS handshake: Let's Encrypt had rejected the ACME
|
|
// email, Traefik had no certificate, and sniStrict left the browser with only
|
|
// a handshake error. Setup now waits for the wildcard certificate, checks the
|
|
// two DNS records, and names the fix in the provider's terms.
|
|
func TestProviderMSPSetupReportsPortalReadiness(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := string(scriptBytes)
|
|
|
|
assertContainsAll(t, script,
|
|
`PULSE_PROVIDER_MSP_CERT_WAIT_SECONDS="${PULSE_PROVIDER_MSP_CERT_WAIT_SECONDS:-180}"`,
|
|
`openssl s_client -connect 127.0.0.1:443 -servername "${domain}"`,
|
|
`-verify_return_error -verify_hostname "${domain}"`,
|
|
`grep -qxF "${required_san}"`,
|
|
`required_san="DNS:*.${domain}"`,
|
|
`required_san="DNS:${domain}"`,
|
|
"Certificate: verified on this host",
|
|
`grep -F "Unable to obtain ACME certificate"`,
|
|
`for name in "${domain}" "pulse-dns-check.${domain}"; do`,
|
|
`timeout 10 getent ahostsv4 "${name}"`,
|
|
"sudo docker compose up -d --force-recreate traefik control-plane",
|
|
)
|
|
explain := script[strings.Index(script, "explain_acme_failure() {"):]
|
|
explain = explain[:strings.Index(explain, "\n}\n")]
|
|
assertContainsAll(t, explain,
|
|
"*invalidContact*", "Let's Encrypt refused ACME_EMAIL",
|
|
"*[Cc]loudflare*", "Zone / Zone / Read and Zone / DNS / Edit",
|
|
"*rateLimited*",
|
|
`*"Timeout during connect"*`, "could not reach port 80",
|
|
`*"too many certificates"*sslip.io*`, "Everyone using sslip.io or nip.io shares it",
|
|
`*"too many failed authorizations"*`, "it allows 5 an hour",
|
|
)
|
|
// The report is printed when it is made, so a failing install proof
|
|
// cannot hide it, and again in the closing summary.
|
|
check := script[strings.Index(script, "check_portal_readiness() {"):]
|
|
check = check[:strings.Index(check, "\n}\n")]
|
|
if !strings.Contains(check, `printf '\n%s\n\n' "${PORTAL_READINESS_REPORT}"`) {
|
|
t.Fatal("readiness report must be printed before the install proof runs")
|
|
}
|
|
summary := script[strings.Index(script, "Pulse Provider MSP is running."):]
|
|
summary = summary[:strings.Index(summary, "EOF")]
|
|
assertContainsAll(t, summary, "${PORTAL_READINESS_REPORT}")
|
|
}
|
|
|
|
// Trying Pulse MSP should not need a domain or a DNS token. With a domain and no
|
|
// token each client gets its own certificate over port 80. With neither, setup
|
|
// builds a shared trial address from the host's public IP, and that address is
|
|
// labelled trial-only because moving off it means reinstalling every agent.
|
|
func TestProviderMSPSetupOffersCertificatesWithoutADNSToken(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP setup: %v", err)
|
|
}
|
|
script := string(scriptBytes)
|
|
assertContainsAll(t, script,
|
|
`set_env_value ACME_CHALLENGE_SETTING_1 "httpchallenge=true"`,
|
|
`set_env_value ACME_CHALLENGE_SETTING_2 "httpchallenge.entrypoint=web"`,
|
|
`set_env_value CP_PER_CLIENT_CERTIFICATES "true"`,
|
|
`set_env_value PROVIDER_MSP_TRIAL_ADDRESS "true"`,
|
|
`trial_address "${ip}" sslip.io`,
|
|
"A trial address is for evaluation only. Moving to your own domain later",
|
|
"TRIAL ONLY:",
|
|
"moving to your own domain later means reinstalling every agent",
|
|
)
|
|
// An existing .env is the operator's: only a first run may rename the address.
|
|
if !strings.Contains(script, `[[ "${FIRST_RUN_ENV_CREATED}" -eq 1 ]] || return 0`) {
|
|
t.Fatal("setup must not rename the trial address on an install that may have clients")
|
|
}
|
|
|
|
composeBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "docker-compose.yml"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP compose: %v", err)
|
|
}
|
|
assertContainsAll(t, string(composeBytes),
|
|
"${ACME_CHALLENGE_SETTING_2:-dnschallenge.resolvers=1.1.1.1:53,8.8.8.8:53}",
|
|
"${PORTAL_CERTIFICATE_SANS_LABEL:-traefik.http.routers.provider-control-plane.tls.domains[0].sans=*.${DOMAIN}}",
|
|
"CP_PER_CLIENT_CERTIFICATES=${CP_PER_CLIENT_CERTIFICATES:-false}",
|
|
)
|
|
|
|
envBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", ".env.example"))
|
|
if err != nil {
|
|
t.Fatalf("read provider MSP env example: %v", err)
|
|
}
|
|
// Blank settings keep DNS-01 and the wildcard, so existing installs and the
|
|
// paid path are unchanged unless setup or the operator opts in.
|
|
assertContainsAll(t, string(envBytes),
|
|
"\nACME_CHALLENGE_SETTING_1=\n",
|
|
"\nACME_CHALLENGE_SETTING_2=\n",
|
|
"\nPORTAL_CERTIFICATE_SANS_LABEL=\n",
|
|
"\nCP_PER_CLIENT_CERTIFICATES=false\n",
|
|
"\nPROVIDER_MSP_TRIAL_ADDRESS=false\n",
|
|
)
|
|
}
|
|
|
|
// Setup pins the images in .env to digests once, so an upgrade used to re-pull
|
|
// only the release a provider first installed. Run from a newly extracted
|
|
// bundle, upgrade.sh must install that bundle into the existing install,
|
|
// re-pin the two Pulse images to the bundle's release, keep a copy of the old
|
|
// .env, and only then hand over to the backup-gated flow.
|
|
func TestProviderMSPUpgradeFromBundleRepinsToTheBundleRelease(t *testing.T) {
|
|
t.Parallel()
|
|
newDigest := "sha256:" + strings.Repeat("b", 64)
|
|
oldControlPlane := "ghcr.io/rcourtman/pulse-control-plane@sha256:" + strings.Repeat("a", 64)
|
|
oldRuntime := "ghcr.io/rcourtman/pulse@sha256:" + strings.Repeat("a", 64)
|
|
|
|
setup := func(t *testing.T) (bundle, install, dockerLog string) {
|
|
t.Helper()
|
|
root := t.TempDir()
|
|
bundle = filepath.Join(root, "pulse-provider-msp-v6.6.0")
|
|
install = filepath.Join(root, "install")
|
|
bin := filepath.Join(root, "bin")
|
|
for _, dir := range []string{bundle, install, bin} {
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
for _, name := range []string{"docker-compose.yml", "traefik-dynamic.yml", ".env.example", "run-install-proof.sh", "upgrade.sh", "setup.sh"} {
|
|
content, err := os.ReadFile(repoFile("deploy", "provider-msp", name))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if name == ".env.example" {
|
|
// What scripts/build-release.sh stamps into a release bundle.
|
|
text := strings.Replace(string(content), "\nCONTROL_PLANE_IMAGE=\n", "\nCONTROL_PLANE_IMAGE=ghcr.io/rcourtman/pulse-control-plane:v6.6.0\n", 1)
|
|
text = strings.Replace(text, "\nCP_PULSE_IMAGE=\n", "\nCP_PULSE_IMAGE=ghcr.io/rcourtman/pulse:v6.6.0\n", 1)
|
|
content = []byte(text)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(bundle, name), content, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := os.WriteFile(filepath.Join(bundle, "VERSION"), []byte("6.6.0\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
env := "DOMAIN=msp.example.com\nCONTROL_PLANE_IMAGE=" + oldControlPlane + "\nCP_PULSE_IMAGE=" + oldRuntime + "\nPULSE_PROVIDER_MSP_DATA_DIR=/data\n"
|
|
if err := os.WriteFile(filepath.Join(install, ".env"), []byte(env), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(install, "upgrade.sh"), []byte("#!/bin/sh\necho old-upgrade-script\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dockerLog = filepath.Join(root, "docker.log")
|
|
// Log each call with the control-plane pin in .env and the image
|
|
// compose would use (a shell value wins over .env) at that moment.
|
|
fake := "#!/bin/sh\nfile=$(grep '^CONTROL_PLANE_IMAGE=' .env 2>/dev/null | cut -d= -f2)\n" +
|
|
"echo \"$* [env=${file}] [uses=${CONTROL_PLANE_IMAGE:-$file}]\" >> " + dockerLog + "\n" +
|
|
"case \"$*\" in\n" +
|
|
" 'buildx imagetools inspect '*' --format '*) echo '{\"digest\":\"" + newDigest + "\"}' ;;\n" +
|
|
" 'buildx imagetools inspect '*) echo 'Digest: " + newDigest + "' ;;\n" +
|
|
" *'backup create'*) echo 'archive_path=/data/backups/pre-upgrade.tar.gz' ;;\n" +
|
|
"esac\nexit 0\n"
|
|
if err := os.WriteFile(filepath.Join(bin, "docker"), []byte(fake), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return bundle, install, dockerLog
|
|
}
|
|
run := func(t *testing.T, bundle, install string, args ...string) string {
|
|
t.Helper()
|
|
cmd := exec.Command("bash", append([]string{filepath.Join(bundle, "upgrade.sh")}, args...)...)
|
|
cmd.Env = append(os.Environ(), "PATH="+filepath.Join(filepath.Dir(bundle), "bin")+":"+os.Getenv("PATH"), "PULSE_PROVIDER_MSP_INSTALL_DIR="+install)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("upgrade.sh %v: %v\n%s", args, err, output)
|
|
}
|
|
return string(output)
|
|
}
|
|
envOf := func(t *testing.T, install string) string {
|
|
t.Helper()
|
|
b, err := os.ReadFile(filepath.Join(install, ".env"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
t.Run("upgrade", func(t *testing.T) {
|
|
bundle, install, dockerLog := setup(t)
|
|
output := run(t, bundle, install)
|
|
env := envOf(t, install)
|
|
for _, want := range []string{
|
|
"CONTROL_PLANE_IMAGE=ghcr.io/rcourtman/pulse-control-plane@" + newDigest,
|
|
"CP_PULSE_IMAGE=ghcr.io/rcourtman/pulse@" + newDigest,
|
|
"DOMAIN=msp.example.com",
|
|
} {
|
|
if !strings.Contains(env, want) {
|
|
t.Fatalf("upgraded .env lacks %q:\n%s", want, env)
|
|
}
|
|
}
|
|
backups, _ := filepath.Glob(filepath.Join(install, ".env.pre-upgrade-*"))
|
|
if len(backups) != 1 {
|
|
t.Fatalf("pre-upgrade .env copies = %v, want one", backups)
|
|
}
|
|
if old, _ := os.ReadFile(backups[0]); !strings.Contains(string(old), oldControlPlane) {
|
|
t.Fatal("pre-upgrade copy does not hold the previous pins")
|
|
}
|
|
installed, _ := os.ReadFile(filepath.Join(install, "upgrade.sh"))
|
|
shipped, _ := os.ReadFile(filepath.Join(bundle, "upgrade.sh"))
|
|
if string(installed) != string(shipped) {
|
|
t.Fatal("bundle upgrade.sh was not installed")
|
|
}
|
|
logBytes, _ := os.ReadFile(dockerLog)
|
|
lines := strings.Split(string(logBytes), "\n")
|
|
lineWith := func(needle string) string {
|
|
for _, line := range lines {
|
|
if strings.Contains(line, needle) {
|
|
return line
|
|
}
|
|
}
|
|
t.Fatalf("docker was never called with %q:\n%s", needle, logBytes)
|
|
return ""
|
|
}
|
|
// The check and the backup run the new release's control plane as a
|
|
// one-off while .env still holds the old pins; .env changes only
|
|
// before the new images start.
|
|
newControlPlane := "ghcr.io/rcourtman/pulse-control-plane@" + newDigest
|
|
for _, step := range []string{"control-plane provider-msp status", "provider-msp backup create"} {
|
|
line := lineWith(step)
|
|
if !strings.Contains(line, "[env="+oldControlPlane+"]") || !strings.Contains(line, "[uses="+newControlPlane+"]") {
|
|
t.Fatalf("%s should run the new control plane with .env untouched: %s", step, line)
|
|
}
|
|
}
|
|
// The new runtime image is pulled before status checks it is present.
|
|
pull := strings.Index(string(logBytes), "pull ghcr.io/rcourtman/pulse@"+newDigest)
|
|
status := strings.Index(string(logBytes), "control-plane provider-msp status")
|
|
if pull < 0 || status < 0 || pull > status {
|
|
t.Fatalf("the new tenant runtime image must be pulled before the status gate:\n%s", logBytes)
|
|
}
|
|
if line := lineWith("compose up -d traefik docker-socket-proxy control-plane"); !strings.Contains(line, "[env="+newControlPlane+"]") {
|
|
t.Fatalf("new images did not start on the new pins: %s", line)
|
|
}
|
|
if !strings.Contains(output, "provider_msp_upgrade_ok=true") || !strings.Contains(output, "provider_msp_upgrade_bundle_version=6.6.0") {
|
|
t.Fatalf("upgrade output:\n%s", output)
|
|
}
|
|
})
|
|
|
|
t.Run("keep image pins", func(t *testing.T) {
|
|
bundle, install, _ := setup(t)
|
|
run(t, bundle, install, "--keep-image-pins")
|
|
env := envOf(t, install)
|
|
if !strings.Contains(env, "CONTROL_PLANE_IMAGE="+oldControlPlane) || !strings.Contains(env, "CP_PULSE_IMAGE="+oldRuntime) {
|
|
t.Fatalf("--keep-image-pins changed the pins:\n%s", env)
|
|
}
|
|
})
|
|
|
|
t.Run("dry run changes nothing", func(t *testing.T) {
|
|
bundle, install, _ := setup(t)
|
|
output := run(t, bundle, install, "--dry-run")
|
|
if env := envOf(t, install); !strings.Contains(env, "CONTROL_PLANE_IMAGE="+oldControlPlane) {
|
|
t.Fatalf("dry run changed .env:\n%s", env)
|
|
}
|
|
if installed, _ := os.ReadFile(filepath.Join(install, "upgrade.sh")); string(installed) != "#!/bin/sh\necho old-upgrade-script\n" {
|
|
t.Fatal("dry run installed bundle files")
|
|
}
|
|
if !strings.Contains(output, "current="+oldControlPlane) || !strings.Contains(output, "target=ghcr.io/rcourtman/pulse-control-plane@"+newDigest) {
|
|
t.Fatalf("dry run did not print the pin plan:\n%s", output)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestProviderMSPEvaluationFallbackUsesTheSameFinalComposeConfig(t *testing.T) {
|
|
t.Parallel()
|
|
scriptBytes, err := os.ReadFile(repoFile("deploy", "provider-msp", "setup.sh"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
script := string(scriptBytes)
|
|
const entry = "\nmain \"$@\"\n"
|
|
if !strings.HasSuffix(script, entry) {
|
|
t.Fatal("cannot safely remove the installer entrypoint from the shell fixture")
|
|
}
|
|
for _, skip := range []string{"1", "0"} {
|
|
t.Run("skip="+skip, func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := "CP_PROVIDER_MSP_LICENSE_FILE=\n"
|
|
if err := os.WriteFile(filepath.Join(dir, ".env"), []byte(env), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// No installer, package manager, Docker daemon or licence service.
|
|
// Only the actual best-effort and validation functions execute.
|
|
fixture := strings.TrimSuffix(script, entry) + `
|
|
|
|
derive_lease_signing_public_key() { printf 'synthetic-public-key'; }
|
|
jq() { printf '{}'; }
|
|
curl() { return 7; }
|
|
docker() {
|
|
[[ "$#" == 3 && "$1" == compose && "$2" == config && "$3" == --quiet ]] || exit 81
|
|
[[ ! -v CP_PROVIDER_MSP_LICENSE_FILE ]] || exit 82
|
|
printf 'same-compose-config\n'
|
|
}
|
|
validate_compose_config
|
|
ensure_eval_license
|
|
validate_compose_config
|
|
`
|
|
cmd := exec.Command("bash", "-c", fixture)
|
|
cmd.Env = []string{"PATH=" + os.Getenv("PATH"), "PULSE_PROVIDER_MSP_INSTALL_DIR=" + dir, "PULSE_PROVIDER_MSP_SKIP_EVAL_LICENSE=" + skip}
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("best-effort evaluation must reach final validation: %v\n%s", err, output)
|
|
}
|
|
if strings.Count(string(output), "same-compose-config\n") != 2 {
|
|
t.Fatalf("pre/final validation did not both use the same config: %s", output)
|
|
}
|
|
if skip == "0" && !strings.Contains(string(output), "evaluation license request failed (curl exit 7)") {
|
|
t.Fatal("fixture did not exercise unavailable licence issuance")
|
|
}
|
|
after, err := os.ReadFile(filepath.Join(dir, ".env"))
|
|
if err != nil || string(after) != env {
|
|
t.Fatal("fallback changed the blank operator licence selection")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// The control plane gives Traefik the portal's name on a client's network only when
|
|
// the runtime image declares this label, so losing it would quietly send renewal back
|
|
// over the host. The guide states which runtimes need a public address.
|
|
func TestProviderMSPRuntimeImageDeclaresPrivateLeaseRenewal(t *testing.T) {
|
|
t.Parallel()
|
|
dockerfile, err := os.ReadFile(repoFile("Dockerfile"))
|
|
if err != nil {
|
|
t.Fatalf("read Dockerfile: %v", err)
|
|
}
|
|
assertContainsAll(t, string(dockerfile), `LABEL pulse.runtime.private-lease-renewal="true"`)
|
|
for _, path := range [][]string{{"docs", "MSP.md"}, {"frontend-modern", "public", "docs", "MSP.md"}} {
|
|
guide, err := os.ReadFile(repoFile(path...))
|
|
if err != nil {
|
|
t.Fatalf("read %v: %v", path, err)
|
|
}
|
|
assertContainsAll(t, strings.Join(strings.Fields(string(guide)), " "),
|
|
"falls back to Community behaviour",
|
|
"`DOMAIN` must be a public address",
|
|
"upgrade.sh --rollout-tenants",
|
|
)
|
|
}
|
|
}
|