Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #15008: Add a "Rudder by example" to add CPU vulnerabilities status to inventory #584

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/get-started/modules/ROOT/assets/images/indexhtml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/get-started/modules/ROOT/assets/images/permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/get-started/modules/ROOT/assets/images/service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/get-started/modules/ROOT/assets/images/template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/get-started/modules/ROOT/assets/images/website.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/rudder-by-example/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
** xref:files/edition-replace-line.adoc[Enforce part of a line in a file]
* System management
** xref:system/manage-registry.adoc[Manage Windows registry content]
** xref:system/extend-inventories.adoc[Extend inventories with custom data]
2 changes: 1 addition & 1 deletion src/rudder-by-example/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= Rudder by example

This document gives examples of Rudder usecase examples with a step by step explanation.
This document gives examples of Rudder use case examples with a step by step explanation.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
= Extend inventories with custom data

== Use case

Rudder provides inventories containing generic information about
nodes hardware, configuration and installed software, allowing to classify nodes into
relevant groups and apply different policies.
But sometimes, the content of these inventories is not enough, and you
may want to *add custom data* that could be a node property, but *comes
directly from the node*.

In this case, you can use the xref:reference:usage:advanced_node_management.adoc#extend-nodes-inventory[inventory extension hook mechanism].
Additional data will appear as *read-only node properties in the Rudder server*, ready
to be used like the rest of the properties (to classify nodes or be part
of actual policies content).

We will here describe a complete example, allowing to collect information
about known *CPU vulnerabilities* on the nodes.

image::cpu_vuln.png[CPU vulnerabilities]

== Policy design

To be able to use our custom data we need to:

* write a script collecting the information
* deploy the script to the relevant nodes
* use the defined property to create groups

== Inventory extension script

An inventory extension script can be written in any language, it just needs to be an
executable file placed in `/var/rudder/hooks.d` that outputs a json object. It will be called at each
inventory, and its output will be added into it.

NOTE: Read the xref:reference:usage:advanced_node_management.adoc#extend-nodes-inventory[dedicated section]
for more details.

We'll just have to extract vulnerabilities information provided by the kernel in
`/sys/devices/system/cpu/vulnerabilities`. We'll not return the raw data, but
rework it to make it easily usable on the server. We'll:

* Determine the status of the node for each known vulnerability
* Add details in a separate variable for mode advanced handling

In our case, we have written a small python script (the https://github.com/Normation/rudder-tools/blob/master/contrib/inventory-hooks/cpu_vulnerabilities.py[script] and its https://github.com/Normation/rudder-tools/blob/master/contrib/inventory-hooks/cpu_vulnerabilities.adoc[documentation]) that outputs our CPU vulnerabilities in the
following format:

[source,json]
----
{
"cpu_vulnerabilities": {
"spectre_v2": {
"status": "vulnerable",
"details": "Retpoline without IBPB"
},
"spectre_v1": {
"status": "mitigated",
"details": "Load fences"
},
"meltdown": {
"status": "mitigated",
"details": "PTI"
}
}
}
----

[NOTE]
====

We have a https://github.com/Normation/rudder-tools/tree/master/contrib/inventory-hooks[central place] to allow sharing your inventory extension scripts, if your
are writing one, please consider contributing it! (Just open a _pull request_ directly on the repository,
your script doesn't have to be perfect!).

====

== Deploy the script

Here we can simply use any mean allowing to copy files from the root server to the nodes.
We will create a dedicated directory in `/var/rudder/configuration-repository/shared-files`
on the server and copy the hooks to the right nodes.

An good option (allowing different inventory on different machines)
is to create a dedicated technique like:

image::cpu_technique.png[Technique to deploy inventory hooks]

(applied permissions here are `root:root` and `755`).

Then you can add a directive for each hooks:

image::cpu_directive.png[Directive to deploy CPU vulnerabilities hook]

For example, in our example, we will very likely apply this directive to all our physical nodes.

== Use the defined properties

In our case, we want to define groups identifying vulnerable nodes.

image::cpu_prop.png[Defined property]

To use the data properly, we need to extract information from the object,
and cannot rely on a simple regex. We will use the
xref:reference:usage:node_management.adoc#search-nodes-properties-json-path[JSON path syntax].

For example to select nodes known to be vulnerable to `spectre_v2`, we need to use the `cpu_vulnerabilities:$.spectre_v2[?(@.status=='vulnerable')]` JSON path query in group form that
will only select nodes that have a `spectre_v2` object with the `vulnerable status`.

image::cpu_group.png[Defined group]

You can then apply rules to these groups (upgrade CPU microcode, plan reboots, etc.)

[NOTE]
====

Inventory data is updated daily, if you want to gather updated information,
run `rudder agent inventory` on the target nodes to se changes reflected in Rudder
server.

====