From 8ae9e17dff67cb47468f33837b7bd69098104556 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 1 Dec 2016 19:14:08 -0800 Subject: [PATCH] Adds an opt-in for new ACL policies and features coming in Consul 0.8. --- command/agent/config.go | 18 +++++++++++++----- command/agent/config_test.go | 17 +++++++++++++++++ .../source/docs/agent/options.html.markdown | 7 +++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/command/agent/config.go b/command/agent/config.go index 8c17f91182..fc80b4bf1a 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -525,6 +525,10 @@ type Config struct { // other than the ACLDatacenter. ACLReplicationToken string `mapstructure:"acl_replication_token" json:"-"` + // ACLEnforceVersion8 is used to gate a set of ACL policy features that + // are opt-in prior to Consul 0.8 and opt-out in Consul 0.8 and later. + ACLEnforceVersion8 *bool `mapstructure:"acl_enforce_version_8"` + // Watches are used to monitor various endpoints and to invoke a // handler to act appropriately. These are managed entirely in the // agent layer using the standard APIs. @@ -705,11 +709,12 @@ func DefaultConfig() *Config { SyncCoordinateRateTarget: 64.0, // updates / second SyncCoordinateIntervalMin: 15 * time.Second, - ACLTTL: 30 * time.Second, - ACLDownPolicy: "extend-cache", - ACLDefaultPolicy: "allow", - RetryInterval: 30 * time.Second, - RetryIntervalWan: 30 * time.Second, + ACLTTL: 30 * time.Second, + ACLDownPolicy: "extend-cache", + ACLDefaultPolicy: "allow", + ACLEnforceVersion8: Bool(false), + RetryInterval: 30 * time.Second, + RetryIntervalWan: 30 * time.Second, } } @@ -1480,6 +1485,9 @@ func MergeConfig(a, b *Config) *Config { if b.ACLReplicationToken != "" { result.ACLReplicationToken = b.ACLReplicationToken } + if b.ACLEnforceVersion8 != nil { + result.ACLEnforceVersion8 = b.ACLEnforceVersion8 + } if len(b.Watches) != 0 { result.Watches = append(result.Watches, b.Watches...) } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index e2a04ae98a..48a615f974 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -674,6 +674,22 @@ func TestDecodeConfig(t *testing.T) { t.Fatalf("bad: %#v", config) } + // ACL flag for Consul version 0.8 features (broken out since we will + // eventually remove this). We first verify this is opt-out. + config = DefaultConfig() + if *config.ACLEnforceVersion8 != false { + t.Fatalf("bad: %#v", config) + } + + input = `{"acl_enforce_version_8": true}` + config, err = DecodeConfig(bytes.NewReader([]byte(input))) + if err != nil { + t.Fatalf("err: %s", err) + } + if *config.ACLEnforceVersion8 != true { + t.Fatalf("bad: %#v", config) + } + // Watches input = `{"watches": [{"type":"keyprefix", "prefix":"foo/", "handler":"foobar"}]}` config, err = DecodeConfig(bytes.NewReader([]byte(input))) @@ -1552,6 +1568,7 @@ func TestMergeConfig(t *testing.T) { ACLDownPolicy: "deny", ACLDefaultPolicy: "deny", ACLReplicationToken: "8765309", + ACLEnforceVersion8: Bool(true), Watches: []map[string]interface{}{ map[string]interface{}{ "type": "keyprefix", diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 49253e30b7..ea6fb252c6 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -377,6 +377,13 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass all operations, and "extend-cache" allows any cached ACLs to be used, ignoring their TTL values. If a non-cached ACL is used, "extend-cache" acts like "deny". +* `acl_enforce_version_8` - + Used for clients and servers to determine if enforcement should occur for new ACL policies being + previewed before Consul 0.8. Added in Consul 0.7.2, this will default to false in versions of + Consul prior to 0.8, and will default to true in Consul 0.8 and later. This helps ease the + transition to the new ACL features by allowing policies to be in place before enforcement begins. + Please see the [ACL internals guide](/docs/internals/acl.htmlXS) for more details. + * `acl_master_token` - Only used for servers in the [`acl_datacenter`](#acl_datacenter). This token will be created with management-level permissions if it does not exist. It allows operators to bootstrap the ACL system