-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: add and support unix listener (UDS)
- Loading branch information
shaj13
committed
Dec 5, 2022
1 parent
12b2fab
commit 42aad53
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,3 @@ | ||
```release-note:feature | ||
**Server UDS Listener**: Adding listener to vault server to serve http request vi unix domain socket | ||
``` |
This file contains 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 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 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,36 @@ | ||
package server | ||
|
||
import ( | ||
"io" | ||
"net" | ||
|
||
"github.com/hashicorp/go-secure-stdlib/reloadutil" | ||
"github.com/hashicorp/vault/internalshared/configutil" | ||
"github.com/hashicorp/vault/internalshared/listenerutil" | ||
"github.com/mitchellh/cli" | ||
) | ||
|
||
func unixListenerFactory(l *configutil.Listener, _ io.Writer, ui cli.Ui) (net.Listener, map[string]string, reloadutil.ReloadFunc, error) { | ||
addr := l.Address | ||
if addr == "" { | ||
addr = "/run/vault.sock" | ||
} | ||
|
||
var cfg *listenerutil.UnixSocketsConfig | ||
if l.SocketMode != "" && | ||
l.SocketUser != "" && | ||
l.SocketGroup != "" { | ||
cfg = &listenerutil.UnixSocketsConfig{ | ||
Mode: l.SocketMode, | ||
User: l.SocketUser, | ||
Group: l.SocketGroup, | ||
} | ||
} | ||
|
||
ln, err := listenerutil.UnixSocketListener(addr, cfg) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
|
||
return ln, map[string]string{}, nil, nil | ||
} |
This file contains 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,25 @@ | ||
package server | ||
|
||
import ( | ||
"net" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/internalshared/configutil" | ||
"github.com/mitchellh/cli" | ||
) | ||
|
||
func TestUnixListener(t *testing.T) { | ||
ln, _, _, err := unixListenerFactory(&configutil.Listener{ | ||
Address: filepath.Join(t.TempDir(), "/vault.sock"), | ||
}, nil, cli.NewMockUi()) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
connFn := func(lnReal net.Listener) (net.Conn, error) { | ||
return net.Dial("unix", ln.Addr().String()) | ||
} | ||
|
||
testListenerImpl(t, ln, connFn, "", 0, "", false) | ||
} |