Skip to content
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
28 changes: 27 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ type PipelineConfig struct {
Raw *simplejson.Json
}

type VaultTLSConfig struct {
CACert string
ClientCert string
ClientKey string
Insecure bool
}

type VaultConfig struct {
Address string

Expand All @@ -72,6 +79,8 @@ type VaultConfig struct {
AuthMountPath string
RoleID string
SecretID string

TLS *VaultTLSConfig
}

func NewConfig() *Config {
Expand Down Expand Up @@ -203,9 +212,26 @@ func parseVaultConfig(vault *simplejson.Json) (*VaultConfig, error) {
SecretID: vault.Get("secret_id").MustString(),
}

tls := vault.Get("tls")
if tls.Interface() != nil {
vc.TLS = &VaultTLSConfig{
CACert: tls.Get("ca_cert").MustString(),
ClientCert: tls.Get("client_cert").MustString(),
ClientKey: tls.Get("client_key").MustString(),
Insecure: tls.Get("insecure").MustBool(),
}
}

if vc.Address == "" {
return nil, errors.New("vault address must be non-empty string")
return nil, errors.New("vault address must be provided")
}
if vc.TLS != nil {
if vc.TLS.ClientCert != "" && vc.TLS.ClientKey == "" ||
vc.TLS.ClientCert == "" && vc.TLS.ClientKey != "" {
return nil, errors.New("both client cert and client key must be provided")
}
}

if vc.Token != "" {
return vc, nil
}
Expand Down
20 changes: 20 additions & 0 deletions cfg/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package cfg
import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/vault/api"
auth "github.com/hashicorp/vault/api/auth/approle"
"github.com/ozontech/file.d/logger"
"github.com/ozontech/file.d/xtls"
)

type secreter interface {
Expand All @@ -25,6 +27,24 @@ func newVault(cfg *VaultConfig) (*vault, error) {

conf := api.DefaultConfig()
conf.Address = cfg.Address
if tls := cfg.TLS; tls != nil {
b := xtls.NewConfigBuilder()
if tls.CACert != "" {
if err := b.AppendCARoot(tls.CACert); err != nil {
return nil, fmt.Errorf("can't append CA root: %w", err)
}
}
if tls.ClientCert != "" && tls.ClientKey != "" {
if err := b.AppendX509KeyPair(tls.ClientCert, tls.ClientKey); err != nil {
return nil, fmt.Errorf("can't append X509 key pair: %w", err)
}
}
b.SetSkipVerify(tls.Insecure)

transport, _ := conf.HttpClient.Transport.(*http.Transport)
transport.TLSClientConfig = b.Build()
}

c, err := api.NewClient(conf)
if err != nil {
return nil, fmt.Errorf("can't create api client: %w", err)
Expand Down
11 changes: 10 additions & 1 deletion docs/configuring.idoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,18 @@ vault:
auth_mount_path: some/path # used when formatting the authorization uri: 'auth/%s/login'
```

### TLS support
```yaml
vault:
tls:
ca_cert: path_or_content_of_ca_cert_file
client_cert: path_or_content_of_client_cert_file
client_key: path_or_content_of_client_key_file
insecure: true
```

## Env support
Consider this config:

```yaml
pipelines:
example:
Expand Down
11 changes: 10 additions & 1 deletion docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,18 @@ vault:
auth_mount_path: some/path # used when formatting the authorization uri: 'auth/%s/login'
```

### TLS support
```yaml
vault:
tls:
ca_cert: path_or_content_of_ca_cert_file
client_cert: path_or_content_of_client_cert_file
client_key: path_or_content_of_client_key_file
insecure: true
```

## Env support
Consider this config:

```yaml
pipelines:
example:
Expand Down
Loading