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

leverage Vault token helpers approach while obtaining Vault token #104

Merged
merged 1 commit into from
Jul 29, 2021
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ require (
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f
google.golang.org/protobuf v1.27.1
gopkg.in/square/go-jose.v2 v2.6.0
github.com/mitchellh/go-homedir v1.1.0
)
18 changes: 17 additions & 1 deletion pkg/signature/kms/hashivault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/ReneKroon/ttlcache/v2"
vault "github.com/hashicorp/vault/api"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/sigstore/sigstore/pkg/cryptoutils"
)
Expand Down Expand Up @@ -84,7 +87,18 @@ func newHashivaultClient(keyResourceID string) (*hashivaultClient, error) {

token := os.Getenv("VAULT_TOKEN")
if token == "" {
return nil, errors.New("VAULT_TOKEN is not set")
log.Printf("VAULT_TOKEN is not set, trying to read token from file at path ~/.vault-token")
homeDir, err := homedir.Dir()
if err != nil {
return nil, errors.Wrap(err, "get home directory")
}

tokenFromFile, err := os.ReadFile(filepath.Join(homeDir, ".vault-token"))
if err != nil {
return nil, errors.Wrap(err, "read .vault-token file")
}

token = string(tokenFromFile)
}

client, err := vault.NewClient(&vault.Config{
Expand All @@ -94,6 +108,8 @@ func newHashivaultClient(keyResourceID string) (*hashivaultClient, error) {
return nil, errors.Wrap(err, "new vault client")
}

client.SetToken(token)
bobcallaway marked this conversation as resolved.
Show resolved Hide resolved

transitSecretEnginePath := os.Getenv("TRANSIT_SECRET_ENGINE_PATH")
if transitSecretEnginePath == "" {
transitSecretEnginePath = "transit"
Expand Down