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
Gate cloud provisioning to hosted checkouts
rcourtman1267a817c760
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.mdindex c6604ba434..5838c76cdc 100644--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md@@ -239,7 +239,14 @@ runtime gating as separate unlinked claims.pairing for handoff, push notifications, and 14-day history; it must not imply that thenative mobile app is a full monitoring dashboard until that product surfaceexists.-7. Add or change Stripe provisioning plan resolution through `internal/cloudcp/stripe/provisioner.go`+7. Add or change Stripe provisioning plan resolution through+ `internal/cloudcp/stripe/provisioner.go`, `internal/cloudcp/stripe/webhook.go`,+ and `pkg/licensing/stripe_subscription.go`. Checkout-session provisioning+ must be explicitly classified as hosted before tenant creation: `cloud_*`+ and `msp_*` plan versions may provision hosted runtime, public Cloud signup+ source may provision only when the plan is otherwise unresolved for staging+ compatibility, and self-hosted v5/v6 checkout metadata must be ignored by+ the Cloud control-plane webhook even if Stripe delivers the event there.8. Add or change activation/grant lifecycle, release build helper gating, or dev-mode capability widening through `pkg/licensing/dev_mode_features.go`, `pkg/licensing/service.go`, `pkg/licensing/testing_helpers.go`, `pkg/licensing/grant_refresh.go`, and `pkg/licensing/revocation_poll.go`9. Add or change license-server transport through `pkg/licensing/license_server_client.go`That transport boundary must use HTTPS for non-loopback commercial endpoints,@@ -601,6 +608,12 @@ not see finite monitored-system pressure in the global app shell; when hostedcapacity policy is active, the banner reviews finite-policy usage on the usageledger rather than sending operators to the plan-selection surface withcapacity-shaped copy.+Stripe checkout metadata now treats `plan_id` and `price_id` as Stripe price+identifiers for plan-version derivation, including grandfathered v5 recurring+prices. The Cloud control-plane webhook uses that derivation as an admission+boundary: hosted Cloud/MSP checkout events may provision tenants, while+self-hosted landing purchases are acknowledged and ignored rather than+creating hosted containers or Stripe account mappings.Cloud paid readiness is materially behind architecture work. The main concern iscontract coherence between pricing, entitlements, and runtime enforcement.diff --git a/internal/cloudcp/stripe/helpers_test.go b/internal/cloudcp/stripe/helpers_test.goindex 63eac70d6c..89e6cb7e88 100644--- a/internal/cloudcp/stripe/helpers_test.go+++ b/internal/cloudcp/stripe/helpers_test.go@@ -110,6 +110,8 @@ func TestDerivePlanVersion(t *testing.T) {{"plan_version in metadata", map[string]string{"plan_version": "v2"}, "", "v2"},{"plan in metadata", map[string]string{"plan": "pro"}, "", "pro"},{"plan_version takes priority", map[string]string{"plan_version": "v3", "plan": "pro"}, "", "v3"},+ {"price_id in metadata", map[string]string{"price_id": "price_1T5kg2BrHBocJIGHmkoF0zXY"}, "", "cloud_power"},+ {"plan_id in metadata", map[string]string{"plan_id": "price_1ShIsdBrHBocJIGH71yQusLG"}, "", "v5_pro_monthly_grandfathered"},{"price ID fallback", nil, "price_123", "stripe_price:price_123"},{"generic fallback", nil, "", "stripe"},{"nil metadata with price", nil, "price_abc", "stripe_price:price_abc"},diff --git a/internal/cloudcp/stripe/webhook.go b/internal/cloudcp/stripe/webhook.goindex 136000b08b..9a34a5da3b 100644--- a/internal/cloudcp/stripe/webhook.go+++ b/internal/cloudcp/stripe/webhook.go@@ -12,6 +12,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/cpmetrics""github.com/rcourtman/pulse-go-rewrite/internal/cloudcp/registry"+ pkglicensing "github.com/rcourtman/pulse-go-rewrite/pkg/licensing""github.com/rs/zerolog/log"stripelib "github.com/stripe/stripe-go/v82""github.com/stripe/stripe-go/v82/webhook"@@ -20,6 +21,7 @@ import (const webhookBodyLimit = 1024 * 1024 // 1 MiBconst checkoutProvisioningTimeout = 2 * time.Minuteconst selfHostedProTrialSignupSource = "pulse_pro_trial"+const publicCloudSignupSource = "public_cloud_signup"// WebhookHandler handles incoming Stripe webhook events.type WebhookHandler struct {@@ -144,6 +146,13 @@ func (h *WebhookHandler) handleEvent(r *http.Request, event *stripelib.Event) erMsg("Stripe webhook ignored retired self-hosted Pro trial checkout")return nil}+ if !isHostedProvisioningCheckout(session) {+ log.Info().+ Str("session_id", strings.TrimSpace(session.ID)).+ Str("plan_version", DerivePlanVersion(session.Metadata, "")).+ Msg("Stripe webhook ignored non-hosted checkout")+ return nil+ }return h.provisioner.HandleCheckout(ctx, session)case "customer.subscription.updated":@@ -183,6 +192,29 @@ func isSelfHostedProTrialCheckout(session CheckoutSession) bool {return strings.EqualFold(strings.TrimSpace(session.Metadata["signup_source"]), selfHostedProTrialSignupSource)}+func isHostedProvisioningCheckout(session CheckoutSession) bool {+ metadata := session.Metadata+ if metadata == nil {+ return false+ }+ signupSource := strings.ToLower(strings.TrimSpace(metadata["signup_source"]))+ planVersion := pkglicensing.CanonicalizePlanVersion(DerivePlanVersion(metadata, ""))+ if isHostedPlanVersion(planVersion) {+ return true+ }+ return signupSource == publicCloudSignupSource && isUnresolvedPlanVersion(planVersion)+}++func isHostedPlanVersion(planVersion string) bool {+ normalized := strings.ToLower(pkglicensing.CanonicalizePlanVersion(planVersion))+ return strings.HasPrefix(normalized, "cloud_") || strings.HasPrefix(normalized, "msp_")+}++func isUnresolvedPlanVersion(planVersion string) bool {+ normalized := strings.ToLower(pkglicensing.CanonicalizePlanVersion(planVersion))+ return normalized == "" || normalized == "stripe" || strings.HasPrefix(normalized, "stripe_price:")+}+func webhookEventContext(r *http.Request, eventType stripelib.EventType) (context.Context, context.CancelFunc) {if eventType == stripelib.EventType("checkout.session.completed") {return context.WithTimeout(context.Background(), checkoutProvisioningTimeout)diff --git a/internal/cloudcp/stripe/webhook_test.go b/internal/cloudcp/stripe/webhook_test.goindex 77803c5261..f0480513ce 100644--- a/internal/cloudcp/stripe/webhook_test.go+++ b/internal/cloudcp/stripe/webhook_test.go@@ -91,6 +91,131 @@ func TestWebhookIgnoresSelfHostedProTrialCheckoutSessions(t *testing.T) {}}+func TestWebhookIgnoresSelfHostedLandingCheckoutSessions(t *testing.T) {+ reg := newTestRegistry(t)+ tenantsDir := t.TempDir()+ provisioner := NewProvisioner(reg, tenantsDir, nil, nil, "https://cloud.example.com", nil, "", false)++ const secret = "whsec_test_secret"+ handler := NewWebhookHandler(secret, provisioner)++ eventJSON := `{+ "id":"evt_self_hosted_landing_123",+ "object":"event",+ "type":"checkout.session.completed",+ "data":{+ "object":{+ "id":"cs_test_self_hosted_landing",+ "mode":"subscription",+ "customer":"cus_selfhost_landing",+ "subscription":"sub_selfhost_landing",+ "customer_email":"[email protected]",+ "customer_details":{"email":"[email protected]"},+ "metadata":{+ "plan_id":"price_1ShIsdBrHBocJIGH71yQusLG",+ "generation":"v5",+ "checkout_origin":"pulserelay_landing"+ }+ }+ }+ }`+ req := signedWebhookRequest(t, secret, eventJSON)+ rec := httptest.NewRecorder()+ handler.ServeHTTP(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("delivery status=%d, want=%d, body=%q", rec.Code, http.StatusOK, rec.Body.String())+ }++ tenants, err := reg.List()+ if err != nil {+ t.Fatalf("List tenants: %v", err)+ }+ if len(tenants) != 0 {+ t.Fatalf("tenant count=%d, want 0 for self-hosted landing checkout", len(tenants))+ }+ stripeAccount, err := reg.GetStripeAccountByCustomerID("cus_selfhost_landing")+ if err != nil {+ t.Fatalf("GetStripeAccountByCustomerID: %v", err)+ }+ if stripeAccount != nil {+ t.Fatalf("Stripe account mapping was created for self-hosted landing checkout: %#v", stripeAccount)+ }+}++func TestHostedProvisioningCheckoutClassification(t *testing.T) {+ tests := []struct {+ name string+ metadata map[string]string+ want bool+ }{+ {+ name: "public cloud signup source",+ metadata: map[string]string{+ "signup_source": publicCloudSignupSource,+ },+ want: true,+ },+ {+ name: "public cloud signup source with self hosted plan id",+ metadata: map[string]string{+ "signup_source": publicCloudSignupSource,+ "plan_id": "price_1ShIsdBrHBocJIGH71yQusLG",+ },+ want: false,+ },+ {+ name: "cloud plan version",+ metadata: map[string]string{+ "plan_version": "cloud_starter",+ },+ want: true,+ },+ {+ name: "cloud plan id",+ metadata: map[string]string{+ "plan_id": "price_1T5kg2BrHBocJIGHmkoF0zXY",+ },+ want: true,+ },+ {+ name: "msp plan version",+ metadata: map[string]string{+ "plan_version": "msp_growth",+ },+ want: true,+ },+ {+ name: "self hosted v5 plan id",+ metadata: map[string]string{+ "plan_id": "price_1ShIsdBrHBocJIGH71yQusLG",+ },+ want: false,+ },+ {+ name: "self hosted v6 generation",+ metadata: map[string]string{+ "plan_id": "price_1TPmE6BrHBocJIGHHaPwluoM",+ "generation": "v6",+ },+ want: false,+ },+ {+ name: "missing metadata",+ metadata: nil,+ want: false,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got := isHostedProvisioningCheckout(CheckoutSession{Metadata: tt.metadata})+ if got != tt.want {+ t.Fatalf("isHostedProvisioningCheckout=%t, want %t", got, tt.want)+ }+ })+ }+}+func TestWebhookEventContext_DetachesCheckoutFromRequestContext(t *testing.T) {req := httptest.NewRequest(http.MethodPost, "/api/stripe/webhook", nil)ctx, cancelReq := context.WithCancel(req.Context())diff --git a/pkg/licensing/stripe_subscription.go b/pkg/licensing/stripe_subscription.goindex 084ec0258f..422045bf0e 100644--- a/pkg/licensing/stripe_subscription.go+++ b/pkg/licensing/stripe_subscription.go@@ -39,6 +39,11 @@ func DeriveStripePlanVersion(metadata map[string]string, priceID string) stringif v := strings.TrimSpace(metadata["plan"]); v != "" {return CanonicalizePlanVersion(v)}+ if v := strings.TrimSpace(metadata["price_id"]); v != "" {+ priceID = v+ } else if v := strings.TrimSpace(metadata["plan_id"]); v != "" {+ priceID = v+ }}trimmedPrice := strings.TrimSpace(priceID)if trimmedPrice != "" {diff --git a/pkg/licensing/stripe_subscription_test.go b/pkg/licensing/stripe_subscription_test.goindex 548b53e733..1c9c1594a0 100644--- a/pkg/licensing/stripe_subscription_test.go+++ b/pkg/licensing/stripe_subscription_test.go@@ -95,12 +95,30 @@ func TestDeriveStripePlanVersion(t *testing.T) {priceID: "price_1T5kflBrHBocJIGHUqPv1dzV",want: "cloud_starter",},+ {+ name: "metadata price_id resolves to plan",+ metadata: map[string]string{"price_id": "price_1T5kg2BrHBocJIGHmkoF0zXY"},+ priceID: "",+ want: "cloud_power",+ },+ {+ name: "metadata plan_id resolves to plan",+ metadata: map[string]string{"plan_id": "price_1T5kg4BrHBocJIGHHa8Ecqho"},+ priceID: "",+ want: "cloud_max",+ },{name: "legacy v5 recurring monthly price resolves to grandfathered plan",metadata: nil,priceID: "price_1ShIsdBrHBocJIGH71yQusLG",want: "v5_pro_monthly_grandfathered",},+ {+ name: "legacy v5 recurring plan_id resolves to grandfathered plan",+ metadata: map[string]string{"plan_id": "price_1ShIsdBrHBocJIGH71yQusLG"},+ priceID: "",+ want: "v5_pro_monthly_grandfathered",+ },{name: "legacy v1 recurring annual price resolves to grandfathered plan",metadata: nil,