Skip to content
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

Add support for Named Pipes in Windows #190

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions v2/internal/test/fakeworkloadapi/workload_api_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/rand"
"testing"
"time"

"github.com/Microsoft/go-winio"
"github.com/spiffe/go-spiffe/v2/proto/spiffe/workload"
Expand All @@ -20,6 +21,7 @@ func NewWithNamedPipeListener(tb testing.TB) *WorkloadAPI {
jwtBundlesChans: make(map[chan *workload.JWTBundlesResponse]struct{}),
}

rand.Seed(time.Now().UnixNano())
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this at package init time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

listener, err := winio.ListenPipe(fmt.Sprintf(`\\.\pipe\go-spiffe-test-pipe-%x`, rand.Uint64()), nil)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: If we don't seed rand, then two test processes running concurrently could collide on the names :) We're more than likely ok, but just thought I'd point it out just in case.

require.NoError(tb, err)

Expand Down
10 changes: 5 additions & 5 deletions v2/workloadapi/client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c *Client) setAddress() error {
if c.config.address != "" {
return errors.New("only one of WithAddr or WithNamedPipeName options can be used, not both")
}
c.config.address = parseTargetFromNamedPipeName(c.config.namedPipeName)
c.config.address = namedPipeTarget(c.config.namedPipeName)
return nil
}

Expand All @@ -42,9 +42,9 @@ func (c *Client) setAddress() error {
return err
}

// parseTargetFromNamedPipeName parses the named pipe name
// for the endpoint address and returns the target string
// suitable for dialing.
func parseTargetFromNamedPipeName(pipeName string) string {
// namedPipeTarget returns a target string suitable for
// dialing the endpoint address based on the provided
// pipe name.
func namedPipeTarget(pipeName string) string {
return `\\.\` + filepath.Join("pipe", pipeName)
}