Version information
This version is compatible with:
Start using this module
Add this module to your Puppetfile:
mod 'collectivemedia-krb5keytab', '0.4.0'
Learn more about managing modules with a PuppetfileDocumentation
krb5keytab
Table of Contents
- Overview
- Module Description - What the module does and why it is useful
- Setup - The basics of getting started with krb5keytab
- 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
Overview
This module generates Kerberos keytabs for hosts (manages the /etc/krb5.keytab file) without the need to place a Kerberos administrator credential on the host. It has been extended to manage additional Kerberos principals and keytabs (e.g. for applications).
This module was developed for, and tested with, MIT Kerberos and OpenLDAP on CentOS 6.
Module Description
This module uses custom functions to create the principal and download the keytab on the puppet master, and hiera to store the generated keytabs. The design of this process eliminates the need to call exec{} with a Kerberos administrative credential on every host.
In addition, the module stores the generated keytab file in hiera, so that it is cached for the next run. Some Kerberos implementations (notably MIT) randomize the password each time the keytab is downloaded, so without this feature a new keytab would be generated for each Puppet run. The module is currently able to store the generated key into CouchDB and into a traditional directory/file hiera implementation.
Setup
What krb5keytab affects
The only file on the target system that is affected is /etc/krb5.keytab, which contains the host's Kerberos principal. This keytab is used to authenticate the host itself to network services - for example, sssd uses this keytab to authenticate the host to the LDAP server.
If you choose to generate a keytab for another user and specify a different path for the keytab, then that keytab (rather than /etc/krb5.keytab) will be affected.
Setup Requirements
There are numerous assumptions and configuration parameters required to make full use of this module.
Assumptions
-
You need to have OpenLDAP and Kerberos running and working in your environment.
-
You need to have at least one Kerberos administrative principal created, which has (at minimum) the ability to add principals, change passwords, inquire, and list ("clia" in kadm5.acl). We suggest creating a separate principal used only for your Puppet master, e.g.:
puppetmaster@YOUR-REALM.COM
You would place a corresponding entry in the
/var/kerberos/krb5kdc/kadm5.acl
file to grant the privileges:puppetmaster@YOUR-REALM.COM clia
-
You need to have Hiera running. If you want to use the feature of this module that saves newly generated keytabs in hiera for you, then your Hiera can be backed by CouchDB (see https://github.com/crayfishx/hiera-http) or the traditional directory and file system hiera.
Beginning with krb5keytab
krb5keytab is configured with numerous parameters in Hiera and/or parameters passed to the class. Please see the "Usage" section for details.
Usage
krb5keytab is configured with numerous parameters in Hiera and/or parameters passed to the class. Parameters passed to the class take precedence over Hiera.
Admin Keytab (required)
Hiera: krb5keytab::admin-keytab
Parameter to class: admin_keytab
The base64 encoded keytab for the administrative Kerberos principal.
- How to create a keytab file: https://kb.iu.edu/d/aumh#create
- How to base64 encode the keytab:
base64 username.keytab
Example (this is just random data encoded as BASE64):
VQPlowXZxtrKW8sZv3Ehg2T7W+y1jjxzILnOOHM/GHzykphIHXbvMmezZpupLB3wns8/YNPi4CVM
YGe1rWmCZ7hU0SmEdJNQ9/x2nd2j7YudunhVHAsA8lvE32L0TY8VbpQX4d1y0YxaJeMDksE+M17N
JVKiWeQD7o92guSzp1wapzCA08yZJXZV36Uw21U87NgZPhdbhDE/kzeFep5hrxEIXylaQW8zRCGc
LT/l8RjPCFkjXzxn3VKWsaVaaFC2FCDaEMqkFcxcX5UxatnBqcNtlbR0WTNUiAYu9UDdEz1KVGZc
L5Vxbj3dSmsMm8M2peSSoOl3FgSTUFyqJ9xoiOIPbrJz6MkId1oTW31Lal0hmqTAxZLmYCLNEb6y
yB9J5APTNEW1SPKma7rXmmOQtWZuthYsasWRbFdZKsC96h6jVHzX/pngAhxPBPjEyYUkNBeFSO9W
KIpn3f0KXiFt0+i/Y6N5ZmsODf6fzKUFMW24HogjzleqqhUYEiNdpmZKj5f3iP0Lg2PZpmNFeTzO
2tw6VebNZTCc9REw98sh8L4D0OAF5ProTItJNditAg==
Admin Principal (required)
Hiera: krb5keytab::admin-principal
Parameter to class: admin_principal
The principal's name of your administrative Kerberos principal.
Example:
puppetmaster@YOUR-REALM.COM
Kerberos Realm (required)
Hiera: krb5keytab::krb5-realm
Parameter to class: krb5_realm
The Kerberos realm. In other words, the (usually capitalized) portion of principal names that come after the "@" sign. This is often part of your domain name.
Example:
YOUR-REALM.COM
Hiera Backend (optional)
Hiera: krb5keytab::hiera-backend
Parameter to class: hiera_backend
The type of Hiera backend you run, so that the module can write keytabs that are generated into that Hiera backend for you. The options available are:
none
(or undefined) -- Do not store generated keytabs in Hierafile
-- Store generated keytabs into a directory structurecouchdb
-- Store generated keytabs into a CouchDB
Note that if you select none
or undefined, the code to generate a keytab will be executed each time a Puppet catalog is compiled for a node. On MIT Kerberos, this
will result in randomization of the keytab for the host every time. This is probably undesirable.
LDAP Organizational Unit (required)
Hiera: krb5keytab::ldap-ou
Parameter to class: ldap_ou
The place in your LDAP tree where Kerberos principals for hosts should be created. (This can be overridden with each call to create a resource.)
Example:
ou=hosts,dc=your-realm,dc=com
Kerberos Admin Server FQDN or IP Address (required)
Hiera: krb5keytab::krb5-admin-server
Parameter to class: krb5_admin_server
The fully qualified domain name of your Kerberos admin server. This is that server that will be contacted to identify, list, create, and obtain the host principals.
Example:
kerberos1.your-realm.com
Files Hiera Configuration Parameters
The following settings are supported if you set krb5keytab::hiera-backend
= file
Hiera File Directory (required if hiera-backend = file)
Hiera: krb5keytab::hiera-file-dir
Parameter to class: hiera_file_dir
The directory where files are created with the host keytabs (this must exist on the Puppet master). Within this directory, files named ${::fqdn}.yaml
will be created. Each file will have a field named "krb5-keytab" with the BASE64 encoded keytab.
Use a separate subdirectory for this from all of your other Hiera data. This module tries to preserve existing settings, but this cannot be assured.
CouchDB Hiera Configuration Parameters
The following settings are supported if you set krb5keytab::hiera-backend
= couchdb
.
The 'couchrest' gem is required for krb5keytab to write to a CouchDB.
CouchDB Server Hostname (optional)
Hiera: krb5keytab::hiera-couchdb-hostname
Parameter to class: hiera_couchdb_hostname
The fully qualified domain name or IP address of your CouchDB server. Defaults to 127.0.0.1.
CouchDB Server Port Number (optional)
Hiera: krb5keytab::hiera-couchdb-port
Parameter to class: hiera_couchdb_port
The port number that CouchDB is running on. Defaults to 5984.
CouchDB Server Database Name (optional)
Hiera: krb5keytab::hiera-couchdb-database
Parameter to class: hiera_couchdb_database
The database name in which to store generated keytabs. Defaults to "keytabs".
Note: Within that database, a document named after ${::fqdn} will be generated, and therein a field named "krb5-keytab" will be created and populated with the BASE64 encoded kerberos keytab.
CouchDB Basic Auth Credentials (optional)
Hiera: krb5keytab::hiera-couchdb-username
and krb5keytab::hiera-couchdb-password
Parameter to class: hiera_couchdb_username
and hiera_couchdb_password
If CouchDB has basic authentication turned on, supply the username and password to connect. This account must have the ability to create and update records in the assigned database.
Reference
Classes / Defines
krb5keytab::keytab
This is a define that can be used to create keytabs for arbitrary principals, including host principals. You should be using this, as opposed to the old host_keytab
class.
A typical define may look like this:
krb5keytab::keytab { "ldap/${::fqdn}":
keytab => '/etc/openldap/krb5.keytab',
keytab_owner => 'root',
keytab_group => 'ldap',
keytab_mode => '0640',
}
The name of the resource should be the name of the principal.
- For a host keytab, this is:
"host/${::fqdn}@YOUR-KERBEROS-REALM.COM"
- You need to specify the full name of the principal, including the realm name (e.g.
some-dude/hostname.yourdomain.com@YOUR-REALM.COM
). If the principal does not have a@
in it, the default kerberos realm will be added -- i.e.,some-dude/hostname.yourdomain.com
will becomesome-dude/hostname.yourdomain.com@YOUR-REALM.COM
automatically. - When specifying the principal you can use
${::facter_fact_name}
which will be replaced by the appropriate facter fact.${::fqdn}
is likely to be particularly useful.
The following parameters are generally useful for this class.
- keytab - Keytab file to write -- use
/etc/krb5.keytab
for the host keytab. This defaults to NULL (i.e. do NOT write a keytab file) if the principal is not the host principal. This is useful behavior if you want to declare that a particular principal exists, but not store its keytab somewhere (Cloudera Manager, for example, requires that a principal exist, but it will pull the keytab itself). If you really want to specify this "NULL" behavior and don't trust the omission of the "keytab" parameter, you can passkeytab => 'none'
to be extra sure. - keytab_owner - Owner of keytab file -- defaults to root
- keytab_group - Group of keytab file -- defaults to root
- keytab_mode - Mode (permissions) of keytab file -- defaults to 0400
- ldap_ou - See krb5keytab::ldap-ou hiera parameter.
- hiera_key - Name of the key to create in Hiera -- defaults to 'krb5-keytab' for host keytabs, and the name of the principal for non-host keytabs. (Certain characters in the name of the principal will be replaced with underscores to avoid breaking YAML.)
krb5keytab::host_keytab (DEPRECATED)
Main class to generate and install a host keytab.
This class does not take parameters. The connection and credential parameters for Kerberos are stored in Hiera. The keytab is generated for ${::fqdn}
.
This class is being kept for legacy purposes but should be considered DEPRECATED. You should instead use "krb5keytab::keytab" (which is define-based).
Custom Functions
krb5keytab_generatekt(options_hash)
options_hash is a hash containing the following keys:
- admin_principal - Name of the administrative principal. See krb5keytab::admin-principal hiera parameter.
- admin_keytab - The full path to a file containing the administrative keytab.
- ldap_ou - See krb5keytab::ldap-ou hiera parameter.
- admin_server - See krb5keytab::krb5-admin-server hiera parameter.
- realm - See krb5keytab::krb5-realm hiera parameter.
- fqdn - FQDN of the host whose principal is needed.
From this a host principal is built: "host/#{args['fqdn']}@#{args['realm']}"
The "kadmin" command is used to create the principal if needed, and then to retrieve the keytab.
This method returns the content of the keytab (which is binary data).
krb5keytab_saveinhiera(options_hash)
options_hash is a hash containing the following keys:
- hiera_key - Name of the key to create in Hiera (in our context, "krb5-keytab")
- fqdn - FQDN of the host whose principal is needed.
- hiera_backend - One of 'none', 'files', or 'couchdb'
- hiera_value - Value to write in Hiera (in our context, the BASE64 encoded keytab)
No return value.
krb5keytab_writefile(content)
Creates a temporary file with the content supplied as the argument.
Returns the path to the temporary file.
Limitations
- This module was developed on CentOS 6 for OpenLDAP and Kerberos. While we believe that the underlying code will probably work with other flavors of Linux and other implementations of LDAP and Kerberos, this has not been tested.
- Only one principal per keytab file is supported at present.
Development
If you wish to contribute, please submit a pull request. All contributions must be licensed to us under the Apache 2.0 license.
Contributors
This module was originally developed at Collective, Inc. (http://www.collective.com). We gratefully acknowledge the following contributors:
- Kevin Paulisse (original design and code; expansion from class to define)
- Sarguru Nathan (builds and tests)
- Millie Kim (file backend for Hiera storage)
Dependencies
- puppetlabs/stdlib (>= 1.0.0)
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.