Hide consul token on UI. (#2797)

This commit is contained in:
Roman Vynar 2017-06-02 00:14:23 +03:00 committed by Brian Brazil
parent a391156dfb
commit dbe2eb2afc
4 changed files with 5 additions and 3 deletions

View file

@ -835,7 +835,7 @@ func (c *FileSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// ConsulSDConfig is the configuration for Consul service discovery. // ConsulSDConfig is the configuration for Consul service discovery.
type ConsulSDConfig struct { type ConsulSDConfig struct {
Server string `yaml:"server"` Server string `yaml:"server"`
Token string `yaml:"token,omitempty"` Token Secret `yaml:"token,omitempty"`
Datacenter string `yaml:"datacenter,omitempty"` Datacenter string `yaml:"datacenter,omitempty"`
TagSeparator string `yaml:"tag_separator,omitempty"` TagSeparator string `yaml:"tag_separator,omitempty"`
Scheme string `yaml:"scheme,omitempty"` Scheme string `yaml:"scheme,omitempty"`

View file

@ -247,6 +247,7 @@ var expectedConf = &Config{
ConsulSDConfigs: []*ConsulSDConfig{ ConsulSDConfigs: []*ConsulSDConfig{
{ {
Server: "localhost:1234", Server: "localhost:1234",
Token: "mysecret",
Services: []string{"nginx", "cache", "mysql"}, Services: []string{"nginx", "cache", "mysql"},
TagSeparator: DefaultConsulSDConfig.TagSeparator, TagSeparator: DefaultConsulSDConfig.TagSeparator,
Scheme: "https", Scheme: "https",
@ -542,7 +543,7 @@ func TestLoadConfig(t *testing.T) {
s := c.String() s := c.String()
secretRe := regexp.MustCompile("<secret>") secretRe := regexp.MustCompile("<secret>")
matches := secretRe.FindAllStringIndex(s, -1) 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.") t.Fatalf("config's String method reveals authentication credentials.")
} }

View file

@ -113,6 +113,7 @@ scrape_configs:
consul_sd_configs: consul_sd_configs:
- server: 'localhost:1234' - server: 'localhost:1234'
token: mysecret
services: ['nginx', 'cache', 'mysql'] services: ['nginx', 'cache', 'mysql']
scheme: https scheme: https
tls_config: tls_config:

View file

@ -105,7 +105,7 @@ func NewDiscovery(conf *config.ConsulSDConfig, logger log.Logger) (*Discovery, e
Address: conf.Server, Address: conf.Server,
Scheme: conf.Scheme, Scheme: conf.Scheme,
Datacenter: conf.Datacenter, Datacenter: conf.Datacenter,
Token: conf.Token, Token: string(conf.Token),
HttpAuth: &consul.HttpBasicAuth{ HttpAuth: &consul.HttpBasicAuth{
Username: conf.Username, Username: conf.Username,
Password: string(conf.Password), Password: string(conf.Password),