Skip to content

Detect configuration drift on a machine

What you'll learn:

  • What drift detection checks, and how it differs from the vulnerability scan
  • How to write a baseline, the state you want a machine to be in
  • How to attach it to a machine, run a scan and read the gaps
  • What happens when you patch a machine and the baseline no longer matches

Time: ~20 minutes
Prerequisites: A machine registered in SSH mode (see Add your first client machine) and a maintainer or administrator account.


What drift detection answers

The vulnerability scan asks "does this machine have known flaws?". Drift detection asks a different question: "is this machine still in the state I declared?"

You write the desired state once, as a baseline: packages that must be present, absent or at a given version, services that must be running, files that must keep a known checksum, permissions that must be set. Repod compares the machine with it and reports every gap.

Two properties are worth knowing before you start:

  • It is read-only. Repod only looks. It never changes the machine, and there is no automatic repair: fixing a gap is up to you.
  • It only checks machines that have a baseline. A machine with no baseline is simply not checked, and that is a normal state, not an error.

Step 1 — Open the page

Open Sécurité → Détection de dérive.

The drift detection page with no baseline yet, and the explanation that a machine without a baseline is not an error

Figure 1 — The page before any baseline exists.

  1. No baseline. "Une machine sans baseline assignée n'a simplement aucune vérification de dérive — ce n'est pas une erreur."
  2. Créer la première baseline. The two buttons at the top right do the same job in two ways: Nouvelle baseline (name and description, then you add rules one by one) and Importer YAML (the whole baseline at once). We use the second one.

Step 2 — Write the baseline

A baseline is a short YAML document. Here is the one we use, for an Ubuntu 22.04 server:

name: demo-ubuntu-jammy
description: Baseline de démonstration pour une machine Ubuntu 22.04
rules:
  - id: git-version
    type: package
    target: git
    expected: "1:2.34.1-1ubuntu1"
    severity: high

  - id: openssh-present
    type: package
    target: openssh-server
    expected: present
    severity: high

  - id: telnet-absent
    type: package
    target: telnet
    expected: absent
    severity: medium

  - id: ssh-running
    type: service
    target: ssh
    expected_state: active
    severity: critical

  - id: sshd-config-hash
    type: file
    path: /etc/ssh/sshd_config
    expected_sha256: "<the SHA-256 of the file>"
    severity: high

  - id: shadow-permissions
    type: permission
    path: /etc/shadow
    expected_mode: "640"
    expected_owner: root
    expected_group: shadow
    severity: high

Each rule has a unique id, a type, what to look at, what is expected, and a severity (critical, high, medium or low):

Type Looks at Expected value
package target: the package name expected: an exact version, a pattern such as 1.18.*, present or absent
service target: the service name expected_state: active, inactive, enabled or disabled
file path expected_sha256: the checksum. Get it with sha256sum /etc/ssh/sshd_config
permission path any of expected_mode, expected_owner, expected_group. Only what you write is checked

Click Importer YAML.

The import window: a text area for the YAML, a link to insert an example and the Import button

Figure 2 — The import window.

  1. The text area. Paste your YAML here.
  2. Insérer un exemple. Fills it with a complete example to adapt.
  3. Importer. Creates the baseline.

The window with the YAML pasted: the name, the first rules and the Import button

Figure 3 — The baseline, ready to import.

  1. Name and description.
  2. A rule. Its id, type and target.
  3. The expected value. For git, the exact version.
  4. Importer. Click it. The window closes and a message confirms the import.

Importing twice creates two baselines

The import does not update an existing baseline: it adds a new one. To change a baseline, edit it or duplicate it, then delete the old one.


Step 3 — Check the rules

The baseline now appears in the list.

The baseline list: the baseline with its description and its actions

Figure 4 — The baseline list.

  1. The baseline. Name, description and author.
  2. The actions. Règles / Attribution, Éditer, Dupliquer and Supprimer.

Click Règles / Attribution.

The rules tab: the six rules with their type and severity, and the form to add a rule

Figure 5 — The rules.

  1. Two tabs. Règles and Attribution.
  2. A rule. Its type (PAQUET, SERVICE, FICHIER, PERMISSION), its id, its target and its severity. Retirer deletes it.
  3. A service rule. Here ssh-running, marked critical.
  4. Nouvelle règle. Adds a rule by hand: identifier, type, target, severity, and optional parameters in JSON.
  5. Exporter YAML. Downloads the baseline back as YAML, for a backup or to reuse it.

Step 4 — Attach the baseline to a machine

A baseline does nothing until it is attached. Open the Attribution tab.

The attribution tab: choose a machine, assign it, and the machine listed once assigned

Figure 6 — Attaching the baseline.

  1. Nouvelle attribution. Choose the kind, Tag machine or Machine (client), then the tag or the machine, and click Attribuer.
  2. The rule of precedence. "Une attribution par client remplace entièrement les attributions par tag pour cette machine (pas de fusion)." A baseline attached directly to a machine replaces the ones it would get through its tags. They are never combined.
  3. The attribution. Here the machine ubuntu-deb. Retirer removes it.

Attach by tag to cover a whole group of machines at once, for example everything tagged prod. Attach to a machine for an exception. We chose the machine, so the demonstration touches nothing else.


Step 5 — Run a scan and read the result

Open Clients → Machines clientes, click the machine, then open its Dérive tab.

The Drift tab before any scan: no result and a button to start one

Figure 7 — Before the first scan.

  1. No result yet. Either no baseline is attached to this machine, or no scan has been run.
  2. Lancer le scan de dérive. Starts the first scan.

Repod connects over SSH and reads what each rule asks for. A few seconds later:

The scan result: counters, then the rules grouped by type with the expected and observed values

Figure 8 — The result.

  1. The counters. Dérive (here 2), Conforme (4), Erreur (0) and Non applicable (0), with the date of the scan and a Rescanner button.
  2. Services. Rules grouped by type. A green badge means everything in the group conforms.
  3. A drift. git-version: "attendu : 1:2.34.1-1ubuntu1 → constaté : 1:2.34.1-1ubuntu1.17". The line gives the expected value and the observed one side by side.
  4. Another drift. telnet-absent: "attendu : absent → constaté : 0.17-44build1". The telnet client is installed although the baseline says it should not be.
  5. A conforming rule. The permissions of /etc/shadow match the baseline. The file checksum does too.

The four states:

  • Conforme. The machine matches the rule.
  • Dérive. The machine differs. This is the finding to look at.
  • Erreur. Repod could not check, for example because the SSH command failed.
  • Non applicable. The rule cannot apply to this machine. This is the case for service, file and permission rules on a machine in agent mode, which Repod cannot query.

Step 6 — A drift is not always a problem

The first drift above deserves a second look. The baseline says git must be 1:2.34.1-1ubuntu1. The machine runs 1:2.34.1-1ubuntu1.17 because it was patched to fix a vulnerability (see Fix a vulnerability on your machines). The machine got better, and the baseline is now wrong.

So a drift can mean two things:

  • The machine moved away from the standard: someone installed telnet, changed a file. Decide whether to put it back.
  • The baseline is out of date: the standard itself must change.

Do not pin an exact version unless you must

A rule with an exact version drifts at every security update. For a package you want to keep patched, prefer present, or a pattern such as 1:2.34.*. Pin a precise version only when a precise version really is a requirement.

Drift detection also runs by itself, every day (see Schedule the recurring scans and mirrors): you do not have to click Rescanner to learn that something changed.


What's next