Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
license: add dual-key verification
rcourtmanf810a003ebb2
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.ymlindex 21785469f7..97e18ee1a6 100644--- a/.github/workflows/create-release.yml+++ b/.github/workflows/create-release.yml@@ -184,6 +184,7 @@ jobs:cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/pulse:buildcache,mode=maxbuild-args: |PULSE_LICENSE_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}VERSION=${{ needs.extract_version.outputs.tag }}tags: |ghcr.io/${{ github.repository_owner }}/pulse:staging-${{ needs.extract_version.outputs.tag }}@@ -201,6 +202,7 @@ jobs:cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/pulse-docker-agent:buildcache,mode=maxbuild-args: |PULSE_LICENSE_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}VERSION=${{ needs.extract_version.outputs.tag }}tags: |ghcr.io/${{ github.repository_owner }}/pulse-docker-agent:staging-${{ needs.extract_version.outputs.tag }}@@ -208,9 +210,10 @@ jobs:- name: Build Docker images for integration testsrun: |docker build -t pulse-mock-github:test tests/integration/mock-github-server- docker build -t pulse:test -f Dockerfile --target runtime --cache-from ghcr.io/${{ github.repository_owner }}/pulse:buildcache --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg VERSION="${{ needs.extract_version.outputs.tag }}" .+ docker build -t pulse:test -f Dockerfile --target runtime --cache-from ghcr.io/${{ github.repository_owner }}/pulse:buildcache --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg PULSE_LICENSE_LEGACY_PUBLIC_KEY="$PULSE_LICENSE_LEGACY_PUBLIC_KEY" --build-arg VERSION="${{ needs.extract_version.outputs.tag }}" .env:PULSE_LICENSE_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}- name: Run update integration smoke testsworking-directory: tests/integration@@ -317,6 +320,7 @@ jobs:./scripts/build-release.sh ${{ needs.extract_version.outputs.version }}env:PULSE_LICENSE_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}- name: Post-build health checkrun: |diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.ymlindex fc534018c6..41ae78947b 100644--- a/.github/workflows/publish-docker.yml+++ b/.github/workflows/publish-docker.yml@@ -77,6 +77,7 @@ jobs:cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/pulse:buildcachebuild-args: |PULSE_LICENSE_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}VERSION=${{ steps.version.outputs.tag }}tags: |rcourtman/pulse:${{ steps.version.outputs.tag }}@@ -98,6 +99,7 @@ jobs:cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/pulse-docker-agent:buildcachebuild-args: |PULSE_LICENSE_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY=${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}VERSION=${{ steps.version.outputs.tag }}tags: |rcourtman/pulse-docker-agent:${{ steps.version.outputs.tag }}diff --git a/.github/workflows/release-dry-run.yml b/.github/workflows/release-dry-run.ymlindex f847ee19fe..043fa58efa 100644--- a/.github/workflows/release-dry-run.yml+++ b/.github/workflows/release-dry-run.yml@@ -78,9 +78,10 @@ jobs:run: |VERSION="v$(cat VERSION | tr -d '\n')"docker build -t pulse-mock-github:test tests/integration/mock-github-server- docker build -t pulse:test -f Dockerfile --target runtime --cache-from ghcr.io/${{ github.repository_owner }}/pulse:buildcache --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg VERSION="$VERSION" .+ docker build -t pulse:test -f Dockerfile --target runtime --cache-from ghcr.io/${{ github.repository_owner }}/pulse:buildcache --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg PULSE_LICENSE_LEGACY_PUBLIC_KEY="$PULSE_LICENSE_LEGACY_PUBLIC_KEY" --build-arg VERSION="$VERSION" .env:PULSE_LICENSE_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}- name: Run integration diagnosticsworking-directory: tests/integrationdiff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.ymlindex 81a7ceeeba..cb6cf7d176 100644--- a/.github/workflows/test-e2e.yml+++ b/.github/workflows/test-e2e.yml@@ -53,9 +53,10 @@ jobs:- name: Build Docker images for test environmentrun: |docker build -t pulse-mock-github:test ./tests/integration/mock-github-server- docker build -t pulse:test -f Dockerfile --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" .+ docker build -t pulse:test -f Dockerfile --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg PULSE_LICENSE_LEGACY_PUBLIC_KEY="$PULSE_LICENSE_LEGACY_PUBLIC_KEY" .env:PULSE_LICENSE_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}- name: Start test containersworking-directory: tests/integrationdiff --git a/.github/workflows/test-updates.yml b/.github/workflows/test-updates.ymlindex f6391d383d..f673c723f6 100644--- a/.github/workflows/test-updates.yml+++ b/.github/workflows/test-updates.yml@@ -70,9 +70,10 @@ jobs:# Build Pulse test imagecd ../../- docker build -t pulse:test -f Dockerfile --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" .+ docker build -t pulse:test -f Dockerfile --build-arg PULSE_LICENSE_PUBLIC_KEY="$PULSE_LICENSE_PUBLIC_KEY" --build-arg PULSE_LICENSE_LEGACY_PUBLIC_KEY="$PULSE_LICENSE_LEGACY_PUBLIC_KEY" .env:PULSE_LICENSE_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}+ PULSE_LICENSE_LEGACY_PUBLIC_KEY: ${{ secrets.PULSE_LICENSE_LEGACY_PUBLIC_KEY }}- name: Run diagnostic smoke testworking-directory: tests/integrationdiff --git a/Dockerfile b/Dockerfileindex 11bc342eea..960c9e3c8c 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,6 +1,7 @@# syntax=docker/dockerfile:1.7-labsARG BUILD_AGENT=1ARG PULSE_LICENSE_PUBLIC_KEY+ARG PULSE_LICENSE_LEGACY_PUBLIC_KEY# Build stage for frontend (must be built first for embedding)# Force amd64 platform to avoid slow QEMU emulation during multi-arch builds@@ -27,6 +28,7 @@ FROM --platform=linux/amd64 golang:1.24-alpine AS backend-builderARG BUILD_AGENTARG PULSE_LICENSE_PUBLIC_KEY+ARG PULSE_LICENSE_LEGACY_PUBLIC_KEYARG VERSIONWORKDIR /app@@ -59,6 +61,9 @@ RUN --mount=type=cache,id=pulse-go-mod,target=/go/pkg/mod \if [ -n "${PULSE_LICENSE_PUBLIC_KEY}" ]; then \LICENSE_LDFLAGS="-X github.com/rcourtman/pulse-go-rewrite/internal/license.EmbeddedPublicKey=${PULSE_LICENSE_PUBLIC_KEY}"; \fi && \+ if [ -n "${PULSE_LICENSE_LEGACY_PUBLIC_KEY}" ]; then \+ LICENSE_LDFLAGS="${LICENSE_LDFLAGS} -X github.com/rcourtman/pulse-go-rewrite/internal/license.EmbeddedLegacyPublicKey=${PULSE_LICENSE_LEGACY_PUBLIC_KEY}"; \+ fi && \CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \-ldflags="-s -w -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME} -X main.GitCommit=${GIT_COMMIT} -X github.com/rcourtman/pulse-go-rewrite/internal/dockeragent.Version=${VERSION} ${LICENSE_LDFLAGS}" \-trimpath \diff --git a/internal/license/license.go b/internal/license/license.goindex 0dbdfa84b7..2e7aab14e6 100644--- a/internal/license/license.go+++ b/internal/license/license.go@@ -427,10 +427,24 @@ func ValidateLicense(licenseKey string) (*License, error) {// Verify signature// In production, public key MUST be set. In dev mode, we skip signature validation.+ // Dual-key support: try primary key first, then legacy key for old licenses.devMode := os.Getenv("PULSE_LICENSE_DEV_MODE") == "true"- if len(publicKey) > 0 {- signedData := []byte(parts[0] + "." + parts[1])- if !ed25519.Verify(publicKey, signedData, signature) {+ signedData := []byte(parts[0] + "." + parts[1])++ if len(publicKey) > 0 || len(legacyPublicKey) > 0 {+ verified := false++ // Try primary key first (new licenses)+ if len(publicKey) > 0 && ed25519.Verify(publicKey, signedData, signature) {+ verified = true+ }++ // Fall back to legacy key (old licenses signed before key rotation)+ if !verified && len(legacyPublicKey) > 0 && ed25519.Verify(legacyPublicKey, signedData, signature) {+ verified = true+ }++ if !verified {return nil, ErrSignatureInvalid}} else if !devMode {diff --git a/internal/license/license_test.go b/internal/license/license_test.goindex fddcb179d3..30c54a6d81 100644--- a/internal/license/license_test.go+++ b/internal/license/license_test.go@@ -727,3 +727,113 @@ func TestValidateLicense_RealSignature(t *testing.T) {t.Error("Expected error for invalid signature")}}++func TestValidateLicense_DualKeyVerification(t *testing.T) {+ // Generate two key pairs: "new" primary key and "old" legacy key+ newPub, newPriv, _ := ed25519.GenerateKey(nil)+ oldPub, oldPriv, _ := ed25519.GenerateKey(nil)++ os.Setenv("PULSE_LICENSE_DEV_MODE", "false")+ defer os.Setenv("PULSE_LICENSE_DEV_MODE", "true")++ // Helper to create a signed license token+ createSignedToken := func(priv ed25519.PrivateKey, email string) string {+ claims := Claims{+ LicenseID: "test-dual-key",+ Email: email,+ Tier: TierPro,+ IssuedAt: time.Now().Unix(),+ ExpiresAt: time.Now().Add(30 * 24 * time.Hour).Unix(),+ }+ header := base64.RawURLEncoding.EncodeToString([]byte(`{"alg":"EdDSA","typ":"JWT"}`))+ payloadBytes, _ := json.Marshal(claims)+ payload := base64.RawURLEncoding.EncodeToString(payloadBytes)+ signedData := header + "." + payload+ signature := ed25519.Sign(priv, []byte(signedData))+ return signedData + "." + base64.RawURLEncoding.EncodeToString(signature)+ }++ newKeyToken := createSignedToken(newPriv, "[email protected]")+ oldKeyToken := createSignedToken(oldPriv, "[email protected]")++ t.Run("primary key only validates new token", func(t *testing.T) {+ SetPublicKey(newPub)+ SetLegacyPublicKey(nil)+ defer SetPublicKey(nil)++ lic, err := ValidateLicense(newKeyToken)+ if err != nil {+ t.Fatalf("Expected new token to validate with primary key: %v", err)+ }+ if lic.Claims.Email != "[email protected]" {+ t.Error("Email mismatch")+ }++ // Old token should fail+ _, err = ValidateLicense(oldKeyToken)+ if err == nil {+ t.Error("Expected old token to fail with only primary key")+ }+ })++ t.Run("legacy key only validates old token", func(t *testing.T) {+ SetPublicKey(nil)+ SetLegacyPublicKey(oldPub)+ defer SetLegacyPublicKey(nil)++ lic, err := ValidateLicense(oldKeyToken)+ if err != nil {+ t.Fatalf("Expected old token to validate with legacy key: %v", err)+ }+ if lic.Claims.Email != "[email protected]" {+ t.Error("Email mismatch")+ }++ // New token should fail+ _, err = ValidateLicense(newKeyToken)+ if err == nil {+ t.Error("Expected new token to fail with only legacy key")+ }+ })++ t.Run("dual key validates both tokens", func(t *testing.T) {+ SetPublicKey(newPub)+ SetLegacyPublicKey(oldPub)+ defer SetPublicKey(nil)+ defer SetLegacyPublicKey(nil)++ // New token should validate+ lic, err := ValidateLicense(newKeyToken)+ if err != nil {+ t.Fatalf("Expected new token to validate with dual keys: %v", err)+ }+ if lic.Claims.Email != "[email protected]" {+ t.Error("Email mismatch for new token")+ }++ // Old token should also validate+ lic, err = ValidateLicense(oldKeyToken)+ if err != nil {+ t.Fatalf("Expected old token to validate with dual keys: %v", err)+ }+ if lic.Claims.Email != "[email protected]" {+ t.Error("Email mismatch for old token")+ }+ })++ t.Run("neither key rejects invalid token", func(t *testing.T) {+ SetPublicKey(newPub)+ SetLegacyPublicKey(oldPub)+ defer SetPublicKey(nil)+ defer SetLegacyPublicKey(nil)++ // Create token signed with a completely different key+ _, otherPriv, _ := ed25519.GenerateKey(nil)+ otherToken := createSignedToken(otherPriv, "[email protected]")++ _, err := ValidateLicense(otherToken)+ if err == nil {+ t.Error("Expected token signed with unknown key to fail")+ }+ })+}diff --git a/internal/license/pubkey.go b/internal/license/pubkey.goindex 39965fd422..09bc357ad4 100644--- a/internal/license/pubkey.go+++ b/internal/license/pubkey.go@@ -14,47 +14,83 @@ import (// Example: go build -ldflags "-X github.com/rcourtman/pulse-go-rewrite/internal/license.EmbeddedPublicKey=BASE64_KEY"var EmbeddedPublicKey string = ""-// InitPublicKey initializes the public key for license validation.-// Priority:+// EmbeddedLegacyPublicKey is the previous production public key (base64 encoded).+// Used for dual-key verification during key rotation to validate old licenses.+// Set at build time via -ldflags alongside EmbeddedPublicKey.+var EmbeddedLegacyPublicKey string = ""++// InitPublicKey initializes the public key(s) for license validation.+// Primary key priority:// 1. PULSE_LICENSE_PUBLIC_KEY environment variable (base64 encoded)// 2. EmbeddedPublicKey (set at compile time via -ldflags)-// 3. If PULSE_LICENSE_DEV_MODE=true, skip validation (development only)//+// Legacy key priority (for dual-key verification during key rotation):+// 1. PULSE_LICENSE_LEGACY_PUBLIC_KEY environment variable (base64 encoded)+// 2. EmbeddedLegacyPublicKey (set at compile time via -ldflags)+//+// If PULSE_LICENSE_DEV_MODE=true, skip validation (development only).// Call this during application startup before any license operations.func InitPublicKey() {- // Priority 1: Environment variable+ devMode := os.Getenv("PULSE_LICENSE_DEV_MODE") == "true"+ primaryLoaded := false+ legacyLoaded := false++ // Load primary public keyif envKey := os.Getenv("PULSE_LICENSE_PUBLIC_KEY"); envKey != "" {key, err := decodePublicKey(envKey)if err != nil {- log.Error().Err(err).Msg("Failed to decode PULSE_LICENSE_PUBLIC_KEY, trying embedded key")- // Fall through to try embedded key instead of returning+ log.Error().Err(err).Msg("Failed to decode PULSE_LICENSE_PUBLIC_KEY")} else {SetPublicKey(key)log.Info().Msg("License public key loaded from environment")- return+ primaryLoaded = true}}-- // Priority 2: Embedded key (set at compile time)- if EmbeddedPublicKey != "" {+ if !primaryLoaded && EmbeddedPublicKey != "" {key, err := decodePublicKey(EmbeddedPublicKey)if err != nil {- log.Error().Err(err).Msg("Failed to decode embedded public key, license validation disabled")- return+ log.Error().Err(err).Msg("Failed to decode embedded public key")+ } else {+ SetPublicKey(key)+ log.Info().Msg("License public key loaded from embedded key")+ primaryLoaded = true}- SetPublicKey(key)- log.Info().Msg("License public key loaded from embedded key")- return}- // Priority 3: Dev mode - no key needed- if os.Getenv("PULSE_LICENSE_DEV_MODE") == "true" {- log.Warn().Msg("License validation running in DEV MODE - signatures not verified")- return+ // Load legacy public key (for dual-key verification)+ if envKey := os.Getenv("PULSE_LICENSE_LEGACY_PUBLIC_KEY"); envKey != "" {+ key, err := decodePublicKey(envKey)+ if err != nil {+ log.Error().Err(err).Msg("Failed to decode PULSE_LICENSE_LEGACY_PUBLIC_KEY")+ } else {+ SetLegacyPublicKey(key)+ log.Info().Msg("Legacy license public key loaded from environment")+ legacyLoaded = true+ }+ }+ if !legacyLoaded && EmbeddedLegacyPublicKey != "" {+ key, err := decodePublicKey(EmbeddedLegacyPublicKey)+ if err != nil {+ log.Error().Err(err).Msg("Failed to decode embedded legacy public key")+ } else {+ SetLegacyPublicKey(key)+ log.Info().Msg("Legacy license public key loaded from embedded key")+ legacyLoaded = true+ }}- // No key available - this is a problem in production- log.Warn().Msg("No license public key configured - license activation will fail")+ // Log status+ if primaryLoaded && legacyLoaded {+ log.Info().Msg("Dual-key license verification enabled (primary + legacy)")+ } else if primaryLoaded {+ log.Info().Msg("Single-key license verification enabled")+ } else if legacyLoaded {+ log.Warn().Msg("Only legacy key loaded - new licenses will not validate")+ } else if devMode {+ log.Warn().Msg("License validation running in DEV MODE - signatures not verified")+ } else {+ log.Warn().Msg("No license public key configured - license activation will fail")+ }}// decodePublicKey decodes a base64-encoded Ed25519 public key.diff --git a/mock.env b/mock.envindex 5d34edd807..2ed015c4d7 100644--- a/mock.env+++ b/mock.env@@ -7,4 +7,13 @@ PULSE_MOCK_DOCKER_HOSTS=3PULSE_MOCK_DOCKER_CONTAINERS=12PULSE_MOCK_RANDOM_METRICS=truePULSE_MOCK_STOPPED_PERCENT=20+# License verification keys (Ed25519 public keys, base64 encoded)+# For local dev, use the legacy key as primary since existing test licenses use it.+# For production releases, set the new key as primary and old key as legacy.+#+# Key rotation (2026-02-03):+# - Legacy key: OzbVzmg+TaSGt0eWzDVpn0QkqhOzJqUbOFvSF3AmuRU= (signs existing licenses)+# - New key: See /Users/rcourtman/Development/pulse/secrets/license/public_key.pem+#PULSE_LICENSE_PUBLIC_KEY="OzbVzmg+TaSGt0eWzDVpn0QkqhOzJqUbOFvSF3AmuRU="+# PULSE_LICENSE_LEGACY_PUBLIC_KEY="" # Set in production builds for dual-key verificationdiff --git a/scripts/build-release.sh b/scripts/build-release.shindex 52fcf5b954..982ec582dd 100755--- a/scripts/build-release.sh+++ b/scripts/build-release.sh@@ -27,6 +27,12 @@ elseecho "Warning: PULSE_LICENSE_PUBLIC_KEY not set; Pulse Pro license activation will fail for release binaries."fi+# Optional legacy public key for dual-key verification during key rotation+if [[ -n "${PULSE_LICENSE_LEGACY_PUBLIC_KEY:-}" ]]; then+ LICENSE_LDFLAGS="${LICENSE_LDFLAGS} -X github.com/rcourtman/pulse-go-rewrite/internal/license.EmbeddedLegacyPublicKey=${PULSE_LICENSE_LEGACY_PUBLIC_KEY}"+ echo "Legacy public key configured for dual-key verification."+fi+# Clean previous buildsrm -rf $BUILD_DIR $RELEASE_DIRmkdir -p $BUILD_DIR $RELEASE_DIR