Skip to content

OCI Vault fix #131

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

Merged
merged 7 commits into from
Sep 30, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,10 @@ The following example puts the logfile in the current location with the filename

The exporter will read the password from a secret stored in OCI Vault if you set these two environment variables:

- `VAULT_ID` should be set to the OCID of the OCI vault that you wish to use
- `VAULT_SECRET_NAME` should be set to the name of the secret in the OCI vault which contains the database password
- `OCI_VAULT_ID` should be set to the OCID of the OCI vault that you wish to use
- `OCI_VAULT_SECRET_NAME` should be set to the name of the secret in the OCI vault which contains the database password

Note that the process must be running under a user that has the OCI CLI installed and configured correctly to access the desired tenancy and region.
> Note that the process must be running under a user that has the OCI CLI installed and configured correctly to access the desired tenancy and region. The OCI Profile used is `DEFAULT`.

## Custom metrics

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func main() {
connectString := os.Getenv("DB_CONNECT_STRING")
dbrole := os.Getenv("DB_ROLE")

vaultName, useVault := os.LookupEnv("VAULT_ID")
vaultID, useVault := os.LookupEnv("OCI_VAULT_ID")
if useVault {
level.Info(logger).Log("msg", "VAULT_ID env var is present so using OCI Vault", "vault_name", vaultName)
password = vault.GetVaultSecret(vaultName, os.Getenv("VAULT_SECRET_NAME"))
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "vaultOCID", vaultID)
password = vault.GetVaultSecret(vaultID, os.Getenv("OCI_VAULT_SECRET_NAME"))
}

freeOSMemInterval, enableFree := os.LookupEnv("FREE_INTERVAL")
Expand Down
14 changes: 12 additions & 2 deletions vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ import (
b64 "encoding/base64"
"strings"

"github.com/go-kit/log/level"
"github.com/oracle/oci-go-sdk/v65/common"
"github.com/oracle/oci-go-sdk/v65/example/helpers"
"github.com/oracle/oci-go-sdk/v65/secrets"
"github.com/prometheus/common/promlog"
)

func GetVaultSecret(vaultId string, secretName string) string {
configProvider := common.ConfigurationProviderEnvironmentVariables("vault", "")
promLogConfig := &promlog.Config{}
logger := promlog.New(promLogConfig)

client, err := secrets.NewSecretsClientWithConfigurationProvider(configProvider)
client, err := secrets.NewSecretsClientWithConfigurationProvider(common.DefaultConfigProvider())
helpers.FatalIfError(err)

tenancyID, err := common.DefaultConfigProvider().TenancyOCID()
helpers.FatalIfError(err)
region, err := common.DefaultConfigProvider().Region()
helpers.FatalIfError(err)
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "Region", region)
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "tenancyOCID", tenancyID)

req := secrets.GetSecretBundleByNameRequest{
SecretName: common.String(secretName),
VaultId: common.String(vaultId)}
Expand Down