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

Add vault file handing to secret function #1490

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion template/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func nodesFunc(b *Brain, used, missing *dep.Set) func(...string) ([]*dep.Node, e
}

// secretFunc returns or accumulates secret dependencies from Vault.
func secretFunc(b *Brain, used, missing *dep.Set) func(...string) (*dep.Secret, error) {
func secretFunc(b *Brain, used, missing *dep.Set, sandboxPath string) func(...string) (*dep.Secret, error) {
return func(s ...string) (*dep.Secret, error) {
var result *dep.Secret

Expand All @@ -351,6 +351,29 @@ func secretFunc(b *Brain, used, missing *dep.Set) func(...string) (*dep.Secret,

k, v := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
data[k] = v

// vault has a notation to prefix file paths pointing to files
// containing attribute data with an @. Parse this, load the file
// contents and use as the value. Most useful for PKI `sign`
// method to provide csr as a file
if v[0] == '@' {
var extfile_path string
extfile_path = v[1:]

sandbox_err := pathInSandbox(sandboxPath, extfile_path)
if sandbox_err != nil {
return result, sandbox_err
}

extfile, err := ioutil.ReadFile(extfile_path)

if err != nil {
fmt.Println("Error reading external file", err)
return nil, err
}

data[k] = string(extfile)
}
}

var d dep.Dependency
Expand Down
4 changes: 2 additions & 2 deletions template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func funcMap(i *funcMapInput) template.FuncMap {
"safeLs": safeLsFunc(i.brain, i.used, i.missing),
"node": nodeFunc(i.brain, i.used, i.missing),
"nodes": nodesFunc(i.brain, i.used, i.missing),
"secret": secretFunc(i.brain, i.used, i.missing),
"secret": secretFunc(i.brain, i.used, i.missing, i.sandboxPath),
"secrets": secretsFunc(i.brain, i.used, i.missing),
"service": serviceFunc(i.brain, i.used, i.missing),
"connect": connectFunc(i.brain, i.used, i.missing),
Expand Down Expand Up @@ -294,7 +294,7 @@ func funcMap(i *funcMapInput) template.FuncMap {
"split": split,
"byMeta": byMeta,
"sockaddr": sockaddr,

// Math functions
"add": add,
"subtract": subtract,
Expand Down