It’s not very pretty to do with HCL-formatted ones, either. :-)
Here’s part of a script I use, and it depends on the “jq” utility:
policy=$( cat "/var/lib/consul/agent_acl_policy.hcl" )
jq \
-n \
--arg token_name "agent: ${HOSTNAME}" \
--arg policy "${policy}" \
'{"Name": $token_name, "Type": "client", "Rules": $policy}' \
> acl_request.json
curl -s -S -f \
-X PUT \
-o create_resp.json \
-d @acl_request.json \
localhost:8500/v1/acl/create?token="${mgmt_token}"
I think you could also just “sed” to escape the double quotes. Something like
sed -e ’s#”#\”#g’ < policy.json
I agree the documentation examples could be much better (and frankly the documentation around ACLs seems kind of buried in the Internals section, anyway).
Yes, that’s correct. But your applications that interact with the agent via the HTTP API can provide their own token different from what the agent has configured.
I also prefer to give each agent its own ACL token, rather than sharing one for a particular class of usage.