Skip to content

Add instance flag support#6789

Open
kfox1111 wants to merge 22 commits intospiffe:mainfrom
kfox1111:instance
Open

Add instance flag support#6789
kfox1111 wants to merge 22 commits intospiffe:mainfrom
kfox1111:instance

Conversation

@kfox1111
Copy link
Copy Markdown
Contributor

@kfox1111 kfox1111 commented Mar 25, 2026

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Description of change
Adds easy multiinstance support

Which issue this PR fixes
fixes #6247

Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Comment thread cmd/spire-agent/cli/run/run_posix.go Outdated
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
@kfox1111 kfox1111 marked this pull request as ready for review April 11, 2026 22:04

func (c *ConfigOS) AddOSFlags(flags *flag.FlagSet) {
flags.StringVar(&c.socketPath, "socketPath", DefaultSocketPath, "Path to the SPIRE Agent API Unix domain socket")
flags.StringVar(&c.instance, "i", "", "Instance name to substitute into socket templates (env SPIRE_AGENT_PUBLIC_SOCKET_TEMPLATE). If omitted and the env var is set, defaults to 'main'.")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if it's not a better UX to error out instead of defaulting to main, since main is not particularly meaningful in any way and it might not be an instance name.

I'm thinking that people might forget the -i in the case where those env vars are available and they accidentally target the wrong instance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

without instance flag support, it defaults to /tmp/xxxxxxx, so there is precedent where people expect not having a flag to "just work"

I'm kind of trying to reproduce that feeling too when configured with system packages and not just use /tmp on a systemd system which is pretty insecure. The system packages would set the path by default and then if you only have one instance, things "just work" like they always have.

But, if its a show stopper, requiring -i if the env vars set is still probably better then not having support at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kind of envisioned the env vars here along with a default -i, fulfilling the role of:
#5770

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Discussed this today and we would prefer erroring out if the instance is not present. Any default here is likely to be very opinionated and likely not useful for a lot of people.

For #5770 I think we can still use SPIRE_SERVER_ADMIN_SOCKET, SPIRE_AGENT_ADMIN_SOCKET and SPIFFE_ENDPOINT_SOCKET. That would cover the non-instanced use case and would not require any instance specified.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. so, if no instance is specified, SPIRE_SERVER_ADMIN_SOCKET, SPIRE_AGENT_ADMIN_SOCKET and SPIFFE_ENDPOINT_SOCKET will be used if set and the regular defaults if not set.

If -instance is set and the template env vars are set, then those are used. otherwise, it will complain

Copy link
Copy Markdown
Contributor Author

@kfox1111 kfox1111 Apr 21, 2026

Choose a reason for hiding this comment

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

actually, I ran into the issue with SPIFFE_ENDPOINT_SOCKET being incompatible with socket path before since one expects unix:// in front and the other does not. For consistency, I coded up everything to have the _TEMPLATE equivalent variable name without the _TEMPLATE

Comment thread cmd/spire-agent/cli/common/template.go Outdated
Comment thread cmd/spire-agent/cli/api/api_posix_test.go Outdated
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
@kfox1111
Copy link
Copy Markdown
Contributor Author

Ok, this should be ready

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.

Instance flag and pathing

2 participants