Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Commit f7bd962

Browse files
authored
Feature/vault tls skip (#74)
* Vault TLS config: Add support to skip TLS verification of Vault endpoint Signed-off-by: Andrew Cornies <acornies@gmail.com> * Also populate vault client insecure flag. Signed-off-by: Andrew Cornies <acornies@gmail.com>
1 parent 720b761 commit f7bd962

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
enableBasicAuth = flag.Bool("enable_basic_auth", false, "Flag for enabling basic authentication on gateway endpoints")
4040
basicAuthSecretPath = flag.String("basic_auth_secret_path", "/secrets", "The directory path to the basic auth secret file")
4141
vaultAddrOverride = flag.String("vault_addr", "", "Vault address override. Default Vault address is returned from the Nomad agent")
42+
vaultTLSSkipVerify = flag.Bool("vault_tls_skip_verify", false, "Skips TLS verification for calls to Vault. Not recommend for production")
4243
vaultDefaultPolicy = flag.String("vault_default_policy", "openfaas", "The default policy used when secrets are deployed with a function")
4344
vaultSecretPathPrefix = flag.String("vault_secret_path_prefix", "secret/openfaas", "The Vault k/v path prefix used when secrets are deployed with a function")
4445
vaultAppRoleID = flag.String("vault_app_role_id", "", "A valid Vault AppRole role_id")
@@ -109,6 +110,7 @@ func createFaaSHandlers(nomadClient *api.Client, consulResolver *consul.Resolver
109110
vaultConfig.SecretPathPrefix = *vaultSecretPathPrefix
110111
vaultConfig.AppRoleID = *vaultAppRoleID
111112
vaultConfig.AppSecretID = *vaultAppRoleSecretID
113+
vaultConfig.TLSSkipVerify = *vaultTLSSkipVerify
112114

113115
providerConfig := &fntypes.ProviderConfig{
114116
Vault: vaultConfig,

types/vault_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
type VaultConfig struct {
44
Addr string `json:"Addr"`
55
Enabled bool `json:"Enabled"`
6+
TLSSkipVerify bool
67
DefaultPolicy string
78
SecretPathPrefix string
89
AppRoleID string

vault/vault_service.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package vault
22

33
import (
4+
"crypto/tls"
45
"encoding/json"
56
"fmt"
67
"io/ioutil"
78
"net/http"
89

9-
"github.com/hashicorp/go-hclog"
10-
11-
"github.com/hashicorp/consul-template/dependency"
1210
"github.com/hashicorp/faas-nomad/types"
11+
"github.com/hashicorp/go-hclog"
1312
"github.com/hashicorp/vault/api"
1413
)
1514

@@ -21,16 +20,12 @@ type VaultService struct {
2120

2221
func NewVaultService(config *types.VaultConfig, log hclog.Logger) *VaultService {
2322

24-
vaultClient, _ := api.NewClient(api.DefaultConfig())
23+
clientConfig := api.DefaultConfig()
24+
clientConfig.ConfigureTLS(&api.TLSConfig{Insecure: config.TLSSkipVerify})
25+
vaultClient, _ := api.NewClient(clientConfig)
2526

2627
vaultClient.SetAddress(config.Addr)
2728

28-
clientSet := dependency.NewClientSet()
29-
clientSet.CreateVaultClient(&dependency.CreateVaultClientInput{
30-
Address: config.Addr,
31-
Token: vaultClient.Token(),
32-
})
33-
3429
vs := &VaultService{
3530
Client: vaultClient,
3631
Config: config,
@@ -81,9 +76,15 @@ func (vs *VaultService) Login() (api.Secret, error) {
8176
func (vs *VaultService) DoRequest(method string, path string, body interface{}) (*http.Response, error) {
8277

8378
client := &http.Client{}
79+
trIgnore := &http.Transport{
80+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
81+
}
8482
createRequest := vs.Client.NewRequest(method, path)
8583
createRequest.SetJSONBody(body)
8684

8785
request, _ := createRequest.ToHTTP()
86+
if vs.Config.TLSSkipVerify {
87+
client.Transport = trIgnore
88+
}
8889
return client.Do(request)
8990
}

0 commit comments

Comments
 (0)