Files
Pulse/cmd/pulse-control-plane/provider_msp.go
rcourtman 0e40ec07cb Make the provider MSP portal honest and self-sufficient without an email provider
Exercised the full provider portal as a pilot MSP would and fixed what
made it feel broken:

- The signed-out portal promised "a sign-in link is on the way" even when
  the control plane has no email provider (the bundle default), and team
  invitations silently sent nothing. The portal bootstrap now carries
  email_sign_in_available and provider_hosted_mode; the sign-in page shows
  the host command that actually prints a link, and the invite panel says
  invitation emails are not sent and how to hand over a link instead.
- New "provider-msp portal-link --email" CLI mints a one-time portal link
  for an account member or pending invitee, so teammates can sign in at
  all on email-less installs (bootstrap only covers the owner).
- Portal sessions were fixed at 12h; CP_SESSION_TTL now configures them
  and provider-hosted MSP mode defaults to 7 days.
- Creating a client past the license cap showed a generic "Failed to
  create workspace." toast: the limit error is now a JSON payload with
  current/limit, the API client no longer drops non-JSON error bodies
  (double body read), and the toast explains the license limit.
- Copy polish: provider-mode sign-in intro (no refunds/privacy register),
  least-privilege default invite role, queue tile label matches "Client
  onboarding", softer Support tab with a docs/MSP.md pointer, setup.sh
  summary now prints the bootstrap next step and day-2 sign-in commands,
  .env.example and docs/MSP.md document portal sign-in and sessions.

Contracts updated (cloud-paid, api-contracts, deployment-installability,
security-privacy) with verification pins in tenant_handlers_test,
config_test, magiclink_test, and provider_msp_deploy_test.

Verified live against a dockerless control plane: portal-link for an
invitee redeems, promotes the invitation, and sets a 7-day session;
the at-cap toast shows the license copy; portal vitest suite and
cloudcp/auth/account/installtests Go suites pass.
2026-07-10 11:22:57 +01:00

125 lines
4.1 KiB
Go

package main
import (
"fmt"
"github.com/rcourtman/pulse-go-rewrite/internal/cloudcp"
"github.com/spf13/cobra"
)
func newProviderMSPCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "provider-msp",
Short: "Operate a provider-hosted MSP control plane",
}
cmd.AddCommand(newProviderMSPBootstrapCmd())
cmd.AddCommand(newProviderMSPPortalLinkCmd())
cmd.AddCommand(newProviderMSPBackupCmd())
cmd.AddCommand(newProviderMSPInstallProofCmd())
cmd.AddCommand(newProviderMSPPreflightCmd())
cmd.AddCommand(newProviderMSPProofCmd())
cmd.AddCommand(newProviderMSPRecoverCmd())
cmd.AddCommand(newProviderMSPStatusCmd())
return cmd
}
func newProviderMSPBootstrapCmd() *cobra.Command {
var accountID string
var accountName string
var ownerEmail string
var magicLink bool
cmd := &cobra.Command{
Use: "bootstrap",
Short: "Create or update the provider MSP account owner",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := cloudcp.LoadConfig()
if err != nil {
return fmt.Errorf("load control plane config: %w", err)
}
result, err := cloudcp.BootstrapProviderMSP(cmd.Context(), cfg, cloudcp.ProviderMSPBootstrapOptions{
AccountID: accountID,
AccountName: accountName,
OwnerEmail: ownerEmail,
GenerateMagicLink: magicLink,
})
if err != nil {
return err
}
printProviderMSPBootstrapResult(result)
return nil
},
}
cmd.Flags().StringVar(&accountID, "account-id", "", "Existing MSP account ID to bootstrap; omitted on first install")
cmd.Flags().StringVar(&accountName, "account-name", "", "Provider account display name")
cmd.Flags().StringVar(&ownerEmail, "owner-email", "", "Provider owner email address")
cmd.Flags().BoolVar(&magicLink, "magic-link", true, "Generate a one-time Pulse Account portal sign-in link")
_ = cmd.MarkFlagRequired("account-name")
_ = cmd.MarkFlagRequired("owner-email")
return cmd
}
func newProviderMSPPortalLinkCmd() *cobra.Command {
var email string
cmd := &cobra.Command{
Use: "portal-link",
Short: "Print a one-time portal sign-in link for an account member or pending invitee",
Long: `Print a one-time portal sign-in link for an account member or pending invitee.
Use this when the control plane has no email provider configured, so the
portal cannot send sign-in links or invitation emails itself. The email
address must already be an account member or hold a pending invitation
created from the portal Access tab.`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := cloudcp.LoadConfig()
if err != nil {
return fmt.Errorf("load control plane config: %w", err)
}
result, err := cloudcp.ProviderMSPPortalLink(cmd.Context(), cfg, cloudcp.ProviderMSPPortalLinkOptions{
Email: email,
})
if err != nil {
return err
}
printProviderMSPPortalLinkResult(result)
return nil
},
}
cmd.Flags().StringVar(&email, "email", "", "Email address of the account member or pending invitee")
_ = cmd.MarkFlagRequired("email")
return cmd
}
func printProviderMSPPortalLinkResult(result *cloudcp.ProviderMSPPortalLinkResult) {
if result == nil {
fmt.Println("provider_msp_portal_link_ok=false")
return
}
fmt.Println("provider_msp_portal_link_ok=true")
fmt.Printf("email=%s\n", result.Email)
fmt.Printf("access_state=%s\n", result.AccessState)
fmt.Printf("role=%s\n", result.Role)
fmt.Printf("portal_magic_link=%s\n", result.MagicLinkURL)
}
func printProviderMSPBootstrapResult(result *cloudcp.ProviderMSPBootstrapResult) {
if result == nil {
fmt.Println("provider_msp_bootstrap_ok=false")
return
}
fmt.Println("provider_msp_bootstrap_ok=true")
fmt.Printf("account_id=%s\n", result.AccountID)
fmt.Printf("account_name=%s\n", result.AccountName)
fmt.Printf("owner_user_id=%s\n", result.OwnerUserID)
fmt.Printf("owner_email=%s\n", result.OwnerEmail)
fmt.Printf("plan_version=%s\n", result.PlanVersion)
fmt.Printf("plan_source=%s\n", result.PlanSource)
fmt.Printf("license_id=%s\n", result.LicenseID)
fmt.Printf("license_email=%s\n", result.LicenseEmail)
fmt.Printf("workspace_limit=%d\n", result.WorkspaceLimit)
if result.MagicLinkURL != "" {
fmt.Printf("portal_magic_link=%s\n", result.MagicLinkURL)
}
}