Skip to content

Agent Mesh

feat(security)!: never accept daemon secrets as flag values

Antonio Ojeab8815ca34062
diff --git a/.github/k8s/sam-console-template.yaml b/.github/k8s/sam-console-template.yaml
index 7c238d8f..45aa6be8 100644
--- a/.github/k8s/sam-console-template.yaml
+++ b/.github/k8s/sam-console-template.yaml
@@ -35,7 +35,6 @@ spec:
- "--control-plane=http://sam-control-plane-${ENV_NAME}:8080"
- "--bind-addr=:8081"
- "--static-dir=/app/public"
- - "--admin-token=$(SAM_ADMIN_TOKEN)"
- "--base-path=/console"
env:
- name: SAM_ADMIN_TOKEN
diff --git a/.github/k8s/sam-control-plane-template.yaml b/.github/k8s/sam-control-plane-template.yaml
index 2aa6279b..552b6ead 100644
--- a/.github/k8s/sam-control-plane-template.yaml
+++ b/.github/k8s/sam-control-plane-template.yaml
@@ -93,7 +93,7 @@ spec:
- name: sam-control-plane
image: ghcr.io/google/sam-control-plane:${IMAGE_TAG}
env:
- - name: ADMIN_TOKEN
+ - name: SAM_ADMIN_TOKEN
valueFrom:
secretKeyRef:
name: sam-control-plane-secret-${ENV_NAME}
@@ -123,7 +123,6 @@ spec:
- "--db-dsn=postgres://sam:sam-secret-password@sam-db-${ENV_NAME}:5432/sam_mesh?sslmode=disable"
- "--issuer=https://auth.sam-mesh.dev,https://container.googleapis.com/v1/projects/${GCP_PROJECT_ID}/locations/${CLUSTER_REGION}/clusters/${CLUSTER_NAME}"
- "--allowed-audiences=sam-mesh-audience,sam-control-plane-audience"
- - "--admin-token=$(ADMIN_TOKEN)"
- "--auto-approve-enrollment"
- "--key-grace-period=48h"
resources:
diff --git a/.github/k8s/sam-node-cop-template.yaml b/.github/k8s/sam-node-cop-template.yaml
index dbd95844..a4b1374c 100644
--- a/.github/k8s/sam-node-cop-template.yaml
+++ b/.github/k8s/sam-node-cop-template.yaml
@@ -60,12 +60,14 @@ spec:
subPath: banana_bot_playground.py
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
- "--bind-addr=127.0.0.1:8080"
ports:
- containerPort: 8080
diff --git a/.github/k8s/sam-node-everything-template.yaml b/.github/k8s/sam-node-everything-template.yaml
index 63452337..9f30c3b8 100644
--- a/.github/k8s/sam-node-everything-template.yaml
+++ b/.github/k8s/sam-node-everything-template.yaml
@@ -48,12 +48,14 @@ spec:
memory: 256Mi
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
- "--bind-addr=127.0.0.1:8080"
ports:
- containerPort: 8080
diff --git a/.github/k8s/sam-node-openclaw-template.yaml b/.github/k8s/sam-node-openclaw-template.yaml
index c14e5fc0..5f69515c 100644
--- a/.github/k8s/sam-node-openclaw-template.yaml
+++ b/.github/k8s/sam-node-openclaw-template.yaml
@@ -104,12 +104,14 @@ spec:
mountPath: /dev/shm
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
- "--bind-addr=127.0.0.1:8080"
ports:
- containerPort: 8080
diff --git a/.github/k8s/sam-node-openrouter-template.yaml b/.github/k8s/sam-node-openrouter-template.yaml
index 6036a878..6d40fe73 100644
--- a/.github/k8s/sam-node-openrouter-template.yaml
+++ b/.github/k8s/sam-node-openrouter-template.yaml
@@ -54,12 +54,14 @@ spec:
memory: 256Mi
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
- "--bind-addr=127.0.0.1:8080"
ports:
- containerPort: 8080
diff --git a/.github/k8s/sam-node-template.yaml b/.github/k8s/sam-node-template.yaml
index 0c88b077..d41cb8bc 100644
--- a/.github/k8s/sam-node-template.yaml
+++ b/.github/k8s/sam-node-template.yaml
@@ -42,12 +42,14 @@ spec:
containers:
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
ports:
- containerPort: 8080
resources:
diff --git a/.github/k8s/sam-node-vllm-template.yaml b/.github/k8s/sam-node-vllm-template.yaml
index c6e7ff54..c7e6c1bf 100644
--- a/.github/k8s/sam-node-vllm-template.yaml
+++ b/.github/k8s/sam-node-vllm-template.yaml
@@ -97,12 +97,14 @@ spec:
mountPath: /root/.cache/huggingface
- name: sam-node
image: ghcr.io/google/sam-node:${IMAGE_TAG}
+ env:
+ - name: SAM_API_TOKEN
+ value: "secret-token"
args:
- "run"
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
- "--bind-addr=127.0.0.1:8080"
ports:
- containerPort: 8080
diff --git a/api/network.go b/api/network.go
index 75bd831a..2832b7d9 100644
--- a/api/network.go
+++ b/api/network.go
@@ -89,7 +89,8 @@ const (
// HeaderSamAuthentication is the custom HTTP header used to authenticate a local
// process to this node's sidecar API (the shared secret configured via
- // "--api-token"). Using a SAM-specific header name — instead of the standard
+ // "--api-token-path" or the SAM_API_TOKEN environment variable). Using a
+ // SAM-specific header name — instead of the standard
// "Authorization" header — leaves "Authorization" free to always mean what
// every HTTP client expects: the credential for the destination being called.
// The sidecar strips this header before forwarding any request off-node, so
diff --git a/charts/sam-mesh/templates/console-deployment.yaml b/charts/sam-mesh/templates/console-deployment.yaml
index 54d5b01f..c3f22ce3 100644
--- a/charts/sam-mesh/templates/console-deployment.yaml
+++ b/charts/sam-mesh/templates/console-deployment.yaml
@@ -33,7 +33,7 @@ spec:
image: "{{ .Values.console.image.repository }}:{{ .Values.global.imageTag }}"
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
env:
- - name: ADMIN_TOKEN
+ - name: SAM_ADMIN_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "sam-mesh.fullname" . }}-secrets
@@ -57,6 +57,4 @@ spec:
args:
- "--control-plane=http://{{ include "sam-mesh.fullname" . }}-control-plane:{{ .Values.controlPlane.service.port }}"
- "--bind-addr=:8081"
- - "--static-dir=/app/public"
- - "--admin-token=$(ADMIN_TOKEN)"
-{{- end }}
+ - "--static-dir=/app/public"{{- end }}
diff --git a/charts/sam-mesh/templates/control-plane-deployment.yaml b/charts/sam-mesh/templates/control-plane-deployment.yaml
index 43fb5a44..9897cc55 100644
--- a/charts/sam-mesh/templates/control-plane-deployment.yaml
+++ b/charts/sam-mesh/templates/control-plane-deployment.yaml
@@ -24,7 +24,7 @@ spec:
secretKeyRef:
name: {{ include "sam-mesh.fullname" . }}-secrets
key: db-password
- - name: ADMIN_TOKEN
+ - name: SAM_ADMIN_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "sam-mesh.fullname" . }}-secrets
@@ -63,7 +63,6 @@ spec:
{{- end }}
- "--issuer={{ .Values.controlPlane.oidcIssuer }}"
- "--allowed-audiences={{ .Values.controlPlane.allowedAudiences }}"
- - "--admin-token=$(ADMIN_TOKEN)"
{{- if .Values.controlPlane.autoApproveEnrollment }}
- "--auto-approve-enrollment"
{{- end }}
diff --git a/cmd/sam-box/main.go b/cmd/sam-box/main.go
index 664f4100..9b251093 100644
--- a/cmd/sam-box/main.go
+++ b/cmd/sam-box/main.go
@@ -29,6 +29,7 @@ import (
"github.com/google/sam/api"
"github.com/google/sam/internal/node"
"github.com/google/sam/internal/sambox"
+ "github.com/google/sam/internal/secrets"
golog "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
@@ -55,8 +56,10 @@ var (
jwtFlag string
jwtPathFlag string
bootstrapTokenFlag string
+ bootstrapTokenPathFlag string
clientIDFlag string
clientSecretFlag string
+ clientSecretPathFlag string
controlPlanePublicKeyFlag string
meshFlag string
discoveryIntervalFlag string
@@ -87,6 +90,30 @@ var (
var logger = golog.Logger("sam-box-cli")
+// resolveSecretFlag folds a --<name>-path file variant into its value flag
+// and warns when the secret was passed on the command line, where it leaks
+// via /proc/<pid>/cmdline, shell history, and pod specs.
+func resolveSecretFlag(name, value, path string) string {
+ if value != "" {
+ logger.Warnf("--%s passes a secret on the command line; prefer --%s-path", name, name)
+ }
+ secret, err := secrets.Resolve(name, value, path)
+ if err != nil {
+ logger.Fatalf("%v", err)
+ }
+ return secret
+}
+
+// resolveDaemonSecret resolves a secret that lives for the daemon's whole
+// lifetime: file (recommended) or environment variable, never a flag value.
+func resolveDaemonSecret(name, path, envVar string) string {
+ secret, err := secrets.FromPathOrEnv(name, path, envVar)
+ if err != nil {
+ logger.Fatalf("%v", err)
+ }
+ return secret
+}
+
func main() {
rootCmd := &cobra.Command{
Use: "sam-box",
@@ -110,6 +137,12 @@ func main() {
_ = golog.SetLogLevel("dht", "fatal")
_ = golog.SetLogLevel("dht/RtRefreshManager", "fatal")
+ bootstrapTokenFlag = resolveSecretFlag("bootstrap-token", bootstrapTokenFlag, bootstrapTokenPathFlag)
+ clientSecretFlag = resolveDaemonSecret("client-secret", clientSecretPathFlag, "SAM_CLIENT_SECRET")
+ if jwtFlag != "" {
+ logger.Warn("--jwt passes a secret on the command line; prefer --jwt-path")
+ }
+
if udsPathFlag == "" {
logger.Fatal("missing required flag: --uds-path")
}
@@ -484,8 +517,9 @@ func main() {
runCmd.Flags().StringVar(&jwtFlag, "jwt", "", "Pre-fetched JWT token")
runCmd.Flags().StringVar(&jwtPathFlag, "jwt-path", "", "Path to file containing JWT token")
runCmd.Flags().StringVar(&bootstrapTokenFlag, "bootstrap-token", "", "Pre-shared bootstrap token for enrollment")
+ runCmd.Flags().StringVar(&bootstrapTokenPathFlag, "bootstrap-token-path", "", "Path to file containing the bootstrap token (recommended over --bootstrap-token)")
runCmd.Flags().StringVar(&clientIDFlag, "client-id", "", "OIDC Client ID for M2M")
- runCmd.Flags().StringVar(&clientSecretFlag, "client-secret", "", "OIDC Client Secret for M2M")
+ runCmd.Flags().StringVar(&clientSecretPathFlag, "client-secret-path", "", "Path to file containing the OIDC client secret (or env SAM_CLIENT_SECRET)")
runCmd.Flags().StringVar(&controlPlanePublicKeyFlag, "control-plane-public-key", "", "Control plane public key (32-byte Hex)")
runCmd.Flags().StringVar(&meshFlag, "mesh", node.DefaultMeshName, "Mesh federation name")
runCmd.Flags().StringVar(&discoveryIntervalFlag, "discovery-interval", node.DefaultDiscoveryInterval, "Polling interval for DHT discovery")
@@ -509,6 +543,7 @@ func main() {
joinCmd.Flags().DurationVar(&routerConnectTimeoutFlag, "router-connect-timeout", node.DefaultRouterConnectTimeout, "Timeout for dialing each router address")
joinCmd.Flags().BoolVar(&offlineAccessFlag, "offline-access", false, "Request OIDC offline access/refresh token for automatic renewal")
joinCmd.Flags().StringVar(&bootstrapTokenFlag, "bootstrap-token", "", "Pre-shared bootstrap token for enrollment")
+ joinCmd.Flags().StringVar(&bootstrapTokenPathFlag, "bootstrap-token-path", "", "Path to file containing the bootstrap token (recommended over --bootstrap-token)")
rootCmd.PersistentFlags().StringVar(&controlPlaneAddr, "control-plane", "", "Control plane URL")
rootCmd.PersistentFlags().StringVar(&configFile, "config", node.DefaultConfigFile, "Path to sam-node.yaml configuration file")
diff --git a/cmd/sam-console/main.go b/cmd/sam-console/main.go
index c2350dd6..de64687c 100644
--- a/cmd/sam-console/main.go
+++ b/cmd/sam-console/main.go
@@ -11,25 +11,30 @@ import (
"time"
"github.com/google/sam/internal/console"
+ "github.com/google/sam/internal/secrets"
)
func main() {
var (
controlPlaneURL = flag.String("control-plane", "http://localhost:8080", "URL of the SAM control plane")
- adminToken = flag.String("admin-token", "", "Admin token for control plane authentication")
+ adminTokenPath = flag.String("admin-token-path", "", "Path to file containing the admin token (or env SAM_ADMIN_TOKEN)")
bindAddr = flag.String("bind-addr", ":8081", "Address to bind the console server")
staticDir = flag.String("static-dir", "public", "Directory containing static frontend files")
basePath = flag.String("base-path", "", "Base path prefix for the console (e.g. /console)")
)
flag.Parse()
- if *adminToken == "" {
- log.Fatal("Admin token is required (via --admin-token)")
+ adminToken, err := secrets.FromPathOrEnv("admin-token", *adminTokenPath, "SAM_ADMIN_TOKEN")
+ if err != nil {
+ log.Fatalf("%v", err)
+ }
+ if adminToken == "" {
+ log.Fatal("Admin token is required (via --admin-token-path or env SAM_ADMIN_TOKEN)")
}
srv, err := console.NewServer(console.Config{
ControlPlaneURL: *controlPlaneURL,
- AdminToken: *adminToken,
+ AdminToken: adminToken,
StaticDir: *staticDir,
BasePath: *basePath,
})
diff --git a/cmd/sam-control-plane/main.go b/cmd/sam-control-plane/main.go
index 605c46e9..f39be7c7 100644
--- a/cmd/sam-control-plane/main.go
+++ b/cmd/sam-control-plane/main.go
@@ -24,6 +24,7 @@ import (
"github.com/google/sam/api"
"github.com/google/sam/internal/controlplane"
+ "github.com/google/sam/internal/secrets"
"github.com/google/sam/internal/storage"
golog "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
@@ -38,7 +39,7 @@ var (
keyRotationInterval time.Duration
keyGracePeriod time.Duration
leaseDuration time.Duration
- adminToken string
+ adminTokenPath string
insecureSkipTLSVerify bool
logLevel string
autoApproveEnrollment bool
@@ -67,6 +68,11 @@ func main() {
logger.Fatalf("OIDC issuer is required (use --issuer flag)")
}
+ adminToken, err := secrets.FromPathOrEnv("admin-token", adminTokenPath, "SAM_ADMIN_TOKEN")
+ if err != nil {
+ logger.Fatalf("%v", err)
+ }
+
var auds []string
for _, aud := range strings.Split(allowedAudiencesFlag, ",") {
aud = strings.TrimSpace(aud)
@@ -131,7 +137,7 @@ func main() {
rootCmd.Flags().DurationVar(&keyRotationInterval, "key-rotation-interval", 24*time.Hour, "Key rotation interval (e.g. 24h). 0 disables rotation.")
rootCmd.Flags().DurationVar(&keyGracePeriod, "key-grace-period", 1*time.Hour, "Key grace period for rotated keys.")
rootCmd.Flags().DurationVar(&leaseDuration, "lease-duration", 15*time.Minute, "Router lease registration TTL.")
- rootCmd.Flags().StringVar(&adminToken, "admin-token", "", "Token for authenticating policy REST API requests")
+ rootCmd.Flags().StringVar(&adminTokenPath, "admin-token-path", "", "Path to file containing the token for authenticating policy REST API requests (or env SAM_ADMIN_TOKEN)")
rootCmd.Flags().BoolVar(&insecureSkipTLSVerify, "insecure-skip-tls-verify", false, "Skip TLS verification for OIDC providers")
rootCmd.Flags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error)")
rootCmd.Flags().BoolVar(&autoApproveEnrollment, "auto-approve-enrollment", false, "Auto-approve valid bootstrap token enrollment requests")
diff --git a/cmd/sam-node/main.go b/cmd/sam-node/main.go
index 4f912171..8d827fd7 100644
--- a/cmd/sam-node/main.go
+++ b/cmd/sam-node/main.go
@@ -29,6 +29,7 @@ import (
"github.com/google/sam/api"
"github.com/google/sam/internal/node"
+ "github.com/google/sam/internal/secrets"
golog "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
@@ -79,6 +80,9 @@ var (
autoRelayBackoffFlag time.Duration
routerConnectTimeoutFlag time.Duration
apiTokenFlag string
+ apiTokenPathFlag string
+ bootstrapTokenPathFlag string
+ clientSecretPathFlag string
regionFlag string
tlsCertFlag string
tlsKeyFlag string
@@ -92,6 +96,30 @@ var (
var logger = golog.Logger("sam-node-cli")
+// resolveSecretFlag folds a --<name>-path file variant into its value flag
+// and warns when the secret was passed on the command line, where it leaks
+// via /proc/<pid>/cmdline, shell history, and pod specs.
+func resolveSecretFlag(name, value, path string) string {
+ if value != "" {
+ logger.Warnf("--%s passes a secret on the command line; prefer --%s-path", name, name)
+ }
+ secret, err := secrets.Resolve(name, value, path)
+ if err != nil {
+ logger.Fatalf("%v", err)
+ }
+ return secret
+}
+
+// resolveDaemonSecret resolves a secret that lives for the daemon's whole
+// lifetime: file (recommended) or environment variable, never a flag value.
+func resolveDaemonSecret(name, path, envVar string) string {
+ secret, err := secrets.FromPathOrEnv(name, path, envVar)
+ if err != nil {
+ logger.Fatalf("%v", err)
+ }
+ return secret
+}
+
func main() {
rootCmd := &cobra.Command{
Use: "sam-node",
@@ -122,6 +150,13 @@ func main() {
_ = golog.SetLogLevel("dht", "fatal")
_ = golog.SetLogLevel("dht/RtRefreshManager", "fatal")
+ apiTokenFlag = resolveDaemonSecret("api-token", apiTokenPathFlag, "SAM_API_TOKEN")
+ bootstrapTokenFlag = resolveSecretFlag("bootstrap-token", bootstrapTokenFlag, bootstrapTokenPathFlag)
+ clientSecretFlag = resolveDaemonSecret("client-secret", clientSecretPathFlag, "SAM_CLIENT_SECRET")
+ if jwtFlag != "" {
+ logger.Warn("--jwt passes a secret on the command line; prefer --jwt-path")
+ }
+
store, err := node.NewStore(resolveDataDir())
if err != nil {
logger.Fatalf("Failed to open store: %v", err)
@@ -434,6 +469,8 @@ func main() {
}
targetControlPlane = strings.TrimSuffix(targetControlPlane, "/")
+ bootstrapTokenFlag = resolveSecretFlag("bootstrap-token", bootstrapTokenFlag, bootstrapTokenPathFlag)
+
store, err := node.NewStore(resolveDataDir())
if err != nil {
logger.Fatalf("Failed to open store: %v", err)
@@ -559,8 +596,9 @@ func main() {
runCmd.Flags().StringVar(&jwtFlag, "jwt", "", "Pre-fetched JWT token")
runCmd.Flags().StringVar(&jwtPathFlag, "jwt-path", "", "Path to file containing JWT token")
runCmd.Flags().StringVar(&bootstrapTokenFlag, "bootstrap-token", "", "Pre-shared bootstrap token for enrollment")
+ runCmd.Flags().StringVar(&bootstrapTokenPathFlag, "bootstrap-token-path", "", "Path to file containing the bootstrap token (recommended over --bootstrap-token)")
runCmd.Flags().StringVar(&clientIDFlag, "client-id", "", "OIDC Client ID for M2M")
- runCmd.Flags().StringVar(&clientSecretFlag, "client-secret", "", "OIDC Client Secret for M2M")
+ runCmd.Flags().StringVar(&clientSecretPathFlag, "client-secret-path", "", "Path to file containing the OIDC client secret (or env SAM_CLIENT_SECRET)")
runCmd.Flags().StringVar(&controlPlanePublicKeyFlag, "control-plane-public-key", "", "Control plane public key (32-byte Hex)")
runCmd.Flags().StringVar(&bindAddrFlag, "bind-addr", "127.0.0.1:8080", "Local TCP address for the HTTP server (MCP and Sidecar API)")
runCmd.Flags().StringVar(&meshFlag, "mesh", node.DefaultMeshName, "Mesh federation name")
@@ -579,7 +617,8 @@ func main() {
joinCmd.Flags().DurationVar(&routerConnectTimeoutFlag, "router-connect-timeout", node.DefaultRouterConnectTimeout, "Timeout for dialing each router address")
joinCmd.Flags().BoolVar(&offlineAccessFlag, "offline-access", false, "Request OIDC offline access/refresh token for automatic renewal")
joinCmd.Flags().StringVar(&bootstrapTokenFlag, "bootstrap-token", "", "Pre-shared bootstrap token for enrollment")
- runCmd.Flags().StringVar(&apiTokenFlag, "api-token", "", "Static Bearer token for API authorization")
+ joinCmd.Flags().StringVar(&bootstrapTokenPathFlag, "bootstrap-token-path", "", "Path to file containing the bootstrap token (recommended over --bootstrap-token)")
+ runCmd.Flags().StringVar(&apiTokenPathFlag, "api-token-path", "", "Path to file containing the static Bearer token for API authorization (or env SAM_API_TOKEN)")
runCmd.Flags().StringVar(&regionFlag, "region", "", "Operator-declared region of this node: CONTINENT[-COUNTRY[-ZONE]] per ISO 3166 (e.g. \"EU\", \"EU-DE\", \"NA-US-CA\"); empty means no claim")
runCmd.Flags().StringVar(&tlsCertFlag, "tls-cert", "", "Path to TLS certificate for sidecar API")
runCmd.Flags().StringVar(&tlsKeyFlag, "tls-key", "", "Path to TLS key for sidecar API")
diff --git a/development/kind/node.template.yaml b/development/kind/node.template.yaml
index a8c34a3b..c7e8b445 100644
--- a/development/kind/node.template.yaml
+++ b/development/kind/node.template.yaml
@@ -26,11 +26,13 @@ spec:
- name: sam-node
image: sam-node:${IMAGE_TAG}
imagePullPolicy: IfNotPresent
+ env:
+ - name: SAM_API_TOKEN
+ value: "devtoken"
args:
- "run"
- "--control-plane=${CONTROL_PLANE_URL}"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=devtoken"
- "--bind-addr=0.0.0.0:8080"
- "--discovery-interval=200ms"
${CONFIG_ARG}
diff --git a/development/kind/run-local-node.sh b/development/kind/run-local-node.sh
index 07dd68ae..f56a31a2 100755
--- a/development/kind/run-local-node.sh
+++ b/development/kind/run-local-node.sh
@@ -29,12 +29,12 @@ JWT="$(kubectl --context "${KCTX}" -n "${NAMESPACE}" create token local-node-sa
echo "Enrolling local ./bin/sam-node into the mesh control plane at http://127.0.0.1:9090…"
echo " MCP/sidecar API on 127.0.0.1:9099"
+export SAM_API_TOKEN=devtoken
exec ./bin/sam-node run \
--control-plane http://127.0.0.1:9090 \
--jwt "${JWT}" \
--listen /ip4/0.0.0.0/tcp/0 \
--bind-addr 127.0.0.1:9099 \
- --api-token devtoken \
--discovery-interval 200ms \
--router-connect-timeout 10s \
"$@"
diff --git a/internal/node/mcp.go b/internal/node/mcp.go
index 7cc461de..7cf35de4 100644
--- a/internal/node/mcp.go
+++ b/internal/node/mcp.go
@@ -47,7 +47,7 @@ Other useful tools: discover_remote_services browses services by type (e.g. 'MCP
Tools on remote services are identified via the format 'scheme://service-name/tool-name' (where 'scheme://service-name' represents the well-known local address of the service, and 'tool-name' is the individual tool to execute on it. Tool names themselves can contain any characters).
-Inference services ('inference://...') are NOT called via call_remote_tool — they are plain OpenAI-compatible HTTP endpoints. Use discover_remote_services with type 'inference' to get each one's local_proxy_url, then send a normal HTTP request (e.g. POST <local_proxy_url>/chat/completions) directly to that URL: add header 'X-Sam-Authentication: Bearer <your local --api-token>' to authenticate to this node, and only add 'Authorization: Bearer <upstream-credential>' if the destination service itself requires its own credential — it passes straight through untouched and is never used to authenticate to this node.`
+Inference services ('inference://...') are NOT called via call_remote_tool — they are plain OpenAI-compatible HTTP endpoints. Use discover_remote_services with type 'inference' to get each one's local_proxy_url, then send a normal HTTP request (e.g. POST <local_proxy_url>/chat/completions) directly to that URL: add header 'X-Sam-Authentication: Bearer <your local node API token>' to authenticate to this node, and only add 'Authorization: Bearer <upstream-credential>' if the destination service itself requires its own credential — it passes straight through untouched and is never used to authenticate to this node.`
// NewMCPServer creates a new MCP server instance with all tools registered.
func NewMCPServer(node *SamNode) *mcp.Server {
diff --git a/internal/node/mcp_handlers.go b/internal/node/mcp_handlers.go
index dd9ee7d4..e859389a 100644
--- a/internal/node/mcp_handlers.go
+++ b/internal/node/mcp_handlers.go
@@ -64,7 +64,7 @@ func (n *SamNode) handleListLocalServices(ctx context.Context, req *mcp.CallTool
// service's local_proxy_url directly over HTTP. Inference services are plain
// OpenAI-compatible endpoints, never invoked via call_remote_tool.
const inferenceInvocationHint = `To call an inference service, send a normal HTTP request (e.g. POST <local_proxy_url>/chat/completions) directly to its "local_proxy_url" — do NOT use call_remote_tool. Required headers:
- - "X-Sam-Authentication: Bearer <your local --api-token>" authenticates you to this node; it is never forwarded off-node.
+ - "X-Sam-Authentication: Bearer <your local node API token>" authenticates you to this node; it is never forwarded off-node.
- "Authorization: Bearer <upstream-credential>" is OPTIONAL and only needed if the destination service itself requires its own credential (e.g. a provider API key); it passes straight through untouched and plays no part in authenticating to this node.`
// DiscoverRemoteServicesParams defines the parameters for the discover_remote_services tool.
diff --git a/internal/secrets/secrets.go b/internal/secrets/secrets.go
new file mode 100644
index 00000000..b93b791d
--- /dev/null
+++ b/internal/secrets/secrets.go
@@ -0,0 +1,71 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package secrets resolves secret configuration for SAM binaries.
+//
+// Daemon-lifetime secrets are never accepted as flag values: command lines
+// leak via /proc/<pid>/cmdline (world-readable), shell history, CI logs, and
+// pod specs. They are accepted from a file (--<name>-path, the recommended
+// production channel — e.g. a Kubernetes Secret volume) or an environment
+// variable (developer convenience; /proc/<pid>/environ is owner-only).
+package secrets
+
+import (
+ "fmt"
+ "os"
+ "strings"
+)
+
+// FromPathOrEnv resolves a daemon-lifetime secret: the file at path wins,
+// the environment variable is the fallback. File and env contents are
+// whitespace-trimmed; a configured but empty file is an error. An empty
+// result means the secret was not configured at all.
+func FromPathOrEnv(name, path, envVar string) (string, error) {
+ if path != "" {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return "", fmt.Errorf("read --%s-path: %w", name, err)
+ }
+ secret := strings.TrimSpace(string(data))
+ if secret == "" {
+ return "", fmt.Errorf("--%s-path file %s is empty", name, path)
+ }
+ return secret, nil
+ }
+ return strings.TrimSpace(os.Getenv(envVar)), nil
+}
+
+// Resolve returns a one-shot secret configured either directly (value) or
+// via a file (path). Setting both is an error; file contents are
+// whitespace-trimmed and must be non-empty. Direct values are tolerated for
+// short-lived interactive flows (e.g. enrollment); daemon-lifetime secrets
+// use FromPathOrEnv instead.
+func Resolve(name, value, path string) (string, error) {
+ switch {
+ case value != "" && path != "":
+ return "", fmt.Errorf("--%s and --%s-path are mutually exclusive", name, name)
+ case path != "":
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return "", fmt.Errorf("read --%s-path: %w", name, err)
+ }
+ secret := strings.TrimSpace(string(data))
+ if secret == "" {
+ return "", fmt.Errorf("--%s-path file %s is empty", name, path)
+ }
+ return secret, nil
+ default:
+ return value, nil
+ }
+}
diff --git a/internal/secrets/secrets_test.go b/internal/secrets/secrets_test.go
new file mode 100644
index 00000000..d58224f6
--- /dev/null
+++ b/internal/secrets/secrets_test.go
@@ -0,0 +1,106 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package secrets
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func TestResolve(t *testing.T) {
+ dir := t.TempDir()
+ tokenFile := filepath.Join(dir, "token")
+ if err := os.WriteFile(tokenFile, []byte(" s3cret\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ emptyFile := filepath.Join(dir, "empty")
+ if err := os.WriteFile(emptyFile, []byte(" \n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+
+ tests := []struct {
+ name string
+ value string
+ path string
+ want string
+ wantErr bool
+ }{
+ {"unset", "", "", "", false},
+ {"direct value", "tok", "", "tok", false},
+ {"file value trimmed", "", tokenFile, "s3cret", false},
+ {"both set", "tok", tokenFile, "", true},
+ {"missing file", "", filepath.Join(dir, "nope"), "", true},
+ {"empty file", "", emptyFile, "", true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := Resolve("api-token", tt.value, tt.path)
+ if (err != nil) != tt.wantErr {
+ t.Fatalf("Resolve: err=%v, wantErr=%v", err, tt.wantErr)
+ }
+ if got != tt.want {
+ t.Errorf("Resolve: got %q, want %q", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestFromPathOrEnv(t *testing.T) {
+ dir := t.TempDir()
+ tokenFile := filepath.Join(dir, "token")
+ if err := os.WriteFile(tokenFile, []byte("file-secret\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+
+ t.Run("file wins over env", func(t *testing.T) {
+ t.Setenv("SAM_TEST_SECRET", "env-secret")
+ got, err := FromPathOrEnv("api-token", tokenFile, "SAM_TEST_SECRET")
+ if err != nil || got != "file-secret" {
+ t.Errorf("got %q, %v; want file-secret", got, err)
+ }
+ })
+
+ t.Run("env fallback trimmed", func(t *testing.T) {
+ t.Setenv("SAM_TEST_SECRET", " env-secret \n")
+ got, err := FromPathOrEnv("api-token", "", "SAM_TEST_SECRET")
+ if err != nil || got != "env-secret" {
+ t.Errorf("got %q, %v; want env-secret", got, err)
+ }
+ })
+
+ t.Run("unset means unconfigured", func(t *testing.T) {
+ got, err := FromPathOrEnv("api-token", "", "SAM_TEST_SECRET_UNSET")
+ if err != nil || got != "" {
+ t.Errorf("got %q, %v; want empty", got, err)
+ }
+ })
+
+ t.Run("missing file is an error", func(t *testing.T) {
+ if _, err := FromPathOrEnv("api-token", filepath.Join(dir, "nope"), "SAM_TEST_SECRET"); err == nil {
+ t.Error("expected error for missing file")
+ }
+ })
+
+ t.Run("empty file is an error", func(t *testing.T) {
+ empty := filepath.Join(dir, "empty")
+ if err := os.WriteFile(empty, []byte("\n"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := FromPathOrEnv("api-token", empty, "SAM_TEST_SECRET"); err == nil {
+ t.Error("expected error for empty file")
+ }
+ })
+}
diff --git a/mobile/mobile_e2e.sh b/mobile/mobile_e2e.sh
index 1547508b..959f9e44 100755
--- a/mobile/mobile_e2e.sh
+++ b/mobile/mobile_e2e.sh
@@ -72,6 +72,7 @@ docker run --name sam-control-plane \
-p 37001:37001 \
--user "$(id -u):$(id -g)" \
-v /tmp/control-plane-data:/data \
+ -e SAM_ADMIN_TOKEN=secret-admin-token \
-d --rm \
sam-control-plane:local \
--bind-address 0.0.0.0:37001 \
@@ -79,7 +80,6 @@ docker run --name sam-control-plane \
--db-dsn /data/control-plane.db \
--issuer http://mock-oidc:18080 \
--allowed-audiences sam-mesh-audience,sam-control-plane-audience \
- --admin-token secret-admin-token \
--insecure-skip-tls-verify \
--log-level debug
@@ -139,6 +139,7 @@ docker run --name host-node \
--user "$(id -u):$(id -g)" \
-v /tmp/host-node-data:/data \
--add-host=host.docker.internal:host-gateway \
+ -e SAM_API_TOKEN=host-token \
-d --rm \
sam-node:local \
run \
@@ -146,7 +147,6 @@ docker run --name host-node \
--control-plane http://sam-control-plane:37001 \
--jwt "$HOST_JWT" \
--bind-addr 0.0.0.0:8081 \
- --api-token host-token \
--allow-loopback \
--enable-relay \
--log-level debug
diff --git a/site/content/docs/development/_index.md b/site/content/docs/development/_index.md
index 58a35df5..1421f478 100644
--- a/site/content/docs/development/_index.md
+++ b/site/content/docs/development/_index.md
@@ -54,7 +54,7 @@ export SAM_OIDC_SECRET=sam-secret
./bin/sam-router \
--control-plane=http://localhost:8080 \
--listen=/ip4/127.0.0.1/tcp/4501 \
- --api-token=devtoken
+ # api token via SAM_API_TOKEN env or --api-token-path
```
---
diff --git a/site/content/docs/development/kubernetes-deployment.md b/site/content/docs/development/kubernetes-deployment.md
index 44a73486..19f682ee 100644
--- a/site/content/docs/development/kubernetes-deployment.md
+++ b/site/content/docs/development/kubernetes-deployment.md
@@ -230,7 +230,7 @@ If you are using the **Mock OIDC Provider**, the node can fetch the token using
--control-plane "http://$CONTROL_PLANE_IP:9090" \
--oidc-issuer "http://$MOCK_IP:18080" \
--client-id "sam-mesh-audience" \
- --client-secret "sam-e2e-secret"
+ # client secret via SAM_CLIENT_SECRET env or --client-secret-path
```
If you are using **Google OIDC**, you must obtain a valid Google ID token for your user and pass it via the `--jwt` flag:
diff --git a/site/content/docs/development/testnet-validation.md b/site/content/docs/development/testnet-validation.md
index 07fb1ee6..9b509842 100644
--- a/site/content/docs/development/testnet-validation.md
+++ b/site/content/docs/development/testnet-validation.md
@@ -28,7 +28,7 @@ Before starting, ensure you have:
run --data-dir /data \
--control-plane https://bananas.sam-mesh.dev \
--bind-addr 0.0.0.0:8080 \
- --api-token secret-token \
+ # api token via SAM_API_TOKEN env or --api-token-path \
--log-level debug
```
diff --git a/site/content/docs/integrations/antigravity.md b/site/content/docs/integrations/antigravity.md
index fd3c8907..c3269109 100644
--- a/site/content/docs/integrations/antigravity.md
+++ b/site/content/docs/integrations/antigravity.md
@@ -10,7 +10,7 @@ Antigravity natively supports Streamable HTTP MCP servers via the `serverUrl` co
## Prerequisites
-- A running `sam-node` (default `http://localhost:8080`) and its `--api-token`.
+- A running `sam-node` (default `http://localhost:8080`) and its the node API token (`SAM_API_TOKEN` env or `--api-token-path`).
## Configuration
@@ -18,7 +18,7 @@ Edit your Antigravity MCP configuration file:
- Path: `~/.gemini/config/mcp_config.json`
-Add the node directly using its HTTP endpoint (replace `<YOUR_TOKEN>` with your `--api-token`):
+Add the node directly using its HTTP endpoint (replace `<YOUR_TOKEN>` with your the node API token (`SAM_API_TOKEN` env or `--api-token-path`)):
```json
{
@@ -46,5 +46,5 @@ The tool flow for Antigravity is as follows:
## Troubleshooting
-* **Connection errors**: verify `sam-node` is reachable at the configured URL and that the bearer token matches `--api-token`.
+* **Connection errors**: verify `sam-node` is reachable at the configured URL and that the bearer token matches the node API token (`SAM_API_TOKEN` env or `--api-token-path`).
* **Running `sam-node` in WSL or a container**: the `mcp-remote` bridge runs on the host, so that host must be able to reach the node's bind address. Bind the node to an address the host can reach (e.g. `0.0.0.0`).
diff --git a/site/content/docs/integrations/claude-code.md b/site/content/docs/integrations/claude-code.md
index d6bfda74..48613911 100644
--- a/site/content/docs/integrations/claude-code.md
+++ b/site/content/docs/integrations/claude-code.md
@@ -11,12 +11,12 @@ You can connect your `sam-node` to [Claude Code](https://claude.com/claude-code)
## Prerequisites
- A running `sam-node` with its local control-plane API reachable (default `http://localhost:8080`). See the [Quick Start](../quickstart/).
-- The `--api-token` you launched the node with.
+- The the node API token (`SAM_API_TOKEN` env or `--api-token-path`) you launched the node with.
- Claude Code installed (the `claude` CLI).
## Configuration
-Register the node as an HTTP MCP server. Replace `<YOUR_TOKEN>` with your `--api-token`:
+Register the node as an HTTP MCP server. Replace `<YOUR_TOKEN>` with your the node API token (`SAM_API_TOKEN` env or `--api-token-path`):
```bash
claude mcp add --transport http p2p-mesh-node \
@@ -65,7 +65,7 @@ Claude Code calls the tools `sam-node` exposes like any other tool. The flow mir
## Troubleshooting
-* **Connection shows failed / 401**: verify the `X-Sam-Authentication` header matches the node's `--api-token`.
+* **Connection shows failed / 401**: verify the `X-Sam-Authentication` header matches the node's the node API token (`SAM_API_TOKEN` env or `--api-token-path`).
* **Server unreachable**: confirm `sam-node` is listening (default `http://localhost:8080`).
* **Tools not visible**: MCP servers load at session start — restart Claude Code and check `/mcp`.
* **Remove the server**: `claude mcp remove p2p-mesh-node -s user` (match the scope you used to add it).
diff --git a/site/content/docs/integrations/claude-desktop.md b/site/content/docs/integrations/claude-desktop.md
index 022c8b23..98174c87 100644
--- a/site/content/docs/integrations/claude-desktop.md
+++ b/site/content/docs/integrations/claude-desktop.md
@@ -12,7 +12,7 @@ Claude Desktop's `claude_desktop_config.json` natively launches **stdio** MCP se
## Prerequisites
-- A running `sam-node` (default `http://localhost:8080`) and its `--api-token`.
+- A running `sam-node` (default `http://localhost:8080`) and its the node API token (`SAM_API_TOKEN` env or `--api-token-path`).
- [Node.js](https://nodejs.org) installed, which provides the `npx` used to run `mcp-remote`.
- Claude Desktop installed.
@@ -23,7 +23,7 @@ Edit `claude_desktop_config.json`:
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
-Add the node through the `mcp-remote` bridge (replace `<YOUR_TOKEN>` with your `--api-token`):
+Add the node through the `mcp-remote` bridge (replace `<YOUR_TOKEN>` with your the node API token (`SAM_API_TOKEN` env or `--api-token-path`)):
```json
{
@@ -59,6 +59,6 @@ The tool flow is identical to the [Claude Code guide](./claude-code/#discovering
## Troubleshooting
* **Tools don't appear**: fully quit and reopen Claude Desktop, and make sure npx is on your PATH. On Windows, you may need to use "command": "npx.cmd" instead of "command": "npx" in your configuration.
-* **Connection errors**: verify `sam-node` is reachable at the configured URL and that the bearer token matches `--api-token`.
+* **Connection errors**: verify `sam-node` is reachable at the configured URL and that the bearer token matches the node API token (`SAM_API_TOKEN` env or `--api-token-path`).
* **Running `sam-node` in WSL or a container**: the `mcp-remote` bridge runs on the Claude Desktop host, so that host must be able to reach the node's bind address. Bind the node to an address the host can reach (e.g. `0.0.0.0`) or set up port forwarding, rather than a container-only `127.0.0.1`.
* **Authentication header ignored**: if testing via the command line, the header value must be enclosed in quotes to be passed as a single argument (e.g., --header "Authorization: Bearer <YOUR_TOKEN>"). In the JSON configuration, they must remain as separate elements in the args array.
diff --git a/site/content/docs/integrations/openclaw.md b/site/content/docs/integrations/openclaw.md
index d5f82b8a..e81789ad 100644
--- a/site/content/docs/integrations/openclaw.md
+++ b/site/content/docs/integrations/openclaw.md
@@ -55,5 +55,5 @@ Because these tools are surfaced automatically, no remote tool needs to be regis
## Troubleshooting
* Connection Issues: Ensure `sam-node` is reachable at the configured URL (default `http://localhost:8080/mcp`).
-* Authentication: Double-check that the `X-Sam-Authentication` header matches the `--api-token` provided to your `sam-node`.
+* Authentication: Double-check that the `X-Sam-Authentication` header matches the the node API token (`SAM_API_TOKEN` env or `--api-token-path`) provided to your `sam-node`.
* Gateway Status: Use `openclaw status` to confirm the gateway is running and the MCP bridge is active.
diff --git a/site/content/docs/quickstart.md b/site/content/docs/quickstart.md
index 9c2c95e3..2e4510e1 100644
--- a/site/content/docs/quickstart.md
+++ b/site/content/docs/quickstart.md
@@ -88,11 +88,11 @@ docker run -it \
## 3. Run the Node
-Start your node in the background. We set a security `--api-token` to protect access to the local control plane API.
+Start your node in the background. We set a security API token (via the `SAM_API_TOKEN` environment variable or `--api-token-path` file) to protect access to the local control plane API. Tokens are never accepted as command-line values: they would be visible in process listings.
### Using the Binary
```bash
-sam-node run --bind-addr 127.0.0.1:8080 --api-token my-secret-token
+SAM_API_TOKEN=my-secret-token sam-node run --bind-addr 127.0.0.1:8080
```
You should see in the logs:
```text
@@ -112,8 +112,9 @@ docker run -d \
-p 5001:5001/udp \
-p 5002:5002 \
-p 8080:8080 \
+ -e SAM_API_TOKEN=my-secret-token \
ghcr.io/google/sam-node:latest \
- run --data-dir /data --bind-addr 0.0.0.0:8080 --api-token my-secret-token
+ run --data-dir /data --bind-addr 0.0.0.0:8080
```
Verify the node is running with `docker logs sam-node`.
diff --git a/site/content/docs/user/agent-usage.md b/site/content/docs/user/agent-usage.md
index 21cb0ef6..aad99904 100644
--- a/site/content/docs/user/agent-usage.md
+++ b/site/content/docs/user/agent-usage.md
@@ -28,7 +28,7 @@ sequenceDiagram
Node->>Node: Persist Biscuit in Local Store (agent.db)
Note over User,Agent: Phase 2: Agent Tool Invocation
- User->>Node: sam-node run --api-token "secret-key"
+ User->>Node: sam-node run (SAM_API_TOKEN="secret-key")
Node->>Node: Start local MCP server on 127.0.0.1:8080
Agent->>Node: Connect to local MCP (X-Sam-Authentication: Bearer "secret-key")
Agent->>Node: Call Remote P2P Tool
@@ -72,12 +72,12 @@ Once authorized, you start the node gateway. The gateway spins up a local Model
Run the node daemon, securing the local API endpoint with a custom token:
```bash
-sam-node run --api-token "my-agent-super-token-123" --bind-addr "127.0.0.1:8080"
+SAM_API_TOKEN="my-agent-super-token-123" sam-node run --bind-addr "127.0.0.1:8080"
```
### Key CLI Parameters
* `--bind-addr`: The local TCP address where the node's local HTTP server runs (default: `127.0.0.1:8080`).
-* `--api-token`: A security token required by any local AI agent attempting to connect to your node.
+* API token (`SAM_API_TOKEN` env or `--api-token-path` file): a security token required by any local AI agent attempting to connect to your node.
* `--data-dir`: Custom path to store configurations and Biscuit tokens (defaults to `~/.config/sam-mesh` or env `SAM_DATA_DIR`).
---
diff --git a/site/content/docs/user/control-plane-configuration.md b/site/content/docs/user/control-plane-configuration.md
index 15727865..725e7e38 100644
--- a/site/content/docs/user/control-plane-configuration.md
+++ b/site/content/docs/user/control-plane-configuration.md
@@ -21,7 +21,7 @@ The Control Plane is responsible for bridging user identities from trusted OIDC
| `--db-driver` | *None* | `sqlite` | Database driver (`sqlite` or `postgres`). |
| `--db-dsn` | *None* | `control-plane.db` | Database DSN/Connection URL (e.g. `postgres://user:pass@host:5432/db`). |
| `--allowed-audiences` | *None* | `sam-mesh-audience` | Comma-separated list of allowed JWT audiences. |
-| `--admin-token` | *None* | *None* | Secret token string required in the HTTP Header `Authorization: Bearer <token>` for admin operations. |
+| `--admin-token-path` (or env `SAM_ADMIN_TOKEN`) | *None* | *None* | File containing the secret token required in the HTTP Header `Authorization: Bearer <token>` for admin operations. |
| `--insecure-skip-tls-verify` | *None* | `false` | Set to `true` to skip certificate validation for development/testing OIDC providers. |
| `--key-rotation-interval` | *None* | `24h` | Key rotation interval (e.g. `24h`). `0s` disables rotation. |
| `--key-grace-period` | *None* | `1h` | Key grace period for rotated keys. |
@@ -124,7 +124,7 @@ Here is a script demonstrating how to boot both services in a secure development
--issuer "https://accounts.google.com" \
--allowed-audiences "my-google-client-id.apps.googleusercontent.com" \
--bind-address "0.0.0.0:8080" \
- --admin-token "super-secret-admin-token"
+ --admin-token-path /etc/sam/admin-token
# 2. Seed baseline policy via REST API
curl -X POST \
@@ -170,7 +170,7 @@ Nodes and Routers run a background task that periodically checks the remaining B
Administrators can immediately revoke any active session to disable a node's ability to renew its token.
* **Endpoint**: `POST /admin/revoke`
-* **Authentication**: Requires the `--admin-token` in the headers.
+* **Authentication**: Requires the admin token in the headers.
* **Payload**:
```json
{
diff --git a/site/content/docs/user/kubernetes-deployment.md b/site/content/docs/user/kubernetes-deployment.md
index 4b616a1f..206b3b30 100644
--- a/site/content/docs/user/kubernetes-deployment.md
+++ b/site/content/docs/user/kubernetes-deployment.md
@@ -301,7 +301,7 @@ spec:
- "--config=/etc/sam/sam-node.yaml"
- "--control-plane=http://sam-control-plane.sam.svc.cluster.local:8080"
- "--jwt-path=/var/run/secrets/tokens/sam-token"
- - "--api-token=secret-token"
+ - "--api-token-path=/var/run/secrets/sam/api-token"
volumeMounts:
- name: config-volume
mountPath: /etc/sam
diff --git a/site/content/docs/user/node-configuration.md b/site/content/docs/user/node-configuration.md
index 63da9edb..7fd6face 100644
--- a/site/content/docs/user/node-configuration.md
+++ b/site/content/docs/user/node-configuration.md
@@ -13,7 +13,7 @@ The `sam-node` acts as a local security gateway and tool proxy for AI agents. Wh
By default, `sam-node` runs without exposing any local tools to the mesh. To expose local tools or strictly enforce your node's network identity, you must create a Node configuration file and pass it to the daemon using the `--config` flag:
```bash
-sam-node run --config ./sam-node.yaml --api-token "secret"
+SAM_API_TOKEN="secret" sam-node run --config ./sam-node.yaml
```
### Configuration Schema
diff --git a/tests/e2e/auth_flows.bats b/tests/e2e/auth_flows.bats
index b6c78d6e..d0fd6fa3 100644
--- a/tests/e2e/auth_flows.bats
+++ b/tests/e2e/auth_flows.bats
@@ -136,11 +136,11 @@ teardown() {
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
-v "${token_vol}:/var/run/secrets/tokens" \
+ -e SAM_API_TOKEN="secret-token" \
"sam-node:local" \
run \
--control-plane "http://sam-control-plane:8080" \
- --jwt-path "/var/run/secrets/tokens/sa-token" \
- --api-token "secret-token"
+ --jwt-path "/var/run/secrets/tokens/sa-token"
MESH_CONTAINERS+=("${node_name}")
mesh_wait_for_log "${node_name}" "SAM Node Online" 20
diff --git a/tests/e2e/console.bats b/tests/e2e/console.bats
index eac43ddc..b256b96f 100644
--- a/tests/e2e/console.bats
+++ b/tests/e2e/console.bats
@@ -24,10 +24,10 @@ teardown() {
--name "${console_name}" \
--network "${MESH_NETWORK}" \
$(mesh_get_add_hosts) \
+ -e SAM_ADMIN_TOKEN="super-secret-admin-token" \
"sam-console:local" \
--control-plane "http://sam-control-plane:8080" \
- --bind-addr ":8081" \
- --admin-token "super-secret-admin-token"
+ --bind-addr ":8081"
MESH_CONTAINERS+=("${console_name}")
diff --git a/tests/e2e/lib/container_mesh.bash b/tests/e2e/lib/container_mesh.bash
index b2083c4e..8e7fad6c 100644
--- a/tests/e2e/lib/container_mesh.bash
+++ b/tests/e2e/lib/container_mesh.bash
@@ -337,6 +337,8 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
--network-alias "${name}" \
${add_hosts} \
"${mount_args[@]}" \
+ -e SAM_CLIENT_SECRET="sam-e2e-secret" \
+ -e SAM_API_TOKEN="secret-token" \
"${MESH_RUNTIME_IMAGE}" \
/usr/local/bin/sam-node run \
${flags} \
@@ -344,12 +346,10 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
--discovery-interval 2s \
--control-plane "http://sam-control-plane:8080" \
--client-id "sam-mesh-audience" \
- --client-secret "sam-e2e-secret" \
--oidc-issuer "http://mock-oidc:18080" \
--listen "/ip4/0.0.0.0/udp/5001/quic-v1" \
--listen "/ip4/0.0.0.0/tcp/5002" \
--bind-addr "0.0.0.0:8080" \
- --api-token "secret-token" \
--mesh "${MESH_PREFIX}" \
--dht-provider-addr-ttl 5s \
--dht-max-record-age 5s \
diff --git a/tests/integration/auth_test.go b/tests/integration/auth_test.go
index 82c615ba..71a3d34d 100644
--- a/tests/integration/auth_test.go
+++ b/tests/integration/auth_test.go
@@ -47,7 +47,7 @@ func TestNodeAuthEnforcementIntegration(t *testing.T) {
cmd := exec.Command(nodeBin, "run",
"--control-plane", mockRouterAddr,
"--data-dir", home,
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
"--jwt", "fake-jwt",
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", port),
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
diff --git a/tests/integration/catalog_test.go b/tests/integration/catalog_test.go
index 7c856a2c..f1aba91b 100644
--- a/tests/integration/catalog_test.go
+++ b/tests/integration/catalog_test.go
@@ -15,13 +15,25 @@ import (
"github.com/modelcontextprotocol/go-sdk/mcp"
)
+// tokenPath writes a secret to a temp file and returns its path: secret
+// flags only accept file (or env) input.
+func tokenPath(t *testing.T, secret string) string {
+ t.Helper()
+ p := filepath.Join(t.TempDir(), "secret")
+ if err := os.WriteFile(p, []byte(secret), 0o600); err != nil {
+ t.Fatalf("write secret file: %v", err)
+ }
+ return p
+}
+
func startBackgroundNode(t *testing.T, nodeBin string, routerAddr string, homeDir string, args ...string) *exec.Cmd {
t.Helper()
env := append(os.Environ(),
"HOME="+homeDir,
"XDG_CONFIG_HOME="+filepath.Join(homeDir, ".config"),
+ "SAM_API_TOKEN=test-token", // per-test overrides use --api-token-path, which wins
)
- allArgs := append([]string{"run", "--control-plane", routerAddr, "--jwt", "test-jwt", "--bind-addr", "127.0.0.1:0", "--api-token", "test-token", "--allow-loopback"}, args...)
+ allArgs := append([]string{"run", "--control-plane", routerAddr, "--jwt", "test-jwt", "--bind-addr", "127.0.0.1:0", "--allow-loopback"}, args...)
cmd := exec.Command(nodeBin, allArgs...)
cmd.Env = env
diff --git a/tests/integration/cuj_test.go b/tests/integration/cuj_test.go
index b0556bfc..e27609b2 100644
--- a/tests/integration/cuj_test.go
+++ b/tests/integration/cuj_test.go
@@ -44,7 +44,7 @@ func TestSamNodeRunWithManualTokenStarts(t *testing.T) {
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
"--listen", "/ip4/127.0.0.1/tcp/0",
"--bind-addr", "127.0.0.1:0",
- "--api-token", "dummy-token",
+ "--api-token-path", tokenPath(t, "dummy-token"),
)
if err != context.DeadlineExceeded {
t.Fatalf("expected run command to keep running until timeout, got: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
diff --git a/tests/integration/datapath_test.go b/tests/integration/datapath_test.go
index a64c8a4f..68105bcd 100644
--- a/tests/integration/datapath_test.go
+++ b/tests/integration/datapath_test.go
@@ -46,7 +46,7 @@ func TestIntegrationStdioDatapath(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Start Node B
@@ -56,7 +56,7 @@ func TestIntegrationStdioDatapath(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Resolve actual addresses from logs
@@ -171,7 +171,7 @@ func TestIntegrationHTTPDatapath(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Start Node B
@@ -181,7 +181,7 @@ func TestIntegrationHTTPDatapath(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Resolve actual addresses from logs
diff --git a/tests/integration/failover_test.go b/tests/integration/failover_test.go
index b692d6a8..b5aae59b 100644
--- a/tests/integration/failover_test.go
+++ b/tests/integration/failover_test.go
@@ -104,7 +104,7 @@ roles: {}
// 1. Start Control Plane A temporarily to generate keyring
cmdCP_A_temp := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", httpPortCP_A),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnA,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -129,7 +129,7 @@ roles: {}
// 3. Start CP A persistently
cmdCP_A := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", httpPortCP_A),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnA,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -161,7 +161,7 @@ roles: {}
// 5. Start CP B
cmdCP_B := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", httpPortCP_B),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnB,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -205,7 +205,7 @@ roles: {}
"--listen", "/ip4/127.0.0.1/tcp/0",
"--jwt-path", jwtPath,
"--bind-addr", "127.0.0.1:0",
- "--api-token", "dummy-token",
+ "--api-token-path", tokenPath(t, "dummy-token"),
"--allow-loopback",
"--monitor-bootstrap", "1s",
"--monitor-interval", "1s",
diff --git a/tests/integration/federation_test.go b/tests/integration/federation_test.go
index f6651fb5..6c767035 100644
--- a/tests/integration/federation_test.go
+++ b/tests/integration/federation_test.go
@@ -118,7 +118,7 @@ roles:
// to ensure concurrent node enrollment writes do not trigger SQLITE_BUSY locking failures.
cmdCP := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", cpPort),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", filepath.Join(tmpDir, "cp-keys.db")+"?_pragma=journal_mode(DELETE)&_pragma=busy_timeout(5000)",
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -197,7 +197,7 @@ roles:
nodeACmd := exec.Command(nodeBin, "run", "--control-plane", fmt.Sprintf("http://127.0.0.1:%d", cpPort),
"--data-dir", filepath.Join(tmpDir, "nodeA"),
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortA),
- "--api-token", "tokenA",
+ "--api-token-path", tokenPath(t, "tokenA"),
"--jwt", nodeJWT,
"--listen", "/ip4/127.0.0.1/tcp/0",
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
@@ -219,7 +219,7 @@ roles:
nodeBCmd := exec.Command(nodeBin, "run", "--control-plane", fmt.Sprintf("http://127.0.0.1:%d", cpPort),
"--data-dir", filepath.Join(tmpDir, "nodeB"),
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortB),
- "--api-token", "tokenB",
+ "--api-token-path", tokenPath(t, "tokenB"),
"--jwt", nodeJWT,
"--listen", "/ip4/127.0.0.1/tcp/0",
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
diff --git a/tests/integration/local_policy_test.go b/tests/integration/local_policy_test.go
index c5d743bf..49633830 100644
--- a/tests/integration/local_policy_test.go
+++ b/tests/integration/local_policy_test.go
@@ -60,7 +60,7 @@ attenuation:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeB,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortB),
- "--api-token", apiTokenB,
+ "--api-token-path", tokenPath(t, apiTokenB),
"--jwt", mintToken(map[string]interface{}{
"sub": "nodeB-user",
"roles": []string{api.RoleNode},
@@ -104,7 +104,7 @@ attenuation:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeA,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortA),
- "--api-token", apiTokenA,
+ "--api-token-path", tokenPath(t, apiTokenA),
"--jwt", mintToken(map[string]interface{}{
"sub": "unprivileged-user",
"roles": []string{api.RoleNode},
@@ -205,7 +205,7 @@ attenuation:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeB,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortB),
- "--api-token", apiTokenB,
+ "--api-token-path", tokenPath(t, apiTokenB),
"--jwt", mintToken(map[string]interface{}{
"sub": "nodeB-user",
"roles": []string{api.RoleNode},
@@ -249,7 +249,7 @@ attenuation:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeA,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortA),
- "--api-token", apiTokenA,
+ "--api-token-path", tokenPath(t, apiTokenA),
"--jwt", mintToken(map[string]interface{}{
"sub": "client-user",
"roles": []string{api.RoleNode},
diff --git a/tests/integration/login_test.go b/tests/integration/login_test.go
index 7d8ad9ae..c3179ac1 100644
--- a/tests/integration/login_test.go
+++ b/tests/integration/login_test.go
@@ -106,7 +106,7 @@ func TestSamNodeJoin(t *testing.T) {
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
"--listen", "/ip4/127.0.0.1/tcp/0",
"--bind-addr", "127.0.0.1:0",
- "--api-token", "dummy-token",
+ "--api-token-path", tokenPath(t, "dummy-token"),
)
if err != context.DeadlineExceeded {
t.Fatalf("expected run command to keep running, got: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
diff --git a/tests/integration/mcp_local_tools_test.go b/tests/integration/mcp_local_tools_test.go
index 221b3475..5898a725 100644
--- a/tests/integration/mcp_local_tools_test.go
+++ b/tests/integration/mcp_local_tools_test.go
@@ -63,7 +63,7 @@ roles: {}
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
"--listen", "/ip4/127.0.0.1/tcp/0",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
"--jwt", nodeJWT,
)
@@ -73,7 +73,7 @@ roles: {}
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
"--listen", "/ip4/127.0.0.1/tcp/0",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
"--jwt", nodeJWT,
)
diff --git a/tests/integration/minimal_helpers_test.go b/tests/integration/minimal_helpers_test.go
index b73249a7..7c15a2f0 100644
--- a/tests/integration/minimal_helpers_test.go
+++ b/tests/integration/minimal_helpers_test.go
@@ -469,7 +469,7 @@ func startControlPlaneAndRouter(t *testing.T, tmpDir string, oidcURL string, min
"--db-dsn", filepath.Join(tmpDir, "cp-keys.db"),
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
)
cpCmd.Stdout = os.Stdout
cpCmd.Stderr = os.Stderr
diff --git a/tests/integration/multimaster_test.go b/tests/integration/multimaster_test.go
index 01f6eef4..32e543c5 100644
--- a/tests/integration/multimaster_test.go
+++ b/tests/integration/multimaster_test.go
@@ -86,7 +86,7 @@ roles: {}
// 1. Start Control Plane A temporarily to generate keyring
cmdCP_A_temp := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", portA),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnA,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -115,7 +115,7 @@ roles: {}
// 3. Start CP A persistently
cmdCP_A := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", portA),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnA,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -153,7 +153,7 @@ roles: {}
// 5. Start Control Plane B (sharing CP A's keys)
cmdCP_B := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", portB),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", dsnB,
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
diff --git a/tests/integration/policy_permutations_test.go b/tests/integration/policy_permutations_test.go
index 25db06ac..742e2d7a 100644
--- a/tests/integration/policy_permutations_test.go
+++ b/tests/integration/policy_permutations_test.go
@@ -151,7 +151,7 @@ services:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeB,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortB),
- "--api-token", apiTokenB,
+ "--api-token-path", tokenPath(t, apiTokenB),
"--jwt", mintToken(map[string]interface{}{
"sub": "bob-subject",
"roles": []string{api.RoleNode},
@@ -247,7 +247,7 @@ services:
"--control-plane", fmt.Sprintf("http://127.0.0.1:%d", httpPortCP),
"--data-dir", homeA,
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", apiPortA),
- "--api-token", apiTokenA,
+ "--api-token-path", tokenPath(t, apiTokenA),
"--jwt", jwtA,
"--listen", "/ip4/127.0.0.1/tcp/0",
"--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
diff --git a/tests/integration/proxy_test.go b/tests/integration/proxy_test.go
index 72a32493..d54cb08c 100644
--- a/tests/integration/proxy_test.go
+++ b/tests/integration/proxy_test.go
@@ -83,7 +83,7 @@ func TestSamNodeRunWithStoredIdentity(t *testing.T) {
"run", "--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
"--listen", "/ip4/127.0.0.1/tcp/0",
"--bind-addr", "127.0.0.1:0",
- "--api-token", "dummy-token",
+ "--api-token-path", tokenPath(t, "dummy-token"),
"--data-dir", configDir,
)
if err != context.DeadlineExceeded {
diff --git a/tests/integration/pubsub_test.go b/tests/integration/pubsub_test.go
index b997a484..d16edf18 100644
--- a/tests/integration/pubsub_test.go
+++ b/tests/integration/pubsub_test.go
@@ -44,7 +44,7 @@ func TestPubSubTools(t *testing.T) {
// Start Node 1
env1 := append(os.Environ(), "HOME="+tmpHome1, "XDG_CONFIG_HOME="+filepath.Join(tmpHome1, ".config"))
- cmd1 := exec.CommandContext(ctx, nodeBin, "run", "--control-plane", routerAddr, "--bind-addr", "127.0.0.1:0", "--listen", "/ip4/127.0.0.1/udp/5003/quic-v1", "--listen", "/ip4/127.0.0.1/tcp/5004", "--jwt", "dummy-token", "--log-level", "debug", "--discovery-interval", "100ms", "--api-token", "test-token", "--allow-loopback")
+ cmd1 := exec.CommandContext(ctx, nodeBin, "run", "--control-plane", routerAddr, "--bind-addr", "127.0.0.1:0", "--listen", "/ip4/127.0.0.1/udp/5003/quic-v1", "--listen", "/ip4/127.0.0.1/tcp/5004", "--jwt", "dummy-token", "--log-level", "debug", "--discovery-interval", "100ms", "--api-token-path", tokenPath(t, "test-token"), "--allow-loopback")
cmd1.Env = env1
logFile1, err := os.Create(filepath.Join(tmpHome1, "node1.log"))
if err != nil {
@@ -59,7 +59,7 @@ func TestPubSubTools(t *testing.T) {
// Start Node 2
env2 := append(os.Environ(), "HOME="+tmpHome2, "XDG_CONFIG_HOME="+filepath.Join(tmpHome2, ".config"))
- cmd2 := exec.CommandContext(ctx, nodeBin, "run", "--control-plane", routerAddr, "--bind-addr", "127.0.0.1:0", "--listen", "/ip4/127.0.0.1/udp/5005/quic-v1", "--listen", "/ip4/127.0.0.1/tcp/5006", "--jwt", "dummy-token", "--log-level", "debug", "--discovery-interval", "100ms", "--api-token", "test-token", "--allow-loopback")
+ cmd2 := exec.CommandContext(ctx, nodeBin, "run", "--control-plane", routerAddr, "--bind-addr", "127.0.0.1:0", "--listen", "/ip4/127.0.0.1/udp/5005/quic-v1", "--listen", "/ip4/127.0.0.1/tcp/5006", "--jwt", "dummy-token", "--log-level", "debug", "--discovery-interval", "100ms", "--api-token-path", tokenPath(t, "test-token"), "--allow-loopback")
cmd2.Env = env2
logFile2, err := os.Create(filepath.Join(tmpHome2, "node2.log"))
if err != nil {
diff --git a/tests/integration/revocation_test.go b/tests/integration/revocation_test.go
index 24e4a071..0741dbe0 100644
--- a/tests/integration/revocation_test.go
+++ b/tests/integration/revocation_test.go
@@ -65,7 +65,7 @@ roles:
// 2. Start Control Plane (PostgreSQL is used in GKE/Kind, but SQLite is completely fine here for in-process integration test speed)
cpCmd := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", cpPort),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", filepath.Join(tmpDir, "cp-keys.db"),
"--issuer", oidcURL,
"--insecure-skip-tls-verify",
@@ -130,7 +130,7 @@ roles:
"--listen", "/ip4/127.0.0.1/tcp/0",
"--allow-loopback",
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", node1ApiPort),
- "--api-token", "node1-token",
+ "--api-token-path", tokenPath(t, "node1-token"),
"--log-level", "debug",
)
node1Cmd.Env = append(os.Environ(), "HOME="+node1Home, "XDG_CONFIG_HOME="+filepath.Join(node1Home, ".config"))
@@ -160,7 +160,7 @@ roles:
"--listen", "/ip4/127.0.0.1/tcp/0",
"--allow-loopback",
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", node2ApiPort),
- "--api-token", "node2-token",
+ "--api-token-path", tokenPath(t, "node2-token"),
"--log-level", "debug",
)
node2Cmd.Env = append(os.Environ(), "HOME="+node2Home, "XDG_CONFIG_HOME="+filepath.Join(node2Home, ".config"))
diff --git a/tests/integration/rotation_test.go b/tests/integration/rotation_test.go
index 74178d82..4707bc56 100644
--- a/tests/integration/rotation_test.go
+++ b/tests/integration/rotation_test.go
@@ -60,7 +60,7 @@ roles:
// 2. Start Control Plane with aggressive key rotation
cpCmd := exec.Command(cpBin,
"--bind-address", fmt.Sprintf("127.0.0.1:%d", cpPort),
- "--admin-token", "test-admin-token",
+ "--admin-token-path", tokenPath(t, "test-admin-token"),
"--db-dsn", filepath.Join(tmpDir, "cp-keys.db"),
"--issuer", oidcURL,
"--key-rotation-interval", "4s",
@@ -132,7 +132,7 @@ roles:
"--listen", "/ip4/127.0.0.1/tcp/0",
"--allow-loopback",
"--bind-addr", fmt.Sprintf("127.0.0.1:%d", nodeApiPort),
- "--api-token", "dummy-token",
+ "--api-token-path", tokenPath(t, "dummy-token"),
"--log-level", "debug",
)
nodeCmd.Env = nodeEnv
diff --git a/tests/integration/service_discovery_test.go b/tests/integration/service_discovery_test.go
index 9d48ef86..90573885 100644
--- a/tests/integration/service_discovery_test.go
+++ b/tests/integration/service_discovery_test.go
@@ -48,7 +48,7 @@ func TestServiceDiscovery(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Start Node B
@@ -58,7 +58,7 @@ func TestServiceDiscovery(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Resolve actual addresses from logs
@@ -152,7 +152,7 @@ func TestServiceDiscoveryStreaming(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Start Node B
@@ -162,7 +162,7 @@ func TestServiceDiscoveryStreaming(t *testing.T) {
"--listen", "/ip4/127.0.0.1/tcp/0",
"--discovery-interval", "100ms",
"--bind-addr", "127.0.0.1:0",
- "--api-token", apiToken,
+ "--api-token-path", tokenPath(t, apiToken),
)
// Resolve actual addresses from logs