-
Notifications
You must be signed in to change notification settings - Fork 602
Add instance flag support #6789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kfox1111
wants to merge
11
commits into
spiffe:main
Choose a base branch
from
kfox1111:instance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8866619
Add instance flag support
kfox1111 3038974
Add missing file
kfox1111 32b840a
Incorperate feedback
kfox1111 448bdc2
Fix formatting
kfox1111 fa67945
Fix lint
kfox1111 96eaf36
tests
kfox1111 d371e91
Merge branch 'main' into instance
kfox1111 405aa48
Fix wit mint
kfox1111 1a3b90e
Fix lint
kfox1111 17cd74c
Merge branch 'main' into instance
kfox1111 4256073
Merge branch 'main' into instance
kfox1111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package common | ||
|
Check failure on line 1 in cmd/spire-agent/cli/common/template.go
|
||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| func ResolveSocketPath(socketPath, defaultPath, templateEnv, instance string) string { | ||
| tpl := os.Getenv(templateEnv) | ||
| if tpl != "" && strings.Contains(tpl, "%i") { | ||
| if instance == "" { | ||
| instance = "main" | ||
| } | ||
| if socketPath == "" || socketPath == defaultPath { | ||
| return strings.ReplaceAll(tpl, "%i", instance) | ||
| } | ||
| } | ||
| if socketPath == "" { | ||
| return defaultPath | ||
| } | ||
| return socketPath | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Running Multiple SPIRE Instances | ||
|
|
||
| Systemd (and other init systems) can run multiple instances of the same service using a template unit. To make it easier to target a particular instance of `spire-agent` or `spire-server`, the CLI supports environment-variable socket templates and a short `-i` flag. | ||
|
|
||
| Environment variables | ||
|
|
||
| - `SPIFFE_PUBLIC_SOCKET_TEMPLATE` — template for agent public/workload socket, use `%i` for the instance name. | ||
| - `SPIRE_AGENT_PRIVATE_SOCKET_TEMPLATE` — template for agent private/admin socket, use `%i` for the instance name. | ||
| - `SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE` — template for server private API socket, use `%i` for the instance name. | ||
|
|
||
| Defaulting and precedence | ||
|
|
||
| When one of the above env vars is set and the `-i` flag is omitted, the CLI will default the instance name to `main` and substitute it into the template. If you explicitly pass a `-socketPath`/`-socket_path` value, that value takes precedence over the environment template substitution. | ||
|
|
||
| Examples | ||
|
|
||
| ```bash | ||
| export SPIFFE_PUBLIC_SOCKET_TEMPLATE=/var/run/spire/agent/sockets/%i/public/spiffe.sock | ||
| spire-agent -i a api watch # uses instance "a" | ||
| spire-agent api watch # uses instance "main" (because env var is set) | ||
|
|
||
| export SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE=/var/run/spire/server/sockets/%i/private/api.sock | ||
| spire-server agent list # uses instance "main" if -i omitted | ||
| ``` | ||
|
|
||
| Notes | ||
|
|
||
| - The `-i` flag is a short alias for specifying the instance name on the CLI. When omitted and a relevant template env var is present, the CLI assumes instance mode and uses `main` unless `-i` is provided. | ||
| - This feature aims to simplify using systemd template units such as `spire-agent@.service` and `spire-server@.service`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this variable should be
SPIRE_PUBLIC_SOCKET_TEMPLATE. We can't use anything from theSPIFFE_namespace since the spec might want to use that later on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated