Merge pull request #655 from hashicorp/f-exec-acl

agent: pass locally configured token during remote exec
This commit is contained in:
Ryan Uber 2015-01-29 11:16:01 -08:00
commit 1caaae0ff7
2 changed files with 32 additions and 2 deletions

View File

@ -242,6 +242,7 @@ func (a *Agent) remoteExecGetSpec(event *remoteExecEvent, spec *remoteExecSpec)
AllowStale: true, // Stale read for scale! Retry on failure.
},
}
get.Token = a.config.ACLToken
var out structs.IndexedDirEntries
QUERY:
if err := a.RPC("KVS.Get", &get, &out); err != nil {
@ -308,6 +309,7 @@ func (a *Agent) remoteExecWriteKey(event *remoteExecEvent, suffix string, val []
Session: event.Session,
},
}
write.Token = a.config.ACLToken
var success bool
if err := a.RPC("KVS.Apply", &write, &success); err != nil {
return err

View File

@ -84,7 +84,20 @@ func TestRexecWriter(t *testing.T) {
}
func TestRemoteExecGetSpec(t *testing.T) {
dir, agent := makeAgent(t, nextConfig())
config := nextConfig()
testRemoteExecGetSpec(t, config)
}
func TestRemoteExecGetSpec_ACLToken(t *testing.T) {
config := nextConfig()
config.ACLDatacenter = "dc1"
config.ACLToken = "root"
config.ACLDefaultPolicy = "deny"
testRemoteExecGetSpec(t, config)
}
func testRemoteExecGetSpec(t *testing.T, c *Config) {
dir, agent := makeAgent(t, c)
defer os.RemoveAll(dir)
defer agent.Shutdown()
testutil.WaitForLeader(t, agent.RPC, "dc1")
@ -117,7 +130,20 @@ func TestRemoteExecGetSpec(t *testing.T) {
}
func TestRemoteExecWrites(t *testing.T) {
dir, agent := makeAgent(t, nextConfig())
config := nextConfig()
testRemoteExecWrites(t, config)
}
func TestRemoteExecWrites_ACLToken(t *testing.T) {
config := nextConfig()
config.ACLDatacenter = "dc1"
config.ACLToken = "root"
config.ACLDefaultPolicy = "deny"
testRemoteExecWrites(t, config)
}
func testRemoteExecWrites(t *testing.T, c *Config) {
dir, agent := makeAgent(t, c)
defer os.RemoveAll(dir)
defer agent.Shutdown()
testutil.WaitForLeader(t, agent.RPC, "dc1")
@ -275,6 +301,7 @@ func setKV(t *testing.T, agent *Agent, key string, val []byte) {
Value: val,
},
}
write.Token = agent.config.ACLToken
var success bool
if err := agent.RPC("KVS.Apply", &write, &success); err != nil {
t.Fatalf("err: %v", err)
@ -286,6 +313,7 @@ func getKV(t *testing.T, agent *Agent, key string) *structs.DirEntry {
Datacenter: agent.config.Datacenter,
Key: key,
}
req.Token = agent.config.ACLToken
var out structs.IndexedDirEntries
if err := agent.RPC("KVS.Get", &req, &out); err != nil {
t.Fatalf("err: %v", err)