Skip to content

Commit

Permalink
support loading vault CA from remote endpoint (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
asiyani authored Jan 24, 2025
1 parent 843abe0 commit 77dc106
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ spec:
```

### Vault CA Reload
terraform-applier support hot reload of vault CA cert for secure communication.
CA is updated before making vault API Calls. Following envs are supported.

* `VAULT_CACERT`: value should be path to a PEM-encoded certificate file or bundle.
Takes precedence over CACertificate and CAPath.

* `VAULT_CAPATH`: value should be path to a directory populated with PEM-encoded certificates.

* `VAULT_CAURL`: value should be URL which returns a PEM-encoded certificate or bundle as body.
Takes precedence over CAPath.

## Monitoring

### Metrics
Expand Down
23 changes: 20 additions & 3 deletions vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
"time"

Expand Down Expand Up @@ -31,6 +33,7 @@ func newClient() (*vaultapi.Client, error) {

var envCACert string
var envCAPath string
var envCACertBytes []byte

if v := os.Getenv(vaultapi.EnvVaultCACert); v != "" {
envCACert = v
Expand All @@ -40,11 +43,25 @@ func newClient() (*vaultapi.Client, error) {
envCAPath = v
}

if v := os.Getenv("VAULT_CAURL"); v != "" {
resp, err := http.Get(v)
if err != nil {
return nil, err
}
defer resp.Body.Close()

envCACertBytes, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
}

// use custom cert if set
if envCACert != "" || envCAPath != "" {
if envCACert != "" || envCAPath != "" || len(envCACertBytes) != 0 {
err := vaultConfig.ConfigureTLS(&vaultapi.TLSConfig{
CACert: envCACert,
CAPath: envCAPath,
CACert: envCACert,
CACertBytes: envCACertBytes,
CAPath: envCAPath,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 77dc106

Please sign in to comment.