-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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) (#18227)
Co-authored-by: shaj13 <[email protected]>
- Loading branch information
Showing
8 changed files
with
146 additions
and
2 deletions.
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 via 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) | ||
} |
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,69 @@ | ||
--- | ||
layout: docs | ||
page_title: Unix - Listeners - Configuration | ||
description: |- | ||
The Unix listener configures Vault to listen on the specified Unix domain socket. | ||
--- | ||
|
||
# `unix` Listener | ||
|
||
The Unix listener configures Vault to listen on the specified Unix domain socket. | ||
|
||
```hcl | ||
listener "unix" { | ||
address = "/run/vault.sock" | ||
} | ||
``` | ||
|
||
The `listener` stanza may be specified more than once to make Vault listen on | ||
multiple sockets. | ||
|
||
## `unix` Listener Parameters | ||
- `address` `(string: "/run/vault.sock", <required>)` – Specifies the address to bind the Unix socket. | ||
|
||
- `socket_mode` `(string: "", <optional>)` – Changes the access | ||
permissions and the special mode flags of the Unix socket. | ||
|
||
- `socket_user` `(string: "", <optional>)` – Changes the user owner of the Unix socket. | ||
|
||
- `socket_group` `(string: "", <optional>)` – Changes the group owner of the Unix socket. | ||
|
||
|
||
## `unix` Listener Examples | ||
|
||
### Listening on Multiple Sockets | ||
|
||
This example shows Vault listening on a specified socket, as well as the default. | ||
|
||
```hcl | ||
listener "unix" {} | ||
listener "unix" { | ||
address = "/var/run/vault.sock" | ||
} | ||
``` | ||
|
||
### Listening on Multiple Interfaces | ||
|
||
This example shows Vault listening on TCP localhost, as well as Unix socket. | ||
|
||
```hcl | ||
listener "unix" { | ||
address = "/var/run/vault.sock" | ||
} | ||
listener "tcp" { | ||
address = "127.0.0.1:8200" | ||
} | ||
``` | ||
|
||
### Configuring Permissions | ||
This example shows changing access permissions and ownership of the Unix socket. | ||
```hcl | ||
listener "unix" { | ||
address = "/var/run/vault.sock" | ||
socket_mode = "644" | ||
socket_user = "1000" | ||
socket_group = "1000" | ||
} | ||
``` |
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