Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
refactor(sam-one): use provider-agnostic SAM_TUNNEL_TOKEN env var
Antonio Ojea2c2bbb74a3df
diff --git a/cmd/sam-one/main.go b/cmd/sam-one/main.goindex 65b98e9a..6eae5bea 100644--- a/cmd/sam-one/main.go+++ b/cmd/sam-one/main.go@@ -99,7 +99,7 @@ func main() {if err != nil {logger.Fatalf("Invalid --admin-token-path: %v", err)}- tunnelToken, err := secretFromPathOrEnv(tunnelTokenPath, "CLOUDFLARE_TUNNEL_TOKEN")+ tunnelToken, err := secretFromPathOrEnv(tunnelTokenPath, "SAM_TUNNEL_TOKEN")if err != nil {logger.Fatalf("Invalid --tunnel-token-path: %v", err)}@@ -120,10 +120,10 @@ func main() {var tun tunnel.Tunnelif tunnelProvider != "" {if tunnelToken == "" && externalURL != "" {- logger.Fatal("--tunnel and --external-url are mutually exclusive unless --tunnel-token-path / CLOUDFLARE_TUNNEL_TOKEN is set")+ logger.Fatal("--tunnel and --external-url are mutually exclusive unless --tunnel-token-path / SAM_TUNNEL_TOKEN is set")}if tunnelToken != "" && externalURL == "" {- logger.Fatal("--tunnel-token-path / CLOUDFLARE_TUNNEL_TOKEN requires --external-url (the public https:// hostname routed to the named tunnel)")+ logger.Fatal("--tunnel-token-path / SAM_TUNNEL_TOKEN requires --external-url (the public https:// hostname routed to the tunnel)")}if port == 0 {var err error@@ -212,7 +212,7 @@ func main() {rootCmd.Flags().StringVar(&allowedAudiencesFlag, "allowed-audiences", api.DefaultAudience, "Comma-separated list of allowed OIDC audiences")rootCmd.Flags().StringVar(&logLevel, "log-level", "", "Log level: debug, info, warn, error")rootCmd.Flags().StringVar(&tunnelProvider, "tunnel", "", "Publish the listener on a public URL through a tunnel provider ("+strings.Join(tunnel.Names(), ", ")+"); sets the external URL")- rootCmd.Flags().StringVar(&tunnelTokenPath, "tunnel-token-path", "", "File containing a Cloudflare Named Tunnel token (or env CLOUDFLARE_TUNNEL_TOKEN); use with --tunnel cloudflare --external-url https://...")+ rootCmd.Flags().StringVar(&tunnelTokenPath, "tunnel-token-path", "", "File containing the tunnel provider token (or env SAM_TUNNEL_TOKEN); use with --tunnel <provider> --external-url https://...")rootCmd.Flags().BoolVar(&tunnelInstall, "tunnel-install", false, "Download the pinned connector binary (cloudflared "+tunnel.CloudflaredVersion+", digest-verified) into <data-dir>/bin without asking; implies accepting its license")rootCmd.Flags().StringVar(&cloudflaredPath, "cloudflared-path", "", "Explicit cloudflared executable for --tunnel cloudflare (default: PATH, then <data-dir>/bin)")rootCmd.Flags().BoolVar(&enrollQR, "enroll-qr", stdoutIsTerminal(), "Print a device enrollment QR code at startup (default: when stdout is a terminal)")diff --git a/deploy/skypilot/sam-one.yaml b/deploy/skypilot/sam-one.yamlindex 3a7ab307..0508ac05 100644--- a/deploy/skypilot/sam-one.yaml+++ b/deploy/skypilot/sam-one.yaml@@ -1,10 +1,10 @@# SkyPilot recipe for deploying a standalone SAM control plane + router (sam-one)# on any cloud provider (GCP, AWS, Azure, OCI, or Kubernetes).#-# Production deployment with a permanent custom domain (Cloudflare Named Tunnel):+# Production deployment with a permanent custom domain:# sky launch -y -c sam-hub deploy/skypilot/sam-one.yaml --detach-run \# --env SAM_EXTERNAL_URL=https://mesh.example.com \-# --secret CLOUDFLARE_TUNNEL_TOKEN+# --secret SAM_TUNNEL_TOKEN## Quick deployment with an automatic HTTPS tunnel:# sky launch -y -c sam-hub deploy/skypilot/sam-one.yaml --detach-run@@ -28,7 +28,7 @@ envs:SAM_EXTERNAL_URL: ""secrets:- CLOUDFLARE_TUNNEL_TOKEN: ""+ SAM_TUNNEL_TOKEN: ""setup: |set -euo pipefaildiff --git a/internal/tunnel/cloudflare.go b/internal/tunnel/cloudflare.goindex 425329b8..37702340 100644--- a/internal/tunnel/cloudflare.go+++ b/internal/tunnel/cloudflare.go@@ -71,8 +71,8 @@ type Cloudflare struct {// the zone's authoritative nameserver (see authoritativeLookup). Tests// stub it.LookupHost func(ctx context.Context, host string) ([]string, error)- // Token is an optional Cloudflare Named Tunnel token (from- // --tunnel-token-path or CLOUDFLARE_TUNNEL_TOKEN). When set, Open runs+ // Token is an optional named tunnel token (from --tunnel-token-path+ // or SAM_TUNNEL_TOKEN). When set, Open runs// `cloudflared tunnel --no-autoupdate run --url <target>` with// TUNNEL_TOKEN in the child environment instead of a random// trycloudflare.com quick tunnel, and publishes ExternalURL.diff --git a/site/content/docs/guides/skypilot.md b/site/content/docs/guides/skypilot.mdindex d7cee592..53216170 100644--- a/site/content/docs/guides/skypilot.md+++ b/site/content/docs/guides/skypilot.md@@ -19,18 +19,18 @@ tiers such as GCP `e2-micro` or AWS `t4g.micro` for testing.)*## 1. Deploy `sam-one` with SkyPilot-### Production deployment (custom domain via Cloudflare Named Tunnel)+### Production deployment (custom domain)-If you have a Cloudflare Named Tunnel token bound to a custom hostname (such as+If you have a tunnel authentication token bound to a custom hostname (such as`https://mesh.example.com`), launch the cluster with `SAM_EXTERNAL_URL` and-`CLOUDFLARE_TUNNEL_TOKEN`:+`SAM_TUNNEL_TOKEN`:```bash-export CLOUDFLARE_TUNNEL_TOKEN="eyJhIjoi..."+export SAM_TUNNEL_TOKEN="eyJhIjoi..."sky launch -y -c sam-hub deploy/skypilot/sam-one.yaml --detach-run \--env SAM_EXTERNAL_URL=https://mesh.example.com \- --secret CLOUDFLARE_TUNNEL_TOKEN+ --secret SAM_TUNNEL_TOKEN```### Quick deployment (automatic HTTPS tunnel)diff --git a/site/content/docs/reference/sam-one.md b/site/content/docs/reference/sam-one.mdindex d5b6d7eb..246bbb99 100644--- a/site/content/docs/reference/sam-one.md+++ b/site/content/docs/reference/sam-one.md@@ -29,7 +29,7 @@ downloaded tunnel connector.| `--port` | `0` | TCP port. `0` picks a free one and prints it in the banner. || `--external-url` | | Public URL on which nodes reach this instance, for a reverse proxy or a hosted platform. Can also be set with `SAM_EXTERNAL_URL`. When omitted behind an HTTPS proxy (Cloud Run, Fly.io), `/info` infers the advertised `wss` address from the incoming `Host` / `X-Forwarded-Proto` headers automatically. || `--tunnel` | | Publish the port through a tunnel provider and use the resulting URL as the external URL. The provider is `cloudflare` (defaults to a free quick tunnel on `*.trycloudflare.com`, no account needed). |-| `--tunnel-token-path` | | File containing a Cloudflare Named Tunnel token (can also be set with `CLOUDFLARE_TUNNEL_TOKEN`). Use together with `--tunnel cloudflare --external-url https://mesh.example.com` for a permanent custom domain. |+| `--tunnel-token-path` | | File containing the tunnel provider authentication token (can also be set with `SAM_TUNNEL_TOKEN`). Use together with `--tunnel <provider> --external-url https://mesh.example.com` for a permanent custom domain. || `--tunnel-install` | `false` | Download the pinned, digest-verified `cloudflared` into `<data-dir>/bin` without asking. Implies acceptance of its license. || `--cloudflared-path` | `PATH`, then `<data-dir>/bin` | Explicit connector binary. || `--p2p-listen` | none | Extra native libp2p listen addresses, in addition to the WebSocket transport on the main port. |