Skip to content

Agent Mesh

cmd: --issuer and --workload-issuer accumulate when repeated

Antonio Ojeab2712d8e04a1
diff --git a/cmd/agentmesh-control-plane/main.go b/cmd/agentmesh-control-plane/main.go
index 17293c4c..56409588 100644
--- a/cmd/agentmesh-control-plane/main.go
+++ b/cmd/agentmesh-control-plane/main.go
@@ -41,8 +41,7 @@ var (
dbDriver string
dbDSN string
dbDSNPath string
- oidcIssuer string
- workloadIssuer string
+ issuerFlags controlplane.IssuerFlags
oidcClientID string
allowedAudiencesFlag string
keyRotationInterval time.Duration
@@ -86,7 +85,7 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
logging.Setup(logging.Options{Level: logLevel, Format: logFormat})
- if oidcIssuer == "" && workloadIssuer == "" {
+ if issuerFlags.Empty() {
logger.Fatalf("OIDC issuer is required (use --issuer or --workload-issuer flag)")
}
if insecureSkipTLSVerify {
@@ -134,8 +133,8 @@ func main() {
ListenAddr: bindAddress,
DriverName: dbDriver,
DataSourceName: dbDSN,
- OIDCIssuer: oidcIssuer,
- WorkloadIssuer: workloadIssuer,
+ OIDCIssuer: issuerFlags.OIDCIssuer(),
+ WorkloadIssuer: issuerFlags.WorkloadIssuer(),
OIDCClientID: oidcClientID,
AllowedAudiences: auds,
LeaseDuration: leaseDuration,
@@ -201,8 +200,7 @@ func main() {
rootCmd.PersistentFlags().StringVar(&dbDriver, "db-driver", "sqlite", "Database driver (sqlite or postgres)")
rootCmd.PersistentFlags().StringVar(&dbDSN, "db-dsn", "control-plane.db", "Database DSN/Connection URL (avoid for postgres: embeds a password; prefer --db-dsn-path or AGENTMESH_DB_DSN)")
rootCmd.PersistentFlags().StringVar(&dbDSNPath, "db-dsn-path", "", "Path to file containing the database DSN/Connection URL (overrides --db-dsn; or env AGENTMESH_DB_DSN)")
- rootCmd.Flags().StringVar(&oidcIssuer, "issuer", "", "OIDC Issuer URL (comma-separated)")
- rootCmd.Flags().StringVar(&workloadIssuer, "workload-issuer", "", "Workload OIDC Issuer URL or '<issuer>=<email-suffix>' (comma-separated); accepted at /register, /refresh and /token/exchange, refused at /user/* and /oauth/authorize")
+ issuerFlags.Register(rootCmd.Flags(), "")
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.")
diff --git a/cmd/agentmesh-one/main.go b/cmd/agentmesh-one/main.go
index a5d73349..79db0bb1 100644
--- a/cmd/agentmesh-one/main.go
+++ b/cmd/agentmesh-one/main.go
@@ -29,6 +29,7 @@ import (
"syscall"
"github.com/google/agentmesh/api"
+ "github.com/google/agentmesh/internal/controlplane"
"github.com/google/agentmesh/internal/logging"
"github.com/google/agentmesh/internal/router"
"github.com/google/agentmesh/internal/standalone"
@@ -54,8 +55,7 @@ func main() {
noJoinToken bool
adminTokenPath string
policyFile string
- oidcIssuer string
- workloadIssuer string
+ issuerFlags controlplane.IssuerFlags
oidcClientID string
allowedAudiencesFlag string
logLevel string
@@ -155,8 +155,8 @@ func main() {
DisableJoinToken: noJoinToken,
AdminToken: adminToken,
PolicyFile: policyFile,
- OIDCIssuer: oidcIssuer,
- WorkloadIssuer: workloadIssuer,
+ OIDCIssuer: issuerFlags.OIDCIssuer(),
+ WorkloadIssuer: issuerFlags.WorkloadIssuer(),
OIDCClientID: oidcClientID,
AllowedAudiences: auds,
ControlPlane: cpTunables,
@@ -210,8 +210,7 @@ func main() {
rootCmd.Flags().BoolVar(&noJoinToken, "no-join-token", false, "Run without a standing join token; devices enroll only with minted bootstrap tokens (token create/qr) or OIDC")
rootCmd.Flags().StringVar(&adminTokenPath, "admin-token-path", "", "File containing the admin API bearer token (or env AGENTMESH_ADMIN_TOKEN; auto-generated and persisted in --data-dir if neither is set)")
rootCmd.Flags().StringVar(&policyFile, "policy-file", "", "Path to a protojson PolicyConfig seeding the mesh policy on first boot only")
- rootCmd.Flags().StringVar(&oidcIssuer, "issuer", "", "Optional external OIDC issuer URL (comma-separated)")
- rootCmd.Flags().StringVar(&workloadIssuer, "workload-issuer", "", "Optional workload OIDC issuer URL or '<issuer>=<email-suffix>' (comma-separated); accepted at /register, /refresh and /token/exchange, refused at /user/* and /oauth/authorize")
+ issuerFlags.Register(rootCmd.Flags(), "Optional ")
rootCmd.Flags().StringVar(&oidcClientID, "oidc-client-id", "", "OAuth client id advertised 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().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error)")
diff --git a/go.mod b/go.mod
index 3b26ab59..9b45a20a 100644
--- a/go.mod
+++ b/go.mod
@@ -28,6 +28,7 @@ require (
github.com/prometheus/client_model v0.6.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/cobra v1.10.2
+ github.com/spf13/pflag v1.0.10
go.etcd.io/bbolt v1.5.0
go.uber.org/zap v1.28.0
golang.org/x/net v0.60.0
@@ -128,7 +129,6 @@ require (
github.com/segmentio/asm v1.2.1 // indirect
github.com/segmentio/encoding v0.5.4 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
- github.com/spf13/pflag v1.0.10 // indirect
github.com/tidwall/gjson v1.19.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
diff --git a/internal/controlplane/issuerflags.go b/internal/controlplane/issuerflags.go
new file mode 100644
index 00000000..090c3dce
--- /dev/null
+++ b/internal/controlplane/issuerflags.go
@@ -0,0 +1,48 @@
+// 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 controlplane
+
+import (
+ "strings"
+
+ "github.com/spf13/pflag"
+)
+
+// IssuerFlags are the OIDC issuer settings a control plane binary takes on
+// its command line. Both flags accumulate: given twice, or once with a
+// comma-separated value, every issuer counts. A repeated flag that replaced
+// the previous value dropped an issuer silently, and every member of the
+// platform behind the dropped one was refused with "unknown issuer".
+type IssuerFlags struct {
+ Login []string
+ Workload []string
+}
+
+// Register adds --issuer and --workload-issuer to fs. optional names what
+// an empty value means in the help text ("Optional " for agentmesh-one,
+// "" for the control plane, where one of the two is required).
+func (f *IssuerFlags) Register(fs *pflag.FlagSet, optional string) {
+ fs.StringSliceVar(&f.Login, "issuer", nil, optional+"OIDC issuer URL; repeatable or comma-separated")
+ fs.StringSliceVar(&f.Workload, "workload-issuer", nil, optional+"workload OIDC issuer URL or '<issuer>=<email-suffix>', repeatable or comma-separated; accepted at /register, /refresh and /token/exchange, refused at /user/* and /oauth/authorize")
+}
+
+// OIDCIssuer is the value for Options.OIDCIssuer.
+func (f *IssuerFlags) OIDCIssuer() string { return strings.Join(f.Login, ",") }
+
+// WorkloadIssuer is the value for Options.WorkloadIssuer.
+func (f *IssuerFlags) WorkloadIssuer() string { return strings.Join(f.Workload, ",") }
+
+// Empty reports whether no issuer of either kind was given.
+func (f *IssuerFlags) Empty() bool { return len(f.Login) == 0 && len(f.Workload) == 0 }
diff --git a/internal/controlplane/issuerflags_test.go b/internal/controlplane/issuerflags_test.go
new file mode 100644
index 00000000..ab200426
--- /dev/null
+++ b/internal/controlplane/issuerflags_test.go
@@ -0,0 +1,90 @@
+// 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 controlplane
+
+import (
+ "testing"
+
+ "github.com/spf13/pflag"
+)
+
+// TestIssuerFlagsAccumulate is the Cloud Run case: --workload-issuer given
+// once per platform must keep every platform, and the comma form must keep
+// working. Before this helper a repeated flag replaced the previous value.
+func TestIssuerFlagsAccumulate(t *testing.T) {
+ cases := []struct {
+ name string
+ args []string
+ wantLogin string
+ wantWorkload string
+ wantIssuers int
+ }{
+ {
+ name: "repeated",
+ args: []string{"--workload-issuer=http://spire.example", "--workload-issuer=https://bucket.example/substrate"},
+ wantWorkload: "http://spire.example,https://bucket.example/substrate",
+ wantIssuers: 2,
+ },
+ {
+ name: "comma-separated",
+ args: []string{"--workload-issuer=http://spire.example,https://bucket.example/substrate"},
+ wantWorkload: "http://spire.example,https://bucket.example/substrate",
+ wantIssuers: 2,
+ },
+ {
+ name: "both forms and a suffix entry",
+ args: []string{"--issuer=https://login.example", "--workload-issuer=http://spire.example", "--workload-issuer=https://accounts.google.com=.gserviceaccount.com,https://bucket.example/substrate"},
+ wantLogin: "https://login.example",
+ wantWorkload: "http://spire.example,https://accounts.google.com=.gserviceaccount.com,https://bucket.example/substrate",
+ wantIssuers: 2,
+ },
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ var f IssuerFlags
+ fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
+ f.Register(fs, "")
+ if err := fs.Parse(tc.args); err != nil {
+ t.Fatalf("Parse(%v): %v", tc.args, err)
+ }
+ if got := f.OIDCIssuer(); got != tc.wantLogin {
+ t.Fatalf("OIDCIssuer() = %q, want %q", got, tc.wantLogin)
+ }
+ if got := f.WorkloadIssuer(); got != tc.wantWorkload {
+ t.Fatalf("WorkloadIssuer() = %q, want %q", got, tc.wantWorkload)
+ }
+ // The value feeds the same parser the server uses.
+ issuers, suffixes := parseWorkloadIssuers(f.WorkloadIssuer())
+ if len(issuers) != tc.wantIssuers {
+ t.Fatalf("parseWorkloadIssuers kept %d plain issuers, want %d", len(issuers), tc.wantIssuers)
+ }
+ if tc.name == "both forms and a suffix entry" && len(suffixes["https://accounts.google.com"]) != 1 {
+ t.Fatalf("suffix entry lost: %v", suffixes)
+ }
+ })
+ }
+
+ t.Run("empty", func(t *testing.T) {
+ var f IssuerFlags
+ fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
+ f.Register(fs, "")
+ if err := fs.Parse(nil); err != nil {
+ t.Fatal(err)
+ }
+ if !f.Empty() || f.OIDCIssuer() != "" || f.WorkloadIssuer() != "" {
+ t.Fatalf("no flags: Empty()=%v OIDCIssuer()=%q WorkloadIssuer()=%q, want empty", f.Empty(), f.OIDCIssuer(), f.WorkloadIssuer())
+ }
+ })
+}
diff --git a/site/content/docs/guides/cloud-run.md b/site/content/docs/guides/cloud-run.md
index 032ed756..a1cd984c 100644
--- a/site/content/docs/guides/cloud-run.md
+++ b/site/content/docs/guides/cloud-run.md
@@ -133,6 +133,10 @@ The whole procedure, including a control plane that restarts with an empty
store between steps, is exercised by
`TestOperatorSigningKeyRotationProcess` in `tests/integration`.
+Several issuers on Cloud Run: `--args` splits on commas, so either repeat
+the flag (`--workload-issuer=A,--workload-issuer=B` inside `--args`, each a
+separate argument) or switch the delimiter: `--args="^;^--port=8080;--workload-issuer=A,B;..."`.
+
Why each Cloud Run flag matters:
- `--min-instances 1 --max-instances 1`: the router's DHT and relay state
diff --git a/site/content/docs/reference/agentmesh-one.md b/site/content/docs/reference/agentmesh-one.md
index 2f862980..fe80d752 100644
--- a/site/content/docs/reference/agentmesh-one.md
+++ b/site/content/docs/reference/agentmesh-one.md
@@ -44,7 +44,7 @@ downloaded tunnel connector.
| `--policy-file` | | Protojson `PolicyConfig` that seeds the mesh policy on first boot. Ignored once the database has a policy. Without it, first boot seeds an open development policy and logs a warning. |
| `--issuer` | | External OIDC issuer(s), comma-separated. Optional. Without an issuer, enrollment works by token only. |
| `--signing-key-path` | | PEM file with operator-owned signing keys (Ed25519 for Biscuits, P-256 for ES256 JWTs; first of each kind signs, later ones verify). Automatic key rotation is off while set; rotate by publishing a new first key and keeping the previous one for the grace period. See the control plane reference. |
-| `--workload-issuer` | | Workload OIDC issuer(s), comma-separated (`<issuer>` or `<issuer>=<email-suffix>`). Automatically added to `--issuer` and refused at `/user/*` and `/oauth/authorize`. One that does not answer at start-up is resolved in the background and its tokens refused until then (`agentmesh_control_plane_workload_issuer_ready{issuer}`); a `--issuer` that does not answer is fatal. |
+| `--workload-issuer` | | Workload OIDC issuer(s), repeatable or comma-separated (`<issuer>` or `<issuer>=<email-suffix>`). Automatically added to `--issuer` and refused at `/user/*` and `/oauth/authorize`. One that does not answer at start-up is resolved in the background and its tokens refused until then (`agentmesh_control_plane_workload_issuer_ready{issuer}`); a `--issuer` that does not answer is fatal. |
| `--oidc-client-id` | first audience | Client ID advertised on `/info`. |
| `--allowed-audiences` | `agentmesh-audience` | Accepted OIDC audiences. |
| `--enroll-qr` | when stdout is a terminal | Print a device-enrollment QR code at startup. Only for `https` URLs. |
diff --git a/site/content/docs/reference/control-plane.md b/site/content/docs/reference/control-plane.md
index d541ed5b..603c55b1 100644
--- a/site/content/docs/reference/control-plane.md
+++ b/site/content/docs/reference/control-plane.md
@@ -19,8 +19,8 @@ agentmesh-control-plane admin unban --peer <id> lift a ban
| Flag | Default | Meaning |
|---|---|---|
-| `--issuer` | | OIDC issuer URL(s), comma-separated. At least one of `--issuer` or `--workload-issuer` is required. The first issuer is advertised to enrolling nodes on `/info`. |
-| `--workload-issuer` | | Workload OIDC issuer(s), comma-separated (`<issuer>` or `<issuer>=<email-suffix>`, such as `https://accounts.google.com=.gserviceaccount.com`). Automatically added to `--issuer`. Workload tokens can enroll, refresh, and exchange credentials (`/register`, `/refresh`, `/token/exchange`), and are refused at `/user/*` and `/oauth/authorize`. A workload issuer that does not answer its discovery document at start-up does not stop the control plane: it keeps retrying in the background (backoff up to 5 minutes), refuses tokens from that issuer with `401` and a message naming it until it does, and reports it as `agentmesh_control_plane_workload_issuer_ready{issuer}` = 0. An `--issuer` that does not answer is still fatal. |
+| `--issuer` | | OIDC issuer URL(s), repeatable or comma-separated. At least one of `--issuer` or `--workload-issuer` is required. The first issuer is advertised to enrolling nodes on `/info`. |
+| `--workload-issuer` | | Workload OIDC issuer(s), repeatable or comma-separated (`<issuer>` or `<issuer>=<email-suffix>`, such as `https://accounts.google.com=.gserviceaccount.com`). Automatically added to `--issuer`. Workload tokens can enroll, refresh, and exchange credentials (`/register`, `/refresh`, `/token/exchange`), and are refused at `/user/*` and `/oauth/authorize`. A workload issuer that does not answer its discovery document at start-up does not stop the control plane: it keeps retrying in the background (backoff up to 5 minutes), refuses tokens from that issuer with `401` and a message naming it until it does, and reports it as `agentmesh_control_plane_workload_issuer_ready{issuer}` = 0. An `--issuer` that does not answer is still fatal. |
| `--allowed-audiences` | `agentmesh-audience` | Audiences accepted in OIDC tokens, comma-separated. |
| `--oidc-client-id` | first audience | OAuth client ID advertised on `/info`, for providers where it differs from the audience. |
| `--insecure-skip-tls-verify` | `false` | Skip TLS verification when fetching issuer metadata and keys. For a cluster issuer served with the cluster CA, or a local development issuer. |