Skip to content
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
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ Package used for retrieving application settings from various sources.

Currently supported variable and secrets implementations:

- AWS SecretsManager
- AWS ParameterStore
- AzureKeyvault Secrets
- TODO:
- GCP
- Hashicorp
- [AWS SecretsManager](https://aws.amazon.com/secrets-manager/)
- [AWS ParameterStore](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)
- [AzureKeyvault Secrets](https://azure.microsoft.com/en-gb/products/key-vault/)
- see [Special consideration for AZKVSECRET](#special-consideration-for-azkvsecret) around how to structure the token in this case.
- [GCP Secrets](https://cloud.google.com/secret-manager)
- [Hashicorp Vault](https://developer.hashicorp.com/vault/docs/secrets/kv)
- using the V2 endpoint
- see

The main driver is to use component level configuration objects, if stored in a `"namespaced"` manner e.g. in AWS ParamStore as `/nonprod/component-service-a/configVar`, however this is not a requirement and the param name can be whatever. Though whilst using some sort of a organised manner it will be more straight forward to allow other services to consume certain secrets/params based on resource/access policies.

Expand Down Expand Up @@ -137,6 +139,15 @@ For Azure KeyVault the first part of the token needs to be the name of the vault

> The preceeding slash to the vault name is optional - `AZKVSECRET#/test-vault/no-slash-token-1` and `AZKVSECRET#test-vault/no-slash-token-1` will both identify the vault of name `test-vault`

### Special consideration for HashicorpVault

For HashicorpVault the first part of the token needs to be the name of the mountpath. In Dev Vaults this is `"secret"`,
e.g.:

`VAULT://secret/demo/configmanager|test`

The Hashicorp Vault functions in the same exact way as the other implementations. It will retrieve the JSON object and can be looked up within it by using a key separator.

## Go API

latest api [here](https://pkg.go.dev/github.com/dnitsch/configmanager)
Expand Down Expand Up @@ -240,6 +251,6 @@ func credentialString(ctx context.Context, pwdToken, hostToken string) (string,
## Help

- More implementations should be easily added with a specific implementation under the strategy interface
- e.g. GCP equivalent
- see [add additional providers](docs/adding-provider.md)

- maybe run as cron in the background to perform a periodic sync in case values change?
47 changes: 25 additions & 22 deletions docs/adding-provider.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
# adding provider

Add Token

`VarPrefix = map[string]bool{SecretMgrPrefix: true, ParamStorePrefix: true, AzKeyVaultSecretsPrefix: true, GcpSecretMgrPrefix: true}` // <-- ADD here
Add Token Prefix

```go
const (
// tokenSeparator used for identifying the end of a prefix and beginning of token
// see notes about special consideration for AZKVSECRET tokens
tokenSeparator = "#"
// keySeparator used for accessing nested objects within the retrieved map
keySeparator = "|"
// AWS SecretsManager prefix
SecretMgrPrefix = "AWSSECRETS"
SecretMgrPrefix ImplementationPrefix = "AWSSECRETS"
// AWS Parameter Store prefix
ParamStorePrefix = "AWSPARAMSTR"
ParamStorePrefix ImplementationPrefix = "AWSPARAMSTR"
// Azure Key Vault Secrets prefix
AzKeyVaultSecretsPrefix = "AZKVSECRET"
// GCP SecretsManager prefix
GcpSecretMgrPrefix = "GCPSECRETS" // <-- ADD here
AzKeyVaultSecretsPrefix ImplementationPrefix = "AZKVSECRET"
// Hashicorp Vault prefix
HashicorpVaultPrefix ImplementationPrefix = "VAULT"
// GcpSecrets
GcpSecretsPrefix ImplementationPrefix = "GCPSECRETS"
)
```

inside

```go
func (imp *GcpSecrets) getTokenValue(v *retrieveStrategy) (string, error) {
var (
// default varPrefix used by the replacer function
// any token must beging with one of these else
// it will be skipped as not a replaceable token
VarPrefix = map[ImplementationPrefix]bool{SecretMgrPrefix: true, ParamStorePrefix: true, AzKeyVaultSecretsPrefix: true, GcpSecretsPrefix: true, HashicorpVaultPrefix: true} // <-- ADD here
)
```

log.Infof("%s", "Concrete implementation GcpSecrets")
log.Infof("Getting Secret: %s", imp.token)
ensure your implementation satisfy the `genVarsStrategy` interface

```go
type genVarsStrategy interface {
getTokenValue(rs *retrieveStrategy) (s string, e error)
setToken(s string)
setValue(s string)
}
```

input := &gcpsecretspb.AccessSecretVersionRequest{
Name: fmt.Sprintf("%s/versions/latest", v.stripPrefix(imp.token, GcpSecretsPrefix)), // <-- Ensure this is set correctly
}
```
Even if the native type is K/V return a marshalled version of the JSON as the rest of the flow will decide how to present it back to the final consumer.
2 changes: 1 addition & 1 deletion pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
// default varPrefix used by the replacer function
// any token must beging with one of these else
// it will be skipped as not a replaceable token
VarPrefix = map[ImplementationPrefix]bool{SecretMgrPrefix: true, ParamStorePrefix: true, AzKeyVaultSecretsPrefix: true, HashicorpVaultPrefix: true}
VarPrefix = map[ImplementationPrefix]bool{SecretMgrPrefix: true, ParamStorePrefix: true, AzKeyVaultSecretsPrefix: true, GcpSecretsPrefix: true, HashicorpVaultPrefix: true}
)

// Generatoriface describes the exported methods
Expand Down