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

Support vault tls by cert path #112

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Download latest static binaries from [release page](https://github.com/fishi0x01
In order to get a valid token, `vsh` uses vault's TokenHelper mechanism.
That means `vsh` supports setting vault tokens via `~/.vault-token`, `VAULT_TOKEN` and external [token-helper](https://www.vaultproject.io/docs/commands/token-helper).

## TLS

Add tls certificate for server by setting `VAULT_CACERT` environment variable to the `pem` certificate path.

## Token permission requirements

`vsh` requires `List` permission on the operated paths.
Expand Down
21 changes: 15 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type Client struct {

// VaultConfig container to keep parameters for Client configuration
type VaultConfig struct {
Addr string
Token string
StartPath string
Addr string
Token string
StartPath string
CertificatePath string
}

func verifyClientPwd(client *Client) (*Client, error) {
Expand All @@ -51,14 +52,22 @@ func verifyClientPwd(client *Client) (*Client, error) {

// NewClient creates a new Client Vault wrapper
func NewClient(conf *VaultConfig) (*Client, error) {
vault, err := api.NewClient(&api.Config{
config := &api.Config{
Address: conf.Addr,
})
}

if len(conf.CertificatePath) > 0 {
log.UserDebug("Configuring TLS to be " + conf.CertificatePath)
config.ConfigureTLS(&api.TLSConfig{
CAPath: conf.CertificatePath,
})
}

vault, err := api.NewClient(config)

if err != nil {
return nil, err
}

vault.SetToken(conf.Token)

permissions, err := vault.Sys().CapabilitiesSelf("sys/mounts")
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ func main() {
}

conf := &client.VaultConfig{
Addr: os.Getenv("VAULT_ADDR"),
Token: token,
StartPath: os.Getenv("VAULT_PATH"),
Addr: os.Getenv("VAULT_ADDR"),
Token: token,
StartPath: os.Getenv("VAULT_PATH"),
CertificatePath: os.Getenv("VAULT_CACERT"),
}

vaultClient, err = client.NewClient(conf)
Expand Down
Loading