Skip to content

Commit d37acee

Browse files
docs: update README.md
1 parent 8c3aae2 commit d37acee

1 file changed

Lines changed: 26 additions & 37 deletions

File tree

README.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -308,51 +308,40 @@ the value correctly.
308308
</details>
309309

310310
<details>
311-
<summary>Using AWS Secrets Manager</summary>
311+
<summary>Accessing DSN from Secret Managers</summary>
312312

313-
If the database runs on AWS EC2 instance, this is a secure option to store the DSN without having it in
314-
the configuration file. To use this option:
313+
If the database runs on AWS or Google Cloud, you might want to store the DSN in their Secret Manager services and allow
314+
SQL Exporter to access it from there. This way you can avoid hardcoding credentials in the configuration file and
315+
benefit from the security features of these services. In addition, Vault is also available as a secret manager option
316+
for SQL Exporter.
315317

316-
- Create a [secret](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_create-basic-secret.html) in
317-
key/value pairs format, specify Key `data_source_name` and then for Value enter the DSN value.
318-
For the secret name, enter a name for your secret, and pass that name in the configuration file as a value for
319-
`aws_secret_name` item under `target`. Secret json example:
318+
The secrets can be referenced in the configuration file as a value for `data_source_name` item using the following
319+
syntax:
320320

321-
```json
322-
{
323-
"data_source_name": "sqlserver://prom_user:prom_password@dbserver1.example.com:1433"
324-
}
325321
```
326-
327-
- Configuration file example:
328-
329-
```yaml
330-
...
331-
target:
332-
aws_secret_name: '<AWS_SECRET_NAME>'
333-
...
322+
awssecretsmanager://<SECRET_NAME>?region=<AWS_REGION>&key=<JSON_KEY>
323+
gcpsecretsmanager://<SECRET_NAME>?project_id=<GCP_PROJECT_ID>&key=<JSON_KEY>
324+
hashivault://<MOUNT>/<SECRET_PATH>?key=<JSON_KEY>
334325
```
335326

336-
- Allow read-only access from EC2 IAM role to the secret by attaching a [resource-based
337-
policy](https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_resource-based-policies.html) to
338-
the secret. Policy example:
339-
340-
```json
341-
{
342-
"Version" : "2012-10-17",
343-
"Statement" : [
344-
{
345-
"Effect": "Allow",
346-
"Principal": {"AWS": "arn:aws:iam::123456789012:role/EC2RoleToAccessSecrets"},
347-
"Action": "secretsmanager:GetSecretValue",
348-
"Resource": "*",
349-
}
350-
]
351-
}
352-
```
327+
The secret value can be a simple string or a JSON object. If it's a JSON object, you need to specify the `key` query
328+
parameter to indicate which value to use as the DSN. If the secret is a valid json but the key is not specified, SQL
329+
Exporter will try to use the value of `data_source_name` key by default. If a simple string, then it will be used as
330+
the DSN directly. Using JSON format gives more flexibility and allows to store additional information or multiple DSNs
331+
in the same secret resource.
332+
333+
Secret references are supported for both single-target and jobs setups, so you can use them in both cases without any
334+
issues. Just make sure to use the correct syntax and provide the necessary parameters for the secret manager you
335+
choose. Also check the permissions and access policies for the secret manager to ensure that SQL Exporter has the
336+
necessary access to read the secrets.
353337

354-
Currently, AWS Secret Manager integration is only available for a single target configuration.
338+
Secrets are only resolved at startup, so if the secret value changes, you need to restart SQL Exporter to pick up the
339+
new value. Or use the `reload` endpoint to trigger a configuration reload without restarting the process, but keep in
340+
mind that this will also reload the entire configuration, not just the secrets.
355341

342+
For Vault, you also need to specify the `VAULT_ADDR` and `VAULT_TOKEN` environment variables to allow SQL Exporter to
343+
authenticate. This is a regular practice and goes beyond the scope of this document, so please refer to Vault
344+
documentation for more details on how to set up and use Vault for secrets management.
356345
</details>
357346

358347
<details>

0 commit comments

Comments
 (0)