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

feat: Add Vault provider #35

Merged
merged 25 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2bba5c5
feat(file provider): Add config, adjust tests
csatib02 Dec 15, 2023
a3085a4
feat(vault provider config): Add config
csatib02 Dec 15, 2023
8850c77
fix(vault provider config): Add lience
csatib02 Dec 15, 2023
a27bcef
feat(vault provider): Add Vault provider
csatib02 Dec 17, 2023
1820fed
fix(vault provider): linter
csatib02 Dec 17, 2023
7256c31
feat(vault provider): Add sanitization
csatib02 Dec 19, 2023
27223b3
feat(vault provider): Implementation finished
csatib02 Dec 20, 2023
bed0ba8
fix(go.mod) update dependency
csatib02 Dec 20, 2023
a330483
fix(env.go) single provider workaround
csatib02 Dec 20, 2023
fb2688c
fix(env.go, main.go) vault provider secret loading
csatib02 Dec 20, 2023
46216ef
feat(vault provider config test): Add config test
csatib02 Dec 20, 2023
4f7ae51
feat(vault provider tests): Add more tests, and minor fixes
csatib02 Dec 21, 2023
b0f4197
fix(vault provider tests): Minor fixes
csatib02 Dec 21, 2023
21cff0e
fix: fix remarks
csatib02 Jan 11, 2024
cc25360
feat(common): add common package for env-vars
csatib02 Jan 18, 2024
4af1b5b
fix(tests): improve tests
csatib02 Jan 18, 2024
f002f26
chore: simplify and improve code
csatib02 Jan 18, 2024
cb9a1c8
feat(pkg: args, config, envstore): add new package, factor out main, …
csatib02 Jan 22, 2024
fb24d3c
chore(configs): minor changes
csatib02 Jan 23, 2024
573ecf5
fix(tests): improve tests
csatib02 Jan 23, 2024
1b9480f
fix(file provider): minor fixes
csatib02 Jan 23, 2024
490bec6
fix(vault provider): minor fixes
csatib02 Jan 23, 2024
08d3e1b
fix(main, common): minor fixes, moved back args.go and env_store.go t…
csatib02 Jan 23, 2024
6275cb8
fix(vault test): add test for vault:login
csatib02 Jan 23, 2024
c4d38a3
chore: minor fixes
csatib02 Jan 24, 2024
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
41 changes: 34 additions & 7 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/bank-vaults/secret-init/provider"
"github.com/bank-vaults/secret-init/provider/file"
"github.com/bank-vaults/secret-init/provider/vault"
)

func GetEnvironMap() map[string]string {
Expand All @@ -35,11 +36,19 @@ func GetEnvironMap() map[string]string {
return environ
}

func ExtractPathsFromEnvs(envs map[string]string) []string {
func ExtractPathsFromEnvs(envs map[string]string, providerName string) []string {
var secretPaths []string
currentProvider := providerName

for envKey, path := range envs {
p, path := getProviderPath(path)
// TODO(csatib02): Implement multi-provider support
if p == currentProvider {
// The injector function expects a map of key:value pairs
if p == vault.ProviderName {
path = envKey + "=" + path
}

for _, path := range envs {
if p, path := getProviderPath(path); p != nil {
secretPaths = append(secretPaths, path)
}
}
Expand All @@ -53,7 +62,8 @@ func CreateSecretEnvsFrom(envs map[string]string, secrets []provider.Secret) ([]
// by using the secret path
reversedEnvs := make(map[string]string)
for envKey, path := range envs {
if p, path := getProviderPath(path); p != nil {
p, path := getProviderPath(path)
if p != "" {
reversedEnvs[path] = envKey
}
}
Expand All @@ -73,11 +83,28 @@ func CreateSecretEnvsFrom(envs map[string]string, secrets []provider.Secret) ([]
}

// Returns the detected provider name and path with removed prefix
func getProviderPath(path string) (*string, string) {
func getProviderPath(path string) (string, string) {
if strings.HasPrefix(path, "file:") {
var fileProviderName = file.ProviderName
return &fileProviderName, strings.TrimPrefix(path, "file:")
return fileProviderName, strings.TrimPrefix(path, "file:")
}
if strings.HasPrefix(path, "vault:") {
var vaultProviderName = vault.ProviderName
// Do not remove the prefix since it will be processed during injection
return vaultProviderName, path
}

return "", path
}

func CreateSecretsEnvForVaultProvider(secrets []provider.Secret) []string {
var secretsEnv []string
for _, secret := range secrets {
key := secret.Path
value := secret.Value
secretsEnv = append(secretsEnv, fmt.Sprintf("%s=%s", key, value))
}

return nil, path
return secretsEnv

}
93 changes: 93 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,111 @@ module github.com/bank-vaults/secret-init
go 1.21

require (
emperror.dev/errors v0.8.1
github.com/hashicorp/vault/api v1.10.0
github.com/samber/slog-multi v1.0.2
github.com/samber/slog-syslog v1.0.0
github.com/spf13/cast v1.6.0
)

require (
cloud.google.com/go v0.110.7 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/kms v1.15.2 // indirect
cloud.google.com/go/storage v1.31.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.1.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/aws/aws-sdk-go v1.47.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.20.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.11 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.32 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.31 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.76 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.31 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.38 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.12 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.32 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.31 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.1 // indirect
github.com/aws/smithy-go v1.14.0 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leosayous21/go-azure-msi v0.0.0-20210509193526-19353bedcfc8 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
gocloud.dev v0.34.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.142.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/bank-vaults/internal v0.2.0
github.com/bank-vaults/vault-sdk v0.9.1
github.com/samber/lo v1.38.1 // indirect
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
Expand Down
Loading
Loading