Skip to content

Commit

Permalink
Changes remote exec KV read to call GetTokenForAgent(), which can use
Browse files Browse the repository at this point in the history
the acl_agent_token instead of the acl_token.

Fixes #3160.
  • Loading branch information
slackpad committed Jul 17, 2017
1 parent 34dda65 commit 481c1f9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
4 changes: 2 additions & 2 deletions agent/remote_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (a *Agent) remoteExecGetSpec(event *remoteExecEvent, spec *remoteExecSpec)
AllowStale: true, // Stale read for scale! Retry on failure.
},
}
get.Token = a.config.ACLToken
get.Token = a.config.GetTokenForAgent()
var out structs.IndexedDirEntries
QUERY:
if err := a.RPC("KVS.Get", &get, &out); err != nil {
Expand Down Expand Up @@ -310,7 +310,7 @@ func (a *Agent) remoteExecWriteKey(event *remoteExecEvent, suffix string, val []
Session: event.Session,
},
}
write.Token = a.config.ACLToken
write.Token = a.config.GetTokenForAgent()
var success bool
if err := a.RPC("KVS.Apply", &write, &success); err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions agent/remote_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func TestRemoteExecGetSpec_ACLToken(t *testing.T) {
testRemoteExecGetSpec(t, cfg)
}

func TestRemoteExecGetSpec_ACLAgentToken(t *testing.T) {
t.Parallel()
cfg := TestConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLAgentToken = "root"
cfg.ACLDefaultPolicy = "deny"
testRemoteExecGetSpec(t, cfg)
}

func testRemoteExecGetSpec(t *testing.T, c *Config) {
a := NewTestAgent(t.Name(), nil)
defer a.Shutdown()
Expand Down
8 changes: 5 additions & 3 deletions website/source/docs/agent/options.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,13 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass
<a href="#acl_enforce_version_8">`acl_enforce_version_8`</a> is set to true.

* <a name="acl_agent_token"></a><a href="#acl_agent_token">`acl_agent_token`</a> - Used for clients
and servers to perform internal operations to the service catalog. If this isn't specified, then
the <a href="#acl_token">`acl_token`</a> will be used. This was added in Consul 0.7.2.
and servers to perform internal operations. If this isn't specified, then the
<a href="#acl_token">`acl_token`</a> will be used. This was added in Consul 0.7.2.
<br><br>
This token must at least have write access to the node name it will register as in order to set any
of the node-level information in the catalog such as metadata, or the node's tagged addresses.
of the node-level information in the catalog such as metadata, or the node's tagged addresses. There
are other places this token is used, please see [ACL Agent Token](/docs/guides/acl.html#acl-agent-token)
for more details.

* <a name="acl_enforce_version_8"></a><a href="#acl_enforce_version_8">`acl_enforce_version_8`</a> -
Used for clients and servers to determine if enforcement should occur for new ACL policies being
Expand Down
42 changes: 35 additions & 7 deletions website/source/docs/guides/acl.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ system, or accessing Consul in special situations:

| Special Token | Servers | Clients | Purpose |
| ------------- | ------- | ------- | ------- |
| [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) | `OPTIONAL` | `OPTIONAL` | Special token that can be used to access [Agent API](/api/agent.html) when the ACL datacenter isn't available, or servers are offline (for clients); used for setting up the cluster such as doing initial join operations |
| [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) | `OPTIONAL` | `OPTIONAL` | Special token that is used for an agent's internal operations with the [Catalog API](/api/catalog.html); this needs to have at least `node` policy access so the agent can self update its registration information, and also needs `service` read access for all services that will be registered with that node for [anti-entropy](/docs/internals/anti-entropy.html) syncing |
| [`acl_master_token`](/docs/agent/options.html#acl_master_token) | `REQUIRED` | `N/A` | Special token used to bootstrap the ACL system, see details below |
| [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) | `OPTIONAL` | `OPTIONAL` | Special token that can be used to access [Agent API](/api/agent.html) when the ACL datacenter isn't available, or servers are offline (for clients); used for setting up the cluster such as doing initial join operations, see the [ACL Agent Master Token](#acl-agent-master-token) section for more details |
| [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) | `OPTIONAL` | `OPTIONAL` | Special token that is used for an agent's internal operations, see the [ACL Agent Token](#acl-agent-token) section for more details |
| [`acl_master_token`](/docs/agent/options.html#acl_master_token) | `REQUIRED` | `N/A` | Special token used to bootstrap the ACL system, see the [Bootstrapping ACLs](#bootstrapping-acls) section for more details |
| [`acl_token`](/docs/agent/options.html#acl_token) | `OPTIONAL` | `OPTIONAL` | Default token to use for client requests where no token is supplied; this is often configured with read-only access to services to enable DNS service discovery on agents |

Since it is designed to be used when the Consul servers are not available, the
`acl_agent_master_token` is managed locally on the agent and does not need to have a
policy defined on the Consul servers via the ACL API. Once set, it implicitly has the
following policy associated with it (the `node` policy was added in Consul 0.9.0):
<a name="acl-agent-master-token"></a>
**`ACL Agent Master Token`**

Since the [`acl_agent_master_token`](/docs/agent/options.html#acl_agent_master_token) is designed to be used when the Consul servers are not available, its policy is managed locally on the agent and does not need to have a token defined on the Consul servers via the ACL API. Once set, it implicitly has the following policy associated with it (the `node` policy was added in Consul 0.9.0):

```text
agent "<node name of agent>" {
Expand All @@ -147,6 +147,32 @@ node "" {
}
```

<a name="acl-agent-token"></a>
**`ACL Agent Token`**

The [`acl_agent_token`](/docs/agent/options.html#acl_agent_token) is a special token that is used for an agent's internal operations. It isn't used directly for any user-initiated operations like the [`acl_token`](/docs/agent/options.html#acl_token), though if the `acl_agent_token` isn't configured the `acl_token` will be used. The ACL agent token is used for the following operations by the agent:

1. Updating the agent's node entry using the [Catalog API](/api/catalog.html), including updating its node metadata, tagged addresses, and network coordinates
2. Performing [anti-entropy](/docs/internals/anti-entropy.html) syncing, in particular reading the node metadata and services registered with the catalog
3. Reading and writing the special `_rexec` section of the KV store when executing [`consul exec`](/docs/commands/exec.html) commands

Here's an example policy sufficient to accomplish the above for a node called `mynode`:

```text
node "mynode" {
policy = "write"
}
service "" {
policy = "read"
}
key "_rexec" {
policy = "write"
}
```

The `service` policy needs `read` access for any services that can be registered on the agent. If [remote exec is disabled](/docs/agent/options.html#disable_remote_exec), the default, then the `key` policy can be omitted.

>>>>>>> Changes remote exec KV read to call GetTokenForAgent(), which can use
#### Bootstrapping ACLs

Bootstrapping ACLs on a new cluster requires a few steps, outlined in the example in this
Expand Down Expand Up @@ -239,6 +265,8 @@ catalog:
2017/07/08 23:42:59 [INFO] agent: Synced node info
```

See the [ACL Agent Token](#acl-agent-token) section for more details.

**Enable ACLs on the Consul Clients**

Since ACL enforcement also occurs on the Consul clients, we need to also restart them
Expand Down

0 comments on commit 481c1f9

Please sign in to comment.