Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
controlplane: add --oidc-client-id to decouple client id from audience
Antonio Ojea811f496a1a05
diff --git a/cmd/sam-control-plane/main.go b/cmd/sam-control-plane/main.goindex b70728f4..8a9d077d 100644--- a/cmd/sam-control-plane/main.go+++ b/cmd/sam-control-plane/main.go@@ -36,6 +36,7 @@ var (dbDSN stringdbDSNPath stringoidcIssuer string+ oidcClientID stringallowedAudiencesFlag stringkeyRotationInterval time.DurationkeyGracePeriod time.Duration@@ -112,6 +113,7 @@ func main() {DriverName: dbDriver,DataSourceName: dbDSN,OIDCIssuer: oidcIssuer,+ OIDCClientID: oidcClientID,AllowedAudiences: auds,LeaseDuration: leaseDuration,KeyRotationInterval: keyRotationInterval,@@ -146,6 +148,7 @@ func main() {rootCmd.PersistentFlags().StringVar(&dbDSN, "db-dsn", "control-plane.db", "Database DSN/Connection URL (avoid for postgres: embeds a password; prefer --db-dsn-path or SAM_DB_DSN)")rootCmd.PersistentFlags().StringVar(&dbDSNPath, "db-dsn-path", "", "Path to file containing the database DSN/Connection URL (overrides --db-dsn; or env SAM_DB_DSN)")rootCmd.Flags().StringVar(&oidcIssuer, "issuer", "", "OIDC Issuer URL (comma-separated)")+ rootCmd.Flags().StringVar(&oidcClientID, "oidc-client-id", "", "OAuth client ID advertised to joining nodes via /info (defaults to the first allowed audience)")rootCmd.Flags().StringVar(&allowedAudiencesFlag, "allowed-audiences", api.DefaultAudience, "Comma-separated list of allowed OIDC audiences")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.")diff --git a/internal/controlplane/config.go b/internal/controlplane/config.goindex f7c8f9e8..bc78fce4 100644--- a/internal/controlplane/config.go+++ b/internal/controlplane/config.go@@ -25,6 +25,7 @@ type Options struct {DriverName stringDataSourceName stringOIDCIssuer string+ OIDCClientID string // OAuth client id advertised via /info; defaults to the first allowed audienceAllowedAudiences []stringLeaseDuration time.DurationKeyRotationInterval time.Durationdiff --git a/internal/controlplane/server.go b/internal/controlplane/server.goindex 2af3583d..547fd2e3 100644--- a/internal/controlplane/server.go+++ b/internal/controlplane/server.go@@ -368,6 +368,13 @@ func (s *Server) HandleInfo(w http.ResponseWriter, r *http.Request) {aud = s.config.AllowedAudiences[0]}+ // aud == client_id only holds for id_token-model IdPs (dex, Google); an+ // explicit client id supports providers where the two differ.+ clientID := s.config.OIDCClientID+ if clientID == "" {+ clientID = aud+ }+// Fetch active routersactiveRouters, err := s.store.GetActiveRouters(r.Context())if err != nil {@@ -383,7 +390,7 @@ func (s *Server) HandleInfo(w http.ResponseWriter, r *http.Request) {resp := &api.ControlPlaneInfoResponse{OidcIssuer: issuer,- ClientId: aud,+ ClientId: clientID,Audience: aud,RouterAddresses: routerAddrs, // Reused this field for back-compatibility with bootstrap routers list}diff --git a/internal/controlplane/server_test.go b/internal/controlplane/server_test.goindex 0ff0e7e4..f50efb63 100644--- a/internal/controlplane/server_test.go+++ b/internal/controlplane/server_test.go@@ -202,6 +202,41 @@ func TestControlPlaneBasic(t *testing.T) {t.Errorf("expected 0 active routers, got %d", len(info.RouterAddresses))}+ // With an explicit OIDC client id, /info must advertise it while the+ // audience stays the first allowed audience.+ t.Run("explicit oidc client id", func(t *testing.T) {+ dbPath := filepath.Join(t.TempDir(), "cp-clientid.db")+ st, err := storage.NewSQLStore("sqlite", dbPath)+ if err != nil {+ t.Fatalf("failed to create store: %v", err)+ }+ defer func() { _ = st.Close() }()++ srv2, err := NewServer(Options{+ DriverName: "sqlite",+ DataSourceName: dbPath,+ OIDCIssuer: issuer,+ OIDCClientID: "sam-cli-app",+ AllowedAudiences: []string{"sam-mesh-audience"},+ }, st)+ if err != nil {+ t.Fatalf("failed to create server: %v", err)+ }++ rec := httptest.NewRecorder()+ srv2.HandleInfo(rec, httptest.NewRequest(http.MethodGet, "/info", nil))+ if rec.Code != http.StatusOK {+ t.Fatalf("unexpected /info status: %d", rec.Code)+ }+ var info2 api.ControlPlaneInfoResponse+ if err := proto.Unmarshal(rec.Body.Bytes(), &info2); err != nil {+ t.Fatalf("failed to unmarshal ControlPlaneInfoResponse: %v", err)+ }+ if info2.ClientId != "sam-cli-app" || info2.Audience != "sam-mesh-audience" {+ t.Errorf("unexpected client id/audience: %+v", &info2)+ }+ })+// 2. Test /keysresp, err = client.Get(baseURL + "/keys")if err != nil {