Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Consul 1.4.0+ ACL system #474

Merged
merged 16 commits into from May 16, 2019

Conversation

marius-meissner
Copy link
Contributor

Resolves #471

Example usage:

consul_policy {'test_policy':
  description   => 'test description',
  rules         => [
      {
          'resource'    => 'service_prefix',
          'segment'     => 'test_service',
          'disposition' => 'read'
      },
      {
          'resource'    => 'key',
          'segment'     => 'test_key',
          'disposition' => 'write'
      },
  ],
  acl_api_token => 'e33653a6-0320-4a71-b3af-75f14578e3aa',
}

consul_token {'test_token':
  policies_by_name  => [
   'test_policy'
  ],
  policies_by_id    => [
    '652f27c9-d08d-412b-8985-9becc9c42fb2'
  ],
}

The current concept treats tokens and policies individually. A token can be assigned both policies managed by puppet (by_name) and external policies (by_id).
The new Consul system does not support any user specified Token ID anymore (s. hashicorp/consul#4977), therefore the mapping is currently done by description.

Due to my limited Ruby or Puppet experience feedback and suggestions for improvements are highly welcome.

@bastelfreak bastelfreak added the enhancement New feature or request label Apr 8, 2019
@@ -199,6 +199,45 @@ consul to restart.

## ACL Definitions

### Policy/Token system

Starting with version 1.4.0, a new ACL system was introduces separating rules (policies) from tokens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yey doc updates \o/

@@ -0,0 +1,190 @@
require 'json'
require 'net/http'
require 'pp'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pp actually required or just a leftover from debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, dependency has been removed.

@@ -158,6 +179,13 @@
#
class consul (
Hash $acls = $consul::params::acls,
Hash $tokens = $consul::params::tokens,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you enforce the datatypes even more? For hashes, you can define the datatypes for the keys and the values. For example:

Suggested change
Hash $tokens = $consul::params::tokens,
Hash[String[1],String[1]] $tokens = $consul::params::tokens,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I tried to add some stricter types in the newest version.

@@ -158,6 +179,13 @@
#
class consul (
Hash $acls = $consul::params::acls,
Hash $tokens = $consul::params::tokens,
Hash $policies = $consul::params::policies,
String $acl_api_hostname = $consul::params::acl_api_hostname,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can enforce the minimal string length like this:

Suggested change
String $acl_api_hostname = $consul::params::acl_api_hostname,
String[1] $acl_api_hostname = $consul::params::acl_api_hostname,

Please also look through https://github.com/puppetlabs/puppetlabs-stdlib/tree/master/types, you might find mor strict datatypes that you could use.

Hash $policies = $consul::params::policies,
String $acl_api_hostname = $consul::params::acl_api_hostname,
String $acl_api_protocol = $consul::params::acl_api_protocol,
Integer $acl_api_port = $consul::params::acl_api_port,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this type can be used https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/types/port.pp ?

Suggested change
Integer $acl_api_port = $consul::params::acl_api_port,
Stdlib::Port $acl_api_port = $consul::params::acl_api_port,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea from my point of view.
As far as I know this type was added in version 4.25 of stdlib. Is it ok to adjust the current dependencies accordingly?

@bastelfreak
Copy link
Member

Hey @SkydiveMarius, thanks for the awesome PR! I made some small inline comments. Can you take a look at the current acceptance tests (https://github.com/solarkennedy/puppet-consul/blob/master/spec/acceptance/class_spec.rb) and extend them with tests for the new types/provider?

@bastelfreak bastelfreak added needs-tests needs-work not ready to merge just yet labels Apr 8, 2019
@bastelfreak
Copy link
Member

@SkydiveMarius thanks for the updates! Can you take a look at the failed travis job?

@marius-meissner
Copy link
Contributor Author

Branch has been rebased, but some Travis builds are randomly failing with Timeout errors (ACL API requests). So far I was not able to reproduce this behavior locally.

In case of failure the content of /var/log/consul would probably help. Does rspec offer possibilities to display this information in case of an error?

@marius-meissner
Copy link
Contributor Author

PR has been adjusted for the recent Consul 1.5.0 update.
As the module is now using the new accessor + secret ID predefinition feature, only Consul > 1.5.0 is supported.

Boolean $enable_beta_ui = false,
Boolean $allow_binding_to_root_ports = false,
Hash $acls = {},
Hash[String[1], Struct[{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please put those types into a custom datatype? That would make the file more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Replaced by type aliases.

@bastelfreak bastelfreak removed needs-rebase needs-tests needs-work not ready to merge just yet labels May 14, 2019
@bastelfreak
Copy link
Member

Hi @SkydiveMarius, thanks for the awesome work! @solarkennedy can you please take a look and merge it? In my opinion this is fine.

@solarkennedy
Copy link
Contributor

looking...

if @resource[:ensure] == :absent
if @existing_policy
@client.delete_policy(@existing_policy.id)
Puppet.notice(" Deleted Consul ACL policy #{@existing_policy.name} (ID: #{@existing_policy.id})")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There is a leading space here in the log line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, space has been removed.

@existing_policy.rules = @rules_encoded

@client.update_policy(@existing_policy)
Puppet.notice(" Updated Consul ACL policy #{@existing_policy.name} (ID: #{@existing_policy.id})")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too, intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By far not intended, space is removed.

@solarkennedy
Copy link
Contributor

This PR looks really solid @SkydiveMarius!
Tests, types, providers, etc.
It has been a long time since I wrote puppet code like this, but I'm a fan of getting the code out there and iterating.

So I say we ship!

@marius-meissner
Copy link
Contributor Author

Thanks for the positive feedback!
Seems the current Travis fails have an unrelated reason:

curl: (22) The requested URL returned error: 404 Not Found
  	error: skipping http://yum.puppet.com/puppet6/puppet6-release-el-6.noarch.rpm - transfer failed
  	Retrieving http://yum.puppet.com/puppet6/puppet6-release-el-6.noarch.rpm

@solarkennedy
Copy link
Contributor

Probably temporary. It really is 404, but I'll check back later in the day to make sure we have a green build and merge.

@bastelfreak
Copy link
Member

I restarted the failed CI jobs

@bastelfreak
Copy link
Member

The related issue for the broken mirror: https://groups.google.com/forum/#!topic/puppet-users/cCsGWKunBe4

@solarkennedy
Copy link
Contributor

Build is green. Thanks again @SkydiveMarius for a really great first time contribution!

@solarkennedy solarkennedy merged commit 3d42a86 into voxpupuli:master May 16, 2019
spuder pushed a commit to spuder/puppet-consul that referenced this pull request Feb 25, 2020
Support for Consul 1.4.0+ ACL system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Provide support for Consul 1.4.0+ ACL System
3 participants