Skip to content

Commit 27077d1

Browse files
gr0migmartri
andauthored
feat: Add support for GCP Secret Manager (#124)
Signed-off-by: gr0 <[email protected]> Co-authored-by: Miguel Martinez Trivino <[email protected]>
1 parent 5b448c5 commit 27077d1

File tree

17 files changed

+1018
-99
lines changed

17 files changed

+1018
-99
lines changed

app/artifact-cas/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Its structure contains the following top to down layers.
2020

2121
## System Dependencies
2222

23-
The CAS proxy **has only one running dependency**. A secret storage backend to retrieve the OCI repository credentials. Currently, we support both [Hashicorp Vault](https://www.vaultproject.io/) and [AWS Secret Manager](https://aws.amazon.com/secrets-manager/).
23+
The CAS proxy **has only one running dependency**. A secret storage backend to retrieve the OCI repository credentials. Currently, we support [Hashicorp Vault](https://www.vaultproject.io/), [AWS Secret Manager](https://aws.amazon.com/secrets-manager/) AND [GCP Secret Manager](https://cloud.google.com/secret-manager).
2424

2525
This secret backend is used to download OCI repository credentials (repository path + key pair) during upload/downloads. This makes the Artifact CAS multi-tenant by default since the destination OCI backend gets selected at runtime.
2626

app/artifact-cas/cmd/main.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/chainloop-dev/chainloop/internal/credentials"
2626
awssecrets "github.com/chainloop-dev/chainloop/internal/credentials/aws"
27+
"github.com/chainloop-dev/chainloop/internal/credentials/gcp"
2728
"github.com/chainloop-dev/chainloop/internal/credentials/vault"
2829
"github.com/getsentry/sentry-go"
2930

@@ -125,18 +126,20 @@ func main() {
125126
}
126127

127128
func newCredentialsReader(conf *conf.Credentials, l log.Logger) (credentials.Reader, error) {
128-
awsc, vaultc := conf.GetAwsSecretManager(), conf.GetVault()
129-
if awsc == nil && vaultc == nil {
129+
awsc, vaultc, gcpc := conf.GetAwsSecretManager(), conf.GetVault(), conf.GetGcpSecretManager()
130+
if awsc == nil && vaultc == nil && gcpc == nil {
130131
return nil, errors.New("no credentials manager configuration found")
131-
} else if awsc != nil && vaultc != nil {
132-
return nil, errors.New("only one credentials manager can be configured")
133132
}
134133

135-
if c := conf.GetAwsSecretManager(); c != nil {
136-
return newAWSCredentialsManager(c, l)
134+
if awsc != nil {
135+
return newAWSCredentialsManager(awsc, l)
137136
}
138137

139-
return newVaultCredentialsManager(conf.GetVault(), l)
138+
if gcpc != nil {
139+
return newGCPCredentialsManager(gcpc, l)
140+
}
141+
142+
return newVaultCredentialsManager(vaultc, l)
140143
}
141144

142145
func newAWSCredentialsManager(conf *conf.Credentials_AWSSecretManager, l log.Logger) (*awssecrets.Manager, error) {
@@ -180,6 +183,26 @@ func newVaultCredentialsManager(conf *conf.Credentials_Vault, l log.Logger) (*va
180183
return m, nil
181184
}
182185

186+
func newGCPCredentialsManager(conf *conf.Credentials_GCPSecretManager, l log.Logger) (*gcp.Manager, error) {
187+
if conf == nil {
188+
return nil, errors.New("uncompleted configuration for GCP secret manager")
189+
}
190+
191+
opts := &gcp.NewManagerOpts{
192+
ProjectID: conf.ProjectId,
193+
ServiceAccountKey: conf.ServiceAccountKey,
194+
SecretPrefix: conf.SecretPrefix,
195+
Logger: l,
196+
}
197+
198+
m, err := gcp.NewManager(opts)
199+
if err != nil {
200+
return nil, fmt.Errorf("configuring the GCP secret manager: %w", err)
201+
}
202+
203+
return m, nil
204+
}
205+
183206
func initSentry(c *conf.Bootstrap, logger log.Logger) (cleanupFunc func(), err error) {
184207
cleanupFunc = func() {
185208
sentry.Flush(2 * time.Second)

app/artifact-cas/configs/samples/config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ observability:
2222
sentry:
2323
dsn: "http://sentryDomain"
2424
environment: development # production
25+
26+
## gcp_secret_manager:
27+
## project_id: 522312304548
28+
## auth_key: "./configs/gcp_auth_key.json"
29+
## secret_prefix: "pre-"

app/artifact-cas/internal/conf/conf.pb.go

Lines changed: 149 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)