Skip to content

Commit

Permalink
Hide consul token on UI. (prometheus#2797)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vynar authored and brian-brazil committed Jun 1, 2017
1 parent a391156 commit dbe2eb2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func (c *FileSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// ConsulSDConfig is the configuration for Consul service discovery.
type ConsulSDConfig struct {
Server string `yaml:"server"`
Token string `yaml:"token,omitempty"`
Token Secret `yaml:"token,omitempty"`
Datacenter string `yaml:"datacenter,omitempty"`
TagSeparator string `yaml:"tag_separator,omitempty"`
Scheme string `yaml:"scheme,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ var expectedConf = &Config{
ConsulSDConfigs: []*ConsulSDConfig{
{
Server: "localhost:1234",
Token: "mysecret",
Services: []string{"nginx", "cache", "mysql"},
TagSeparator: DefaultConsulSDConfig.TagSeparator,
Scheme: "https",
Expand Down Expand Up @@ -542,7 +543,7 @@ func TestLoadConfig(t *testing.T) {
s := c.String()
secretRe := regexp.MustCompile("<secret>")
matches := secretRe.FindAllStringIndex(s, -1)
if len(matches) != 5 || strings.Contains(s, "mysecret") {
if len(matches) != 6 || strings.Contains(s, "mysecret") {
t.Fatalf("config's String method reveals authentication credentials.")
}

Expand Down
1 change: 1 addition & 0 deletions config/testdata/conf.good.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ scrape_configs:

consul_sd_configs:
- server: 'localhost:1234'
token: mysecret
services: ['nginx', 'cache', 'mysql']
scheme: https
tls_config:
Expand Down
2 changes: 1 addition & 1 deletion discovery/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewDiscovery(conf *config.ConsulSDConfig, logger log.Logger) (*Discovery, e
Address: conf.Server,
Scheme: conf.Scheme,
Datacenter: conf.Datacenter,
Token: conf.Token,
Token: string(conf.Token),
HttpAuth: &consul.HttpBasicAuth{
Username: conf.Username,
Password: string(conf.Password),
Expand Down

0 comments on commit dbe2eb2

Please sign in to comment.