We don't think anyone is using it so we want to remove it in Fleet 5 (next major version). - More context here: https://github.com/fleetdm/fleet/issues/28334
6.1 KiB
Contributing to the fleetdm module
The Puppet module is deprecated as of Fleet 4.66. It is maintained for backwards compatibility.
Setup
For a simple local environment setup where your computer acts as the server and client, you'll need to install the following:
If you also want to emulate a real-world environment, you'll need to set up a Puppet server.
How the module works
sequenceDiagram
autonumber
participant A as Agent
participant P as Puppet Server
participant F as Fleet
A->>P: Catalog request
P->>F: POST /mdm/apple/profiles/preassign <br/> for each `fleetdm::profile` resource
P->>A: Catalog compilation finished
A->>P: Results of the run
Note over A,P: Puppet run is completed
P->>F: POST POST /mdm/apple/profiles/match <br/> to signal end of run and match profiles
Note over F: create/edit a team with the pre-assigned profiles
Note over F: assign the host to the team
The sequence diagram above illustrates a typical run:
- The agent initiates communication with the Puppet server, similar to how
osquerychecks in with the Fleet server. - The server builds a catalog (a JSON with instructions) based on the resources defined by the IT admin in manifests (files with
.ppextension).- Inside manifests, one or more
fleetdm::profileresources can be declared. - Each time the Puppet server finds a
fleetdm::profile, it makes a request to the Fleet server to "pre-assign" the profile. - On each request, the Fleet server stores information about the profile and the host in Redis.
- Inside manifests, one or more
- The Puppet server sends the catalog back. Unlike typical modules, this catalog doesn't contain instructions related to profiles; all the work is done by the Fleet server through the MDM protocol.
- The agent applies the catalog and signals to the Puppet server when it finishes.
- After the run, the server can send one or more reports about the run, containing information like the duration of the run. We utilize this feature to send a match request to the Fleet server to signal that the run for the node is done in our custom reporter.
Once the run is complete, the server collects all pre-assigned profiles from Redis and performs the following:
- Creates/edits a team with the set of pre-assigned profiles.
- Adds the host to the team.
Set up a Puppet server
The easiest way to set-up a local instance is by using puppetlabs/pupperware. Follow the instructions on their README to get a server running.
Note:
pupperwaredoesn't work on macOS with ARM processors.
After the server is running, edit your hosts file (in macOS /etc/hosts,) to resove the puppet hostname to the IP of your Puppet server, for example:
192.168.100.13 puppet
Note: there are ways to configure Puppet if you don't want to edit your hosts file, but doing this will save you some trouble.
Once your server is running, you need to configure it, some usefult paths are:
/etc/puppetlabs/codeto manage modules and different environments/opt/puppetlabs/serverfor server-specific stuff
The only thing left to do is to add the fleetdm/fleetdm module to your server. You can either:
- Copy and paste the contents of this directory in
/etc/puppetlabs/code/environments/production/modules(the whole/etc/puppetlabs/codedirectory is a Docker volume) - Install the module running
puppet module install fleetdm-fleetdm --version 0.2.1and tweak the installed code.
Important if you make changes to the
utilsfolder of the module, you need to runpuppetserver reloadin your Puppet server afterwards, files in that folder are not autoloaded.
Releasing
- Bump the module version in the metadata.json file.
- Ensure all new changes are documented in
./CHANGELOG.md - From the
ee/tools/puppet/fleetdmdirectory, runpdk build. This will generate atar.gzfile in theee/tools/puppet/fleetdm/pkg/directory. - Perform a last sanity check running
pdk validate - Test the build by extracting the file you just created and executing a Puppet run:
# extract the build
rm -rf /tmp/puppet-module/fleetdm
mkdir -p /tmp/puppet-module/fleetdm
tar -xzf pkg/fleetdm-fleetdm-0.2.4.tar.gz -C /tmp/puppet-module/fleetdm --strip-components=1
# run Puppet
puppet apply --debug --test --modulepath="/tmp/puppet-module" --reports=fleetdm --hiera_config hiera.yaml examples/multiple-teams.pp
- Login into the Puppet Forge, credentials are in 1Password.
- Visit the upload page and upload the
tar.gzfile you generated.
Development cheatsheet
Add your environment info to ee/tools/puppet/fleetdm/data/common.yaml.
Ensure that the computer you are using for development has MDM turned on in your Fleet instance.
From the ee/tools/puppet/fleetdm directory, trigger a puppet run using the same machine as the server and client:
puppet apply --debug --test --modulepath="$(pwd)/.." --reports=fleetdm --hiera_config hiera.yaml examples/multiple-teams.pp
To trigger a puppet run to a remote server use:
puppet agent --server puppet --serverport 8140 -t --debug
Install pdk bundle dependencies required for linting, formatting, and testing:
pdk bundle install
To lint/fix Puppet (.pp) files, use:
pdk bundle exec puppet-lint --fix .
To lint/fix Ruby (.rb) files, use:
pdk bundle exec rubocop -A
To run tests, use:
pdk test unit