-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure anonymous token policy for connect
When running Consul Connect, cross-dc calls require that the anonymous token has read permissions on all services. This change updates the server-acl-init command to give the anonymous token those permissions if connect is enabled. Since we already set those permissions in the case of dns being enabled, the change was to also set those permissions in the case of connect being enabled. To detect connect being enabled, we used the presence of the -create-inject-auth-method flag since that's set when connect is enabled. The policy was renamed from dns-policy to anonymous-token-policy since it applies for more than just dns now. In existing installations, a new policy with that name will be created and attached to the anonymous token that will duplicate the old dns-policy but will have no detrimental effects.
- Loading branch information
Showing
7 changed files
with
157 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package serveraclinit | ||
|
||
import ( | ||
"github.com/hashicorp/consul/api" | ||
) | ||
|
||
// configureAnonymousPolicy sets up policies and tokens so that Consul DNS and | ||
// cross-datacenter Consul connect calls will work. | ||
func (c *Command) configureAnonymousPolicy(consulClient *api.Client) error { | ||
dnsRules, err := c.anonymousTokenRules() | ||
if err != nil { | ||
c.Log.Error("Error templating anonymous token rules", "err", err) | ||
return err | ||
} | ||
|
||
// Create policy for the anonymous token | ||
anonPolicy := api.ACLPolicy{ | ||
Name: "anonymous-token-policy", | ||
Description: "Anonymous token Policy", | ||
Rules: dnsRules, | ||
} | ||
|
||
err = c.untilSucceeds("creating anonymous token policy - PUT /v1/acl/policy", | ||
func() error { | ||
return c.createOrUpdateACLPolicy(anonPolicy, consulClient) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create token to get sent to TokenUpdate | ||
aToken := api.ACLToken{ | ||
AccessorID: "00000000-0000-0000-0000-000000000002", | ||
Policies: []*api.ACLTokenPolicyLink{{Name: anonPolicy.Name}}, | ||
} | ||
|
||
// Update anonymous token to include this policy | ||
return c.untilSucceeds("updating anonymous token with policy", | ||
func() error { | ||
_, _, err := consulClient.ACL().TokenUpdate(&aToken, &api.WriteOptions{}) | ||
return err | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters