Don't allow connect watches in agent/cli yet

pull/4275/head
Paul Banks 7 years ago committed by Mitchell Hashimoto
parent 946e872f2f
commit 1b197d934a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A

@ -621,6 +621,16 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {
return fmt.Errorf("Handler type '%s' not recognized", params["handler_type"]) return fmt.Errorf("Handler type '%s' not recognized", params["handler_type"])
} }
// Don't let people use connect watches via this mechanism for now as it
// needs thought about how to do securely and shouldn't be necessary. Note
// that if the type assertion fails an type is not a string then
// ParseExample below will error so we don't need to handle that case.
if typ, ok := params["type"].(string); ok {
if strings.HasPrefix(typ, "connect_") {
return fmt.Errorf("Watch type %s is not allowed in agent config", typ)
}
}
// Parse the watches, excluding 'handler' and 'args' // Parse the watches, excluding 'handler' and 'args'
wp, err := watch.ParseExempt(params, []string{"handler", "args"}) wp, err := watch.ParseExempt(params, []string{"handler", "args"})
if err != nil { if err != nil {

@ -2259,6 +2259,18 @@ func TestAgent_reloadWatches(t *testing.T) {
t.Fatalf("bad: %s", err) t.Fatalf("bad: %s", err)
} }
// Should fail to reload with connect watches
newConf.Watches = []map[string]interface{}{
{
"type": "connect_roots",
"key": "asdf",
"args": []interface{}{"ls"},
},
}
if err := a.reloadWatches(&newConf); err == nil || !strings.Contains(err.Error(), "not allowed in agent config") {
t.Fatalf("bad: %s", err)
}
// Should still succeed with only HTTPS addresses // Should still succeed with only HTTPS addresses
newConf.HTTPSAddrs = newConf.HTTPAddrs newConf.HTTPSAddrs = newConf.HTTPAddrs
newConf.HTTPAddrs = make([]net.Addr, 0) newConf.HTTPAddrs = make([]net.Addr, 0)

@ -135,6 +135,11 @@ func (c *cmd) Run(args []string) int {
return 1 return 1
} }
if strings.HasPrefix(wp.Type, "connect_") {
c.UI.Error(fmt.Sprintf("Type %s is not supported in the CLI tool", wp.Type))
return 1
}
// Create and test the HTTP client // Create and test the HTTP client
client, err := c.http.APIClient() client, err := c.http.APIClient()
if err != nil { if err != nil {

@ -33,3 +33,23 @@ func TestWatchCommand(t *testing.T) {
t.Fatalf("bad: %#v", ui.OutputWriter.String()) t.Fatalf("bad: %#v", ui.OutputWriter.String())
} }
} }
func TestWatchCommandNoConnect(t *testing.T) {
t.Parallel()
a := agent.NewTestAgent(t.Name(), ``)
defer a.Shutdown()
ui := cli.NewMockUi()
c := New(ui, nil)
args := []string{"-http-addr=" + a.HTTPAddr(), "-type=connect_leaf"}
code := c.Run(args)
if code != 1 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
if !strings.Contains(ui.ErrorWriter.String(),
"Type connect_leaf is not supported in the CLI tool") {
t.Fatalf("bad: %#v", ui.ErrorWriter.String())
}
}

Loading…
Cancel
Save