Adding file server mount points
Puppet Server includes a file server for transferring static file content to agents; this is what’s used whenever a file resource has a source => puppet:///... attribute specified.
Generally, files are stored in modules. But if you need to serve larger files that shouldn’t be in source control or shouldn’t be distributed with a module, you can make a custom file server mount point and let Puppet serve those files from another directory.
Summary
To create a new mount point, you must:
- Choose a directory on disk for the mount point. Make sure Puppet Server can access it, and put files in it as needed.
- Edit
fileserver.confon your Puppet Server node, so Puppet knows which directory to associate with the new mount point. - Edit
auth.confif you want to restrict which nodes can access this mount point.
Once the mount point is working, you can reference its files at puppet:///<MOUNT POINT>/<PATH>.
What’s a mount point, in a Puppet URI?
Puppet URIs are constructed like this:
puppet://<SERVER>/<MOUNT POINT>/<PATH>
<SERVER>is optional, which is why you usually seepuppet:///URIs with three slashes. There’s little reason to specify a server, since the default is almost always what you want. (It’s the value of theserversetting in Puppet agent, and a special mock server with amodulesmount point in Puppet apply.)<MOUNT POINT>is a unique identifier for some collection of files. There are basically three kinds:- Custom mount points correspond to an arbitrary directory. The rest of this page is about these.
- The special
modulesmount point serves files from thefilesdirectory of every module. It behaves as if someone had copied thefilesdirectory from every module into one big directory, renaming each of them with the name of their module. (So the files inapache/files/...are available atpuppet:///modules/apache/...) - The special
pluginsmount point serves files from thelibdirectory of every module. It behaves as if someone had copied the contents of everylibdirectory into one big directory, with no additional namespacing. Puppet agent uses this mount point when syncing plugins before a run, but there’s no reason to use it in afileresource. - The special
pluginfactsmount point serves files from thefacts.ddirectory of every module, to support external facts. It behaves like thepluginsmount point, but with a different source directory. - The special
localesmount point serves files fromt helocalesdirectory of every module, to support automatic downloading of module translations to agents. It also behaves like thepluginsmount point, and also has a different source directory.
<PATH>is the remainder of the path to the file, starting from the directory (or imaginary directory) that corresponds to the mount point.
Creating a new mount point in fileserver.conf
fileserver.conf uses an INI-like syntax. The fileserver.conf page has a complete description, but all you need to know is:
[<NAME OF MOUNT POINT>]
path <PATH TO DIRECTORY>
allow *
[installer_files]
path /etc/puppetlabs/puppet/installer_files
allow *
In the example above, a file at /etc/puppetlabs/puppet/installer_files/oracle.pkg would be available in manifests as puppet:///installer_files/oracle.pkg.
Make sure that the puppet user can access that directory and its contents.
Always include the allow * line, since the default behavior is to deny all access. If you need to control access to a custom mount point, do so in auth.conf. Putting authorization rules in fileserver.conf is deprecated.
Caution: You should always restrict write access to mounted directories. The file server will follow any symlinks in a file server mount, including links to files that agent nodes should not access (like SSL keys).
When following symlinks, the file server can access any files readable by Puppet Server’s user account.
Controlling access to a custom mount point in auth.conf
By default, any node with a valid certificate can access the files in your new mount point — if it can fetch a catalog, it can fetch files; if it can’t, it can’t. This is the same behavior as the special modules and plugins mount points.
If necessary, you can restrict access to a custom mount point in auth.conf.
New-style auth.conf
If you’ve disabled the legacy auth.conf file by setting jruby-puppet.use-legacy-auth-conf: false, you’ll be adding a rule to Puppet Server’s HOCON-format auth.conf file, located at /etc/puppetlabs/puppetserver/conf.d/auth.conf.
Your new auth rule must meet the following requirements:
- It matches requests to all four of these prefixes:
/puppet/v3/file_metadata/<MOUNT POINT>/puppet/v3/file_metadatas/<MOUNT POINT>/puppet/v3/file_content/<MOUNT POINT>/puppet/v3/file_contents/<MOUNT POINT>
- Its
sort-ordermust be lower than 500, so that it overrides the default rule for the file server.
For example:
{
# Allow limited access to files in /etc/puppetlabs/puppet/installer_files:
match-request: {
path: "^/puppet/v3/file_(content|metadata)s?/installer_files"
type: regex
}
allow: "*.dev.example.com"
sort-order: 400
name: "dev.example.com large installer files"
},
Legacy auth.conf
If you haven’t disabled the legacy auth.conf file, you’ll be adding a stanza to /etc/puppetlabs/puppet/auth.conf.
Your new auth rule must meet the following requirements:
- It matches requests to all four of these prefixes:
/puppet/v3/file_metadata/<MOUNT POINT>/puppet/v3/file_metadatas/<MOUNT POINT>/puppet/v3/file_content/<MOUNT POINT>/puppet/v3/file_contents/<MOUNT POINT>
- It is located earlier in the
auth.conffile than the default/puppet/v3/filerule.
For example:
# Allow limited access to files in /etc/puppetlabs/puppet/installer_files:
path ~ ^/file_(metadata|content)s?/installer_files/
auth yes
allow *.dev.example.com
allow_ip 192.168.100.0/24