Version information
This version is compatible with:
- Puppet Enterprise 2023.8.x, 2023.7.x, 2023.6.x, 2023.5.x, 2023.4.x, 2023.3.x, 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x
- Puppet >= 7.0.0 < 9.0.0
- , , , , ,
Start using this module
Add this module to your Puppetfile:
mod 'puppetlabs-puppet_authorization', '1.0.0'
Learn more about managing modules with a PuppetfileDocumentation
puppet_authorization
Table of Contents
- Module Description - What the module does and why it is useful
- Setup - The basics of getting started with puppet_authorization
- Usage - Configuration options and additional functionality
- Reference - An under-the-hood peek at what the module is doing and how
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Module Description
The puppet_authorization module generates or changes the auth.conf file using authorization rules written as Puppet resources.
Note that this module is used only for the new auth.conf file used by Puppet Server 2.2.0 and later. If you are using the auth.conf file used by core Puppet, this module will not affect it. See Puppet Server documentation for detailed information about the auth.conf file.
This module allows you to add custom rules to your auth.conf file by writing Puppet resources that can create, modify, or remove the associated rules from the auth.conf file. It allows the auth.conf to be created entirely from Puppet code---you never have to touch the auth.conf file directly.
This module is maintained by Puppet, but we have no plans for future feature development. We will keep it working with current versions of Puppet, but new feature development will come from community contributions. It does not qualify for Puppet Support plans.
[tier:maintenance-mode]
Setup
Beginning with puppet_authorization
Note that this section applies only to open source Puppet. In Puppet Enterprise, this resource is managed automatically.
The puppet_authorization
resource sets up the auth.conf and configures settings that apply globally, rather than being specific to individual rules.
For example, this code:
puppet_authorization { '/etc/puppetlabs/puppetserver/conf.d/auth.conf':
version => 1,
allow_header_cert_info => false
}
...would populate the following corresponding settings into the "auth.conf" file:
authorization: {
version: 1
allow-header-cert-info: false
rules: ...
}
Note that the value for rules
in this case would be set to [] if the rules
array was not yet present in the file. Otherwise, whatever value was already in the target file for rules
is preserved.
The values used above are:
version
: Currently, 1 is the only supported value and is the default.allow-header-cert-info
: Controls whether the identity of the client will be inferred from the client's SSL certificate, when false, or from special X-Client HTTP headers, when true. The default for this setting is false. See Puppet Server documentation for information about disabling HTTPS for Puppet Server andallow-header-cert-info
setting.
Usage
The following usage examples assume an empty auth.conf file that looks like this:
authorization: {
version: 1
rules: []
}
Add a rule
The main resource to use is puppet_authorization::rule
, which manages a single
rule in the authorization configuration file (auth.conf). This authorization file also
needs to be managed with a resource, which is done with puppet_authorization
.
The following declares a resource to manage the top-level structure, followed by a resource to add a rule for controlling access to the "environments" HTTP endpoint:
puppet_authorization::rule { 'environments':
match_request_path => '/puppet/v3/environments',
match_request_type => 'path',
match_request_method => 'get',
allow => 'your.special.admin',
sort_order => 300,
path => '/etc/puppetlabs/puppetserver/conf.d/auth.conf',
}
Here, we've declared that only 'your.special.admin'
can access the
/puppet/v3/environments
endpoint.
Delete a rule
Continuing from the previous example to add the "environments" rule, the following example declares a resource that removes it from the file.
puppet_authorization::rule { 'environments':
ensure => absent,
path => '/etc/puppetlabs/puppetserver/conf.d/auth.conf',
}
When removing a rule, you have only to provide the rule name and path to
the configuration file where it can be found. Since rules must have unique names,
you don't have to define the other attributes (match_request_path
, etc);
the rule with the matching name will be removed, regardless.
Configure the catalog endpoint
You can configure the catalog HTTP endpoint for Puppet Server to:
- Permit an administrative node to access the catalog for any node.
- Permit other nodes to be able to access their own catalog, but no other node’s catalog.
In this example, we'll configure the rule to apply only to requests made to the production or test directory environments in Puppet.
puppet_authorization::rule { 'catalog_request':
match_request_path => '^/puppet/v3/catalog/([^/]+)$',
match_request_type => 'regex',
match_request_method => ['get','post'],
match_request_query_params => {'environment' => [ 'production', 'test' ]},
allow => ['$1', 'adminhost.mydomain.com'],
sort_order => 200,
path => '/etc/puppetlabs/puppetserver/conf.d/auth.conf',
}
If the original auth.conf file looked like this:
authorization: {
version: 1
allow-header-cert-info: false
rules: []
}
...then it should look something like this after the new rule is applied:
authorization: {
version: 1
allow-header-cert-info: false
rules: [
{
"allow" : [
"$1",
"adminhost.mydomain.com",
],
"match-request" : {
"method" : [
"get",
"post"
],
"path" : "^/puppet/v3/catalog/([^/]+)$",
"query-params" : {
"environment" : [
"production",
"test"
]
},
"type" : "regex"
},
"name" : "catalog_request",
"sort-order" : 200
}
,
]
}
Trigger rule changes
Puppet Server does not automatically start using the new rule definitions in the auth.conf file as they are applied. Before your auth.conf file changes take effect, the Puppet Server service needs to be restarted. Add the following code to each rule resource to restart the service any time rules in the auth.conf file changes.
If you're using open source Puppet Server, add the following code to your rule resource:
notify => Service['puppetserver']
If you're using Puppet Server in PE, add:
notify => Service['pe-puppetserver']
For example, with this code added, the full rule definition might look like this:
puppet_authorization::rule { 'catalog_request':
match_request_path => '^/puppet/v3/catalog/([^/]+)$',
match_request_type => 'regex',
match_request_method => ['get','post'],
match_request_query_params => {'environment' => [ 'production', 'test' ]},
allow => ['$1', 'adminhost.mydomain.com'],
sort_order => 200,
path => '/etc/puppetlabs/puppetserver/conf.d/auth.conf',
notify => Service['pe-puppetserver'],
}
Reference
Defined Types
Providers
Defined Type: puppet_authorization
Sets up the skeleton server auth.conf file if it doesn't exist.
Parameters (all optional)
-
version
: Theauthorization.version
setting in the server auth.conf. Valid options: an integer (currently, 1 is the only supported value). Default:1
. -
allow_header_cert_info
: Theauthorization.allow-header-cert-info
setting in the server auth.conf. Valid options:true
,false
. Default:false
. -
replace
: Whether or not to replace existing file atpath
. If set to true this will cause the file to be regenerated on every puppet run. Valid options:true
,false
. Default:false
. -
path
: Absolute path for auth.conf. Defaults toname
.
Defined Type: puppet_authorization::rule
Adds individual rules to auth.conf.
Parameters (optional unless otherwise specified)
-
match_request_path
: Required. Valid options: a string. -
match_request_type
: Required. Valid options: 'path', 'regex'. -
path
: Required. The absolute path for the auth.conf file. -
ensure
: Whether to add or remove the rule. Valid options: 'present', 'absent'. Defaults to 'present'. -
rule_name
: Thename
setting for the rule. Valid options: a string. Defaults toname
. -
allow
: Theallow
setting for the rule. Cannot be set along with anallow_unauthenticated
value of true. Valid options: a hash, a string or an array of strings and/or hashes. A hash here must contain only one ofextensions
orcertname
. Defaults to undef. For more details on theallow
setting, see https://github.com/puppetlabs/trapperkeeper-authorization/blob/master/doc/authorization-config.md#allow. -
deny
: Thedeny
setting for the rule. Cannot be set along with anallow_unauthenticated
value of true. Valid options: a hash, a string or an array of strings and/or hashes. A hash here must contain only one ofextensions
orcertname
. Defaults to undef. For more details on thedeny
setting, see https://github.com/puppetlabs/trapperkeeper-authorization/blob/master/doc/authorization-config.md#deny. -
allow_unauthenticated
: Theallow_unauthenticated
setting for the rule. Cannot be set to true along withdeny
orallow
. Valid options: true, false. Defaults to false. -
match_request_method
: Themethod
setting for thematch_request
in the rule. Valid options: String or array of strings containing: 'put', 'post', 'get', 'head', 'delete'. Defaults to undef. -
match_request_query_params
: Thequery_params
setting for thematch_request
in the rule. Valid options: Hash. Defaults to {}. -
sort_order
: The sort order for the rule. Valid options: an integer. Defaults to 200.
Limitations
The auth.conf file this module writes is supported only in open source Puppet Server 2.2.0 or greater or Puppet Enterprise 2015.3.0 or greater. See (https://docs.puppetlabs.com/puppetserver/latest/config_file_auth.html) for more details about authorization in Puppet Server.
Reference
Table of Contents
Defined types
puppet_authorization
: Define type to manage the puppetserver authorizationpuppet_authorization::rule
: manage a puppetserver authorization rule
Resource types
puppet_authorization_hocon_rule
: Manage the state of this type.
Data types
Puppet_authorization::Httpmethod
: Type for validating supported HTTP methods
Defined types
puppet_authorization
Define type to manage the puppetserver authorization
Parameters
The following parameters are available in the puppet_authorization
defined type:
version
Data type: Integer
The version of the authorization
Default value: 1
allow_header_cert_info
Data type: Boolean
Whether to allow header cert info
Default value: false
replace
Data type: Boolean
Whether to replace the file
Default value: false
path
Data type: Stdlib::Absolutepath
The path to the auth.conf file
Default value: $name
puppet_authorization::rule
manage a puppetserver authorization rule
Parameters
The following parameters are available in the puppet_authorization::rule
defined type:
path
ensure
rule_name
allow
allow_unauthenticated
deny
match_request_method
match_request_query_params
sort_order
match_request_path
match_request_type
path
Data type: Stdlib::Absolutepath
The path to the auth.conf file
ensure
Data type: Enum['present', 'absent']
State of rule
Default value: 'present'
rule_name
Data type: String
An arbitrary name used to identity the rule
Default value: $name
allow
Data type: Variant[Array[Variant[String, Hash]], String, Hash, Undef]
Value(s) to permit an authenticated request
Default value: undef
allow_unauthenticated
Data type: Boolean
Puppet Server will always permit the request (potentially insecure) when set to true. If true, the rule cannot use the allow or deny parameters.
Default value: false
deny
Data type: Variant[Array[Variant[String, Hash]], String, Hash, Undef]
Value(s) to deny an authenticated request, even if an allow is also matched.
Default value: undef
match_request_method
Data type: Variant[Array[Puppet_authorization::Httpmethod], Puppet_authorization::Httpmethod, Undef]
Limit rule to match specific HTTP request method(s).
Default value: undef
match_request_query_params
Data type: Hash
Limit rule to matching query parameters with specific value(s). An Array of values can be provided to match a request with any of the values.
Default value: {}
sort_order
Data type: Integer
Rule processing priority, 1 to 399 are evaluated before default Puppet rules, or 601 to 998 are be evaluated after Puppet. Lower-numbered values evaluated first, and secondarily sorts lexicographically by the name string value's Unicode code points.
Default value: 200
match_request_path
Data type: Optional[String]
Match request when the endpoint URL starts with or contains the parameter value.
Default value: undef
match_request_type
Data type: Optional[Enum['path', 'regex']]
How Puppet Server will interpret the match_request_path parameter value.
Default value: undef
Resource types
puppet_authorization_hocon_rule
Manage the state of this type.
Properties
The following properties are available in the puppet_authorization_hocon_rule
type.
ensure
Valid values: present
, absent
Manage the state of this type.
Default value: present
value
The value of the setting to be defined.
Parameters
The following parameters are available in the puppet_authorization_hocon_rule
type.
name
namevar
An arbitrary name used as the identity of the resource.
path
The file Puppet will ensure contains the specified setting.
provider
The specific backend to use for this puppet_authorization_hocon_rule
resource. You will seldom need to specify this
--- Puppet will usually discover the appropriate provider for your platform.
Data types
Puppet_authorization::Httpmethod
Type for validating supported HTTP methods
Alias of Enum['put', 'post', 'get', 'head', 'delete']
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
v1.0.0 - 2024-04-13
Changed
Added
0.5.1 - 2020-04-27
Added
- (MODULES-10578) Add EL8 to metadata.json #32 (trevor-vaughan)
- Support puppetlabs/concat 6.x and puppetlabs/stdlib 6.x. #31 (pillarsdotnet)
Other
0.5.0 - 2018-10-17
Other
- (MODULES-8103) - 0.5.0 Release Prep #29 (david22swan)
- (MODULES-7844) Update stdlib and concat dependencies #28 (Sharpie)
0.4.0 - 2017-09-07
Other
0.3.0 - 2017-09-01
Other
0.2.0 - 2016-04-26
Other
- 0.2.0 release prep #23 (HelenCampbell)
- (maint) Remove unused links from README TOC #22 (haus)
- (PE-14870) Add support for extensions matching #21 (haus)
- update concat version dependency #20 (vicinus)
0.1.0 - 2015-11-13
Dependencies
- puppetlabs-stdlib (>= 4.6.0 < 10.0.0)
- puppetlabs-concat (>= 1.1.1 < 10.0.0)
- puppetlabs-hocon (>= 0.9.3 < 2.0.0)