Skip to content

Agent Mesh

release readiness: bounded drain, one JSON style, --version everywhere, console warning

Antonio Ojea66eaa7ffc153
diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml
index 90804bb3..d7ef6187 100644
--- a/.github/workflows/deploy.yaml
+++ b/.github/workflows/deploy.yaml
@@ -68,6 +68,7 @@ jobs:
with:
context: .
file: Dockerfile.sam-control-plane
+ build-args: VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
platforms: ${{ github.ref_type == 'tag' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: true
tags: ${{ steps.meta-cp.outputs.tags }}
@@ -136,6 +137,7 @@ jobs:
with:
context: .
file: Dockerfile.sam-console
+ build-args: VERSION=${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
platforms: ${{ github.ref_type == 'tag' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: true
tags: ${{ steps.meta-console.outputs.tags }}
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 6a3ed65d..c8bc8e0f 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -31,7 +31,7 @@ builds:
- amd64
- arm64
ldflags:
- - -s -w
+ - -s -w -X github.com/google/sam/internal/version.Version={{ .Tag }}
- id: sam-router
main: ./cmd/sam-router
binary: sam-router
@@ -59,7 +59,7 @@ builds:
- amd64
- arm64
ldflags:
- - -s -w
+ - -s -w -X github.com/google/sam/internal/version.Version={{ .Tag }}
- id: sam-console
main: ./cmd/sam-console
binary: sam-console
@@ -73,7 +73,7 @@ builds:
- amd64
- arm64
ldflags:
- - -s -w
+ - -s -w -X github.com/google/sam/internal/version.Version={{ .Tag }}
- id: sam-one
main: ./cmd/sam-one
binary: sam-one
diff --git a/Dockerfile.sam-console b/Dockerfile.sam-console
index dd807dbd..84c0ee98 100644
--- a/Dockerfile.sam-console
+++ b/Dockerfile.sam-console
@@ -5,7 +5,8 @@ COPY go.mod go.sum ./
RUN go mod download
COPY . .
-RUN CGO_ENABLED=0 go build -o /bin/sam-console ./cmd/sam-console
+ARG VERSION=devel
+RUN CGO_ENABLED=0 go build -buildvcs=false -ldflags="-X github.com/google/sam/internal/version.Version=${VERSION}" -o /bin/sam-console ./cmd/sam-console
FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab
diff --git a/Dockerfile.sam-control-plane b/Dockerfile.sam-control-plane
index f7a92eab..21c39c3d 100644
--- a/Dockerfile.sam-control-plane
+++ b/Dockerfile.sam-control-plane
@@ -4,7 +4,8 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
-RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -o sam-control-plane ./cmd/sam-control-plane
+ARG VERSION=devel
+RUN CGO_ENABLED=0 GOOS=linux go build -buildvcs=false -ldflags="-X github.com/google/sam/internal/version.Version=${VERSION}" -o sam-control-plane ./cmd/sam-control-plane
# Pre-create the sqlite data dir owned by the nonroot UID so that a fresh
# named/anonymous volume mounted over it inherits writable ownership instead
# of defaulting to root.
diff --git a/Makefile b/Makefile
index 6312e16c..6a135644 100644
--- a/Makefile
+++ b/Makefile
@@ -259,7 +259,7 @@ update:
go mod tidy
docker-build-control-plane:
- docker build --load -t sam-control-plane:local -f Dockerfile.sam-control-plane .
+ docker build --load --build-arg VERSION="$(VERSION)" -t sam-control-plane:local -f Dockerfile.sam-control-plane .
docker-build-router:
docker build --load --build-arg VERSION="$(VERSION)" -t sam-router:local -f Dockerfile.sam-router .
@@ -274,7 +274,7 @@ docker-build-e2e-runtime:
docker build --load -t sam-e2e-runtime:local -f tests/e2e/docker/Dockerfile.sam-runtime .
docker-build-sam-console:
- docker build --load -t sam-console:local -f Dockerfile.sam-console .
+ docker build --load --build-arg VERSION="$(VERSION)" -t sam-console:local -f Dockerfile.sam-console .
docker-build: docker-build-control-plane docker-build-router docker-build-node docker-build-mock-oidc docker-build-e2e-runtime docker-build-sam-console
diff --git a/cmd/mcp-client/main.go b/cmd/mcp-client/main.go
index 39d89b24..182d5813 100644
--- a/cmd/mcp-client/main.go
+++ b/cmd/mcp-client/main.go
@@ -32,6 +32,7 @@ import (
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/google/sam/api"
+ "github.com/google/sam/internal/version"
)
func main() {
@@ -42,7 +43,12 @@ func main() {
listTools := flag.Bool("list", false, "List available tools and exit")
streamOpt := flag.Bool("stream", false, "Enable streaming mode for service discovery HTTP API")
tokenOpt := flag.String("token", "", "Authorization Bearer token for protected sidecar endpoints")
+ showVersion := flag.Bool("version", false, "Print the version and exit")
flag.Parse()
+ if *showVersion {
+ fmt.Println(version.String())
+ return
+ }
if *serverURL == "" {
log.Fatal("Must specify -url")
@@ -143,7 +149,7 @@ func main() {
// Create MCP client
client := mcp.NewClient(&mcp.Implementation{
Name: "mcp-test-client",
- Version: "0.1.0",
+ Version: version.String(),
}, nil)
// Connect to server using the URL
diff --git a/cmd/sam-console/main.go b/cmd/sam-console/main.go
index b96056a6..e431f2c0 100644
--- a/cmd/sam-console/main.go
+++ b/cmd/sam-console/main.go
@@ -17,6 +17,7 @@ package main
import (
"context"
"flag"
+ "fmt"
"log"
"net/http"
"os"
@@ -26,6 +27,7 @@ import (
"github.com/google/sam/internal/console"
"github.com/google/sam/internal/secrets"
+ "github.com/google/sam/internal/version"
)
func main() {
@@ -36,8 +38,13 @@ func main() {
staticDir = flag.String("static-dir", "", "Directory containing static frontend files (default: assets embedded in the binary)")
basePath = flag.String("base-path", "", "Base path prefix for the console (e.g. /console)")
externalURL = flag.String("external-url", "", "Origin browsers reach this console on, e.g. https://console.example. Sets the OIDC redirect_uri and cookie Secure flag instead of trusting the Host and X-Forwarded-Proto headers")
+ showVersion = flag.Bool("version", false, "Print the version and exit")
)
flag.Parse()
+ if *showVersion {
+ fmt.Println(version.String())
+ return
+ }
adminToken, err := secrets.FromPathOrEnv("admin-token", *adminTokenPath, "SAM_ADMIN_TOKEN")
if err != nil {
@@ -46,6 +53,9 @@ func main() {
if adminToken == "" {
log.Fatal("Admin token is required (via --admin-token-path or env SAM_ADMIN_TOKEN)")
}
+ if *externalURL == "" {
+ log.Print("WARNING: --external-url is not set; the OIDC redirect_uri and the session cookie's Secure flag follow the Host and X-Forwarded-Proto request headers, which a client controls. Set --external-url when the console is reachable beyond localhost.")
+ }
srv, err := console.NewServer(console.Config{
ControlPlaneURL: *controlPlaneURL,
diff --git a/cmd/sam-control-plane/main.go b/cmd/sam-control-plane/main.go
index aa3e1208..c84c038b 100644
--- a/cmd/sam-control-plane/main.go
+++ b/cmd/sam-control-plane/main.go
@@ -27,6 +27,7 @@ import (
"github.com/google/sam/internal/controlplane"
"github.com/google/sam/internal/secrets"
"github.com/google/sam/internal/storage"
+ "github.com/google/sam/internal/version"
golog "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/spf13/cobra"
@@ -60,8 +61,9 @@ var logger = golog.Logger("sam-control-plane-cli")
func main() {
rootCmd := &cobra.Command{
- Use: "sam-control-plane",
- Short: "Sovereign Agent Mesh - Control Plane",
+ Use: "sam-control-plane",
+ Short: "Sovereign Agent Mesh - Control Plane",
+ Version: version.String(),
// Resolve the DB DSN (may embed a password) before any subcommand runs.
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
resolved, err := secrets.FromPathOrEnv("db-dsn", dbDSNPath, "SAM_DB_DSN")
diff --git a/cmd/sam-one/main.go b/cmd/sam-one/main.go
index af489c90..1c9e8775 100644
--- a/cmd/sam-one/main.go
+++ b/cmd/sam-one/main.go
@@ -31,6 +31,7 @@ import (
"github.com/google/sam/api"
"github.com/google/sam/internal/standalone"
"github.com/google/sam/internal/tunnel"
+ "github.com/google/sam/internal/version"
golog "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
)
@@ -68,8 +69,9 @@ func main() {
)
rootCmd := &cobra.Command{
- Use: "sam-one",
- Short: "Sovereign Agent Mesh - all-in-one standalone server",
+ Use: "sam-one",
+ Short: "Sovereign Agent Mesh - all-in-one standalone server",
+ Version: version.String(),
Run: func(cmd *cobra.Command, args []string) {
if os.Getenv("LOG_FORMAT") == "json" {
_ = os.Setenv("GOLOG_LOG_FMT", "json")
diff --git a/cmd/sam-router/main.go b/cmd/sam-router/main.go
index 168ea3a0..25863e92 100644
--- a/cmd/sam-router/main.go
+++ b/cmd/sam-router/main.go
@@ -22,6 +22,7 @@ import (
"time"
"github.com/google/sam/internal/router"
+ "github.com/google/sam/internal/version"
golog "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
)
@@ -54,8 +55,9 @@ var logger = golog.Logger("sam-router-cli")
func main() {
rootCmd := &cobra.Command{
- Use: "sam-router",
- Short: "Sovereign Agent Mesh - libp2p Router Node",
+ Use: "sam-router",
+ Short: "Sovereign Agent Mesh - libp2p Router Node",
+ Version: version.String(),
Run: func(cmd *cobra.Command, args []string) {
// Initialize logging
if os.Getenv("LOG_FORMAT") == "json" {
diff --git a/internal/controlplane/server.go b/internal/controlplane/server.go
index 31b65b72..df8389f9 100644
--- a/internal/controlplane/server.go
+++ b/internal/controlplane/server.go
@@ -1768,7 +1768,11 @@ func (s *Server) Close() error {
var errs []error
if s.httpServer != nil {
- if err := s.httpServer.Shutdown(context.Background()); err != nil {
+ // Bounded: a stuck connection must not hold the drain past what the
+ // orchestrator allows before it kills the process anyway.
+ ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
+ defer cancel()
+ if err := s.httpServer.Shutdown(ctx); err != nil {
errs = append(errs, err)
}
}
@@ -1776,6 +1780,10 @@ func (s *Server) Close() error {
return errors.Join(errs...)
}
+// shutdownTimeout bounds the HTTP drain in Close; it stays under the 30s
+// Kubernetes grants a pod by default.
+const shutdownTimeout = 20 * time.Second
+
// Addr returns the network address the server is listening on.
func (s *Server) Addr() string {
if s.listener == nil {
diff --git a/internal/node/identity_evidence.go b/internal/node/identity_evidence.go
index 9a435c85..b489cfe6 100644
--- a/internal/node/identity_evidence.go
+++ b/internal/node/identity_evidence.go
@@ -112,7 +112,7 @@ func requireIdentityEvidenceTransport(next http.Handler) http.Handler {
}
func writeEvidenceProtoJSON(w http.ResponseWriter, status int, value proto.Message) {
- body, err := protojson.Marshal(value)
+ body, err := protojson.MarshalOptions{UseProtoNames: true}.Marshal(value)
if err != nil {
logger.Errorf("[IdentityEvidence] Failed to encode response: %v", err)
writeEvidenceError(w, http.StatusInternalServerError, "Failed to encode response")