Add Windows instance flag support for named pipes#6977
Conversation
Signed-off-by: Devansh1093 <dr30031102@gmail.com>
sorindumitru
left a comment
There was a problem hiding this comment.
Thanks @Devansh1093 for the changes. I think spire-agent would also require similar changes to support the instance environment variable.
d167c8f to
c0c8e75
Compare
c0c8e75 to
75ff5f2
Compare
Signed-off-by: Devansh1093 <dr30031102@gmail.com>
| import ( | ||
| "context" | ||
| "flag" | ||
| "net" | ||
| "strings" | ||
|
|
||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/Microsoft/go-winio" | ||
| "github.com/spiffe/spire/pkg/common/namedpipe" | ||
| ) |
| func (a *Adapter) addOSFlags(flags *flag.FlagSet) { | ||
| flags.StringVar(&a.namedPipeName, "namedPipeName", DefaultNamedPipeName, "Pipe name of the SPIRE Server API named pipe") | ||
| flags.StringVar(&a.instance, "instance", "", "Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE).") | ||
| } |
| func (a *Adapter) getGRPCAddr() (string, error) { | ||
| if a.namedPipeName == "" { | ||
| a.namedPipeName = DefaultNamedPipeName | ||
| tpl := os.Getenv("SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE") | ||
| pipe := os.Getenv("SPIRE_SERVER_PRIVATE_SOCKET") | ||
|
|
||
| if a.instance != "" { | ||
| if tpl == "" { | ||
| return "", fmt.Errorf( | ||
| "you must define %s to use the instance flag", | ||
| "SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE", | ||
| ) | ||
| } | ||
|
|
||
| if !strings.Contains(tpl, "%i") { | ||
| return "", fmt.Errorf( | ||
| "failed to find %%i in %s", | ||
| "SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| namedPipeName := DefaultNamedPipeName | ||
|
|
||
| switch { | ||
| case a.namedPipeName != DefaultNamedPipeName: | ||
| namedPipeName = a.namedPipeName | ||
|
|
||
| case a.instance != "": | ||
| namedPipeName = strings.ReplaceAll(tpl, "%i", a.instance) | ||
|
|
||
| case pipe != "": | ||
| namedPipeName = pipe | ||
| } |
There was a problem hiding this comment.
Yes, it would be good to have a test for this
| setUsage = `Usage of logger set: | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). | ||
|
|
||
| -level string | ||
| The new log level, one of (panic, fatal, error, warn, info, debug, trace) | ||
| -namedPipeName string |
| getUsage = `Usage of logger get: | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). | ||
| -namedPipeName string | ||
| -namedPipeName string | ||
| Pipe name of the SPIRE Server API named pipe (default "\\spire-server\\private\\api") | ||
| -output value |
| ` | ||
| evictUsage = `Usage of agent evict: | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). |
| -matchSelectorsOn string | ||
| The match mode used when filtering by selectors. Options: exact, any, superset and subset (default "superset") | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). |
| ` | ||
| showUsage = `Usage of agent show: | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). |
| -jwtSVIDTTL int | ||
| The lifetime, in seconds, for JWT-SVIDs issued based on this registration entry. | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). |
| -matchSelectorsOn string | ||
| The match mode used when filtering by selectors. Options: exact, any, superset and subset (default "superset") | ||
| -instance string | ||
| Instance name to substitute into socket templates (env SPIRE_SERVER_PRIVATE_SOCKET_TEMPLATE). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Devansh Roy <dr30031102@gmail.com>
|
Hi @sorindumitru, I am a bit confused here. Do I need to make changes in my code suggested by copilot? . It would be helpful if you could tell me. |
Hi @Devansh1093, yes, it would be good to go through those and see which make sense to address or not. I'll also go through them when reviewing the code. |
Did you run the |
|
I ran the tests on linux system. |
You'll have to find a way to run them on windows, to test it out. For example via a VM, microsoft has ISOs available for evaluation purposes. |
|
I am not able to run them on virtual machines. I tried multiple times. |
Does something like |
Signed-off-by: Devansh Roy <dr30031102@gmail.com>
Pull Request check list
Affected functionality
Windows named pipe address resolution for SPIRE server CLI utilities.
Description of change
Adds support for the
instanceflag inutil_windows.goto align Windows behavior with the existing POSIX implementation.This change enables named pipe paths to be resolved using template environment variables similarly to the POSIX socket template flow.
The implementation intentionally keeps the
%iplaceholder format consistent with the POSIX implementation to preserve cross-platform behavior and avoid introducing a separate Windows-specific template syntax.Validation performed:
go test ./...GOOS=windows go build ./...Which issue this PR fixes
Related to #6937