Skip to content

Commit

Permalink
Merge pull request #2988 from jvoorhis/redact-vault-token
Browse files Browse the repository at this point in the history
Redact Vault.Token from AgentSelf response.
  • Loading branch information
dadgar authored Aug 8, 2017
2 parents b14cc62 + f7041f5 commit 2a1b886
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/serf/serf"
"github.com/mitchellh/copystructure"
)

type Member struct {
Expand Down Expand Up @@ -52,10 +53,19 @@ func (s *HTTPServer) AgentSelfRequest(resp http.ResponseWriter, req *http.Reques
}

self := agentSelf{
Config: s.agent.config,
Member: nomadMember(member),
Stats: s.agent.Stats(),
}
if ac, err := copystructure.Copy(s.agent.config); err != nil {
return nil, CodedError(500, err.Error())
} else {
self.Config = ac.(*Config)
}

if self.Config != nil && self.Config.Vault != nil && self.Config.Vault.Token != "" {
self.Config.Vault.Token = "<redacted>"
}

return self, nil
}

Expand Down
17 changes: 17 additions & 0 deletions command/agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ func TestHTTP_AgentSelf(t *testing.T) {
if len(self.Stats) == 0 {
t.Fatalf("bad: %#v", self)
}

// Check the Vault config
if self.Config.Vault.Token != "" {
t.Fatalf("bad: %#v", self)
}

// Assign a Vault token and assert it is redacted.
s.Config.Vault.Token = "badc0deb-adc0-deba-dc0d-ebadc0debadc"
respW = httptest.NewRecorder()
obj, err = s.Server.AgentSelfRequest(respW, req)
if err != nil {
t.Fatalf("err: %v", err)
}
self = obj.(agentSelf)
if self.Config.Vault.Token != "<redacted>" {
t.Fatalf("bad: %#v", self)
}
})
}

Expand Down

0 comments on commit 2a1b886

Please sign in to comment.