Skip to content

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

Merged
aojea merged 1 commit into
google:mainfrom
aojea:repeatable-issuer-flags
Oct 18, 2026
Merged

aojea merged 1 commit into
google:mainfrom
aojea:repeatable-issuer-flags

Conversation

@aojea

@aojea aojea commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

--issuer and --workload-issuer on agentmesh-one and agentmesh-control-plane were StringVars. Given twice, the second value replaced the first, silently. Observed on Cloud Run, where --args splits on commas so the comma form cannot be passed naively and the flag was repeated instead:

--workload-issuer=http://35.253.119.53 --workload-issuer=https://storage.googleapis.com/…/substrate

Only the second issuer was configured; every OpenShell sandbox behind the first was refused with JWT validation failed: unknown issuer: http://35.253.119.53 and nothing in the logs pointed at the flag.

Change

A small controlplane.IssuerFlags helper registers both flags with pflag's StringSliceVar (repeatable and comma-separated, both accumulate) and both binaries use it, so they cannot drift. The joined value feeds the same Options fields and parseWorkloadIssuers as before; <issuer>=<suffix> entries are unaffected. Help text and reference docs now say "repeatable or comma-separated"; the Cloud Run guide shows how to pass several issuers through --args (repeat the flag, or --args="^;^…").

go.mod: github.com/spf13/pflag moves from indirect to direct at the version cobra already pins; no new module.

Verified

  • TestIssuerFlagsAccumulate: repeated, comma-separated, both forms with a suffix entry, and empty; the joined value is fed to parseWorkloadIssuers and the expected issuers come out.
  • Binary: agentmesh-one --workload-issuer=http://127.0.0.1:1 --workload-issuer=http://127.0.0.1:2 logs Workload issuer not resolved … "issuer": "http://127.0.0.1:1" and … "http://127.0.0.1:2" (both configured; controlplane: resolve workload issuers in the background instead of failing to start #736 lets it start with neither reachable).
  • go test ./internal/controlplane/ ./cmd/..., ./hack/lint.sh 0 issues.

Both flags were plain strings, so a second --workload-issuer replaced the
first and every member of the platform behind the dropped issuer was
refused with "unknown issuer", with nothing in the logs about the flag.
Seen on Cloud Run, whose --args splits on commas, which is why the flag
was repeated in the first place.

The two flags move to a shared IssuerFlags helper registered by both
binaries with pflag's StringSliceVar: repeated or comma-separated, every
value counts, and the joined result feeds the same Options fields and the
same parser as before. Help text and reference docs say "repeatable or
comma-separated"; the Cloud Run guide shows both ways to pass several
issuers through --args. pflag becomes a direct dependency at the version
cobra already pins.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors OIDC issuer flag handling by introducing a reusable IssuerFlags struct in internal/controlplane to support repeatable and comma-separated --issuer and --workload-issuer flags across both agentmesh-control-plane and agentmesh-one. It also updates the corresponding documentation and adds tests. Feedback is provided to improve the robustness of the Empty() check in IssuerFlags to handle cases where an empty string is explicitly passed as a flag value, which would otherwise bypass the validation.

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 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Correctness / Robustness

The current implementation of Empty() checks the lengths of the slices:

func (f *IssuerFlags) Empty() bool { return len(f.Login) == 0 && len(f.Workload) == 0 }

However, if a user explicitly passes an empty string (e.g., --issuer="" or --workload-issuer=""), pflag.StringSliceVar parses this as a slice containing a single empty string ([]string{""}). In this case, len(f.Login) or len(f.Workload) will be 1, causing Empty() to return false. This bypasses the validation check in agentmesh-control-plane and allows the server to start with empty issuers.

To make this check more robust, we should verify if the resolved (joined) issuer strings are empty.

Suggested change
func (f *IssuerFlags) Empty() bool { return len(f.Login) == 0 && len(f.Workload) == 0 }
func (f *IssuerFlags) Empty() bool { return f.OIDCIssuer() == "" && f.WorkloadIssuer() == "" }

@aojea
aojea merged commit b2712d8 into google:main Oct 18, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant