Skip to content
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

TT-916 Add _secret suffix to secrets in toml #835

Merged
merged 4 commits into from
Feb 26, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ When using `in-memory` or `file` target no other configuration variables are req
[Logging.Loki]
tenant_id="promtail"
url="https://change.me"
basic_auth="my-secret-auth"
bearer_token="bearer-token"
basic_auth_secret="my-secret-auth"
bearer_token_secret="bearer-token"
```

Also, do remember that different URL should be used when running in CI and everywhere else. In CI it should be a public endpoint, while in local environment it should be a private one.
Expand Down
10 changes: 7 additions & 3 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ It's up to the user to provide a way to read the config from file and unmarshal

Also you might find `BytesToAnyTomlStruct(logger zerolog.Logger, filename, configurationName string, target any, content []byte) error` utility method useful for unmarshalling TOMLs read from env var or files into a struct

## Secrets in TOML config

For all values regarded as secrets, their keys should end with the `_secret` suffix. For example, use `basic_auth_secret="basic-auth"` instead of `basic_auth="basic-auth"`.

## Working example

For a full working example making use of all the building blocks see [testconfig.go](../config/examples/testconfig.go). It provides methods for reading TOML, applying overrides and validating non-empty config blocks. It supports 4 levels of overrides, in order of precedence:
Expand Down Expand Up @@ -216,7 +220,7 @@ version="$CHAINLINK_VERSION"
enabled=$pyroscope_enabled
server_url="$PYROSCOPE_SERVER"
environment="$PYROSCOPE_ENVIRONMENT"
key="$PYROSCOPE_KEY"
key_secret="$PYROSCOPE_KEY"

[Logging]
test_log_collect=$test_log_collect
Expand All @@ -228,8 +232,8 @@ log_targets=$log_targets
[Logging.Loki]
tenant_id="$LOKI_TENANT_ID"
url="$LOKI_URL"
basic_auth="$LOKI_BASIC_AUTH"
bearer_token="$LOKI_BEARER_TOKEN"
basic_auth_secret="$LOKI_BASIC_AUTH"
bearer_token_secret="$LOKI_BEARER_TOKEN"

[Logging.Grafana]
url="$GRAFANA_URL"
Expand Down
6 changes: 3 additions & 3 deletions config/examples/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ tenant_id="tenant_id"
# full URL of Loki ingest endpoint
endpoint="https://loki.url/api/v3/push"
# currently only needed when using public instance
basic_auth="loki-basic-auth"
basic_auth_secret="loki-basic-auth"
# only needed for cloud grafana
bearer_token="bearer_token"
bearer_token_secret="bearer_token"

# LogStream will try to shorten Grafana URLs by default (if all 3 variables are set)
[Logging.Grafana]
# grafana url (trailing "/" will be stripped)
base_url="http://grafana.url"
# url of your grafana dashboard (prefix and suffix "/" are stirpped), example: /d/ad61652-2712-1722/my-dashboard
dashboard_url="/d/your-dashboard"
bearer_token="my-awesome-token"
bearer_token_secret="my-awesome-token"

# if you want to use polygon_mumbial
[Network]
Expand Down
6 changes: 3 additions & 3 deletions config/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (l *LogStreamConfig) Validate() error {
type LokiConfig struct {
TenantId *string `toml:"tenant_id"`
Endpoint *string `toml:"endpoint"`
BasicAuth *string `toml:"basic_auth"`
BearerToken *string `toml:"bearer_token"`
BasicAuth *string `toml:"basic_auth_secret"`
BearerToken *string `toml:"bearer_token_secret"`
}

// Validate checks that the loki config is valid, which means that
Expand All @@ -90,7 +90,7 @@ func (l *LokiConfig) Validate() error {
type GrafanaConfig struct {
BaseUrl *string `toml:"base_url"`
DashboardUrl *string `toml:"dashboard_url"`
BearerToken *string `toml:"bearer_token"`
BearerToken *string `toml:"bearer_token_secret"`
}

// Validate checks that the grafana config is valid, which means that
Expand Down
2 changes: 1 addition & 1 deletion config/pyroscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type PyroscopeConfig struct {
Enabled *bool `toml:"enabled"`
ServerUrl *string `toml:"server_url"`
Key *string `toml:"key"`
Key *string `toml:"key_secret"`
Environment *string `toml:"environment"`
}

Expand Down
Loading