Skip to content

Commit

Permalink
enhance: allow key override and update deps (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Aug 20, 2024
1 parent 11e7d3a commit 479673e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
uses: github/codeql-action/init@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3.26.3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
uses: github/codeql-action/autobuild@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3.26.3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -64,4 +64,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
uses: github/codeql-action/analyze@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3.26.3
7 changes: 7 additions & 0 deletions cmd/secret-vault/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type (
Source string
// are the paths to store the key in Vela
Path raw.StringSlice
// key overwrite option
Keys map[string]string
}
)

Expand Down Expand Up @@ -95,6 +97,11 @@ func (r *Read) Exec(v *vault.Client) error {
for k, v := range secret.Data {
path = target + k

// if there is a key override, set the new path
if overrideKey, ok := item.Keys[k]; ok {
path = target + overrideKey
}

// set the secret in the Vela temp build volume
logrus.Tracef("write data to file %s", path)

Expand Down
25 changes: 24 additions & 1 deletion cmd/secret-vault/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ func TestVault_Read_Exec(t *testing.T) {
vault, _ := vault.NewMock(t)
source := "/secret/foo"
path := []string{"foobar", "foobar2"}
keys := map[string]string{
"secret": "my_secret",
}

r := &Read{
Items: []*Item{
{
Path: path,
Source: source,
Keys: keys,
},
},
}
Expand Down Expand Up @@ -160,14 +165,17 @@ func TestVault_Read_Unmarshal(t *testing.T) {
r := &Read{
RawItems: `
[
{"path":["foo", "foo2"],"source":"secret/vela/hello_world"}
{"path":["foo", "foo2"],"source":"secret/vela/hello_world","keys":{"foo":"bar"}}
]
`}

want := []*Item{
{
Path: []string{"foo", "foo2"},
Source: "secret/vela/hello_world",
Keys: map[string]string{
"foo": "bar",
},
},
}

Expand Down Expand Up @@ -221,3 +229,18 @@ func TestVault_Read_Unmarshal_Fail(t *testing.T) {
t.Errorf("Unmarshal should have returned err: %v", err)
}
}

func TestVault_Read_Unmarshal_Fail_BadKeyMap(t *testing.T) {
// setup types
r := &Read{
RawItems: `
[
{"path":["foo", "foo2"],"source":"secret/vela/hello_world","keys":["foo=bar"]}
]
`}

err := r.Unmarshal()
if err == nil {
t.Errorf("Unmarshal should have returned err: %v", err)
}
}
50 changes: 25 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/go-vela/secret-vault
go 1.23.0

require (
github.com/hashicorp/vault v1.16.1
github.com/hashicorp/vault v1.16.3
github.com/hashicorp/vault/api v1.14.0
github.com/joho/godotenv v1.5.1
github.com/sirupsen/logrus v1.9.3
Expand All @@ -13,12 +13,12 @@ require (

require (
cloud.google.com/go/cloudsqlconn v1.4.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand All @@ -27,7 +27,7 @@ require (
github.com/coreos/etcd v3.3.27+incompatible // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20220810130054-c7d1c02cb6cf // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
Expand All @@ -36,7 +36,7 @@ require (
github.com/gammazero/workerpool v1.1.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/tink/go v1.7.0 // indirect
github.com/hashicorp-forge/bbolt v1.3.8-hc3 // indirect
Expand All @@ -52,8 +52,8 @@ require (
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgtype v1.14.3 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/joshlf/go-acl v0.0.0-20200411065538-eae00ae38531 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
Expand All @@ -67,13 +67,13 @@ require (
github.com/spf13/cast v1.6.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
)

require (
Expand Down Expand Up @@ -153,7 +153,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gophercloud/gophercloud v0.1.0 // indirect
github.com/hashicorp/consul/sdk v0.14.0 // indirect
github.com/hashicorp/consul/sdk v0.15.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/eventlogger v0.2.8 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -166,14 +166,14 @@ require (
github.com/hashicorp/go-kms-wrapping/wrappers/alicloudkms/v2 v2.0.3 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/awskms/v2 v2.0.9 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/azurekeyvault/v2 v2.0.11 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.11 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/gcpckms/v2 v2.0.12 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/ocikms/v2 v2.0.7 // indirect
github.com/hashicorp/go-kms-wrapping/wrappers/transit/v2 v2.0.11 // indirect
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-raftchunking v0.6.3-0.20191002164813-7e9e8525653a // indirect
github.com/hashicorp/go-retryablehttp v0.7.6 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/awsutil v0.3.0 // indirect
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 // indirect
Expand Down Expand Up @@ -263,21 +263,21 @@ require (
go.mongodb.org/mongo-driver v1.13.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.163.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/resty.v1 v1.12.0 // indirect
Expand Down
Loading

0 comments on commit 479673e

Please sign in to comment.