Skip to content

Commit 6c19781

Browse files
johnrwatsonjhelwig
authored andcommitted
Replace unique identifier check and prep for NixOS
Primary: - Use "/usr/bin/env bash" for script invocations - Perform "sudo -v" and user check in orchestration script - Account for pitfalls in PATH in README - Add bash syntax highlighting in README NixOS: - Add ability to specify token file path instead of a raw token string - Add AV install opt-out option (you still need it!) - Allow opt-out systemd service install (you still need it!) - Add NixOS configuration file example Co-authored-by: John Watson <[email protected]> Co-authored-by: Jacob Helwig <[email protected]> Signed-off-by: Nick Gerace <[email protected]>
1 parent ea7a277 commit 6c19781

File tree

6 files changed

+128
-24
lines changed

6 files changed

+128
-24
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@
44
Ensure your system has `git`, `jq`. `lscpu`, `lshw` and `ansible-playbook` packages available to your user.
55

66
Pull the Orchestration File & example vars file
7-
```
7+
```bash
88
curl https://raw.githubusercontent.com/systeminit/si-device-compliance/main/orchestrate-install.sh > /tmp/orchestrate-install.sh
99
curl https://raw.githubusercontent.com/systeminit/si-device-compliance/main/installation.vars.example > /tmp/installation.vars
1010
```
1111

1212
Make the script executable
13-
```
13+
```bash
1414
chmod a+x /tmp/orchestrate-install.sh
1515
```
1616

1717
Adjust the variables file for your user/machine values
18-
```
18+
```bash
19+
# Use your editor of choice
1920
vim /tmp/installation.vars
2021
```
22+
2123
Modify these fields to their correct value:
22-
```
24+
```bash
2325
EMAIL_ADDRESS: [email_id] # Your corporate systeminit.com email id
24-
SUBMISSION_TOKEN: [submission_token] # Your submission token # Appendix 2 - Generating a Submission Token
26+
SUBMISSION_TOKEN: [submission_token] # Your submission token (or path to a single-line file containing it) # Appendix 2 - Generating a Submission Token
2527
ROOT_DISK_ENCRYPTED_PARTITION_BLK: [disk-id] # Your encrypted OS root disk blk
2628
USING_PASSWORD_MANAGER: [true/false] # Whether you are using a password manager
2729
```
2830

2931
Run the installation:
30-
```
32+
```bash
3133
/bin/bash /tmp/orchestrate-install.sh /tmp/installation.vars
34+
35+
# You may need to use bash from your PATH
36+
bash /tmp/orchestrate-install.sh /tmp/installation.vars
3237
```
3338

3439
You can check it is submitting correctly with:
35-
```
36-
sudo /etc/si-device-compliance/collect_compliance_data.sh <your token>
40+
```bash
41+
sudo /etc/si-device-compliance/collect_compliance_data.sh <YOUR-TOKEN-OR-PATH>
3742
```
3843

3944
## System Initiative Device Compliance Background

compliance/ansible/main.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
- name: Install Antivirus / Verify Installation
2828
ansible.builtin.include_role:
2929
name: antivirus
30+
when: INSTALL_ANTIVIRUS
3031

3132
- name: Install Service and Timer to submit evidence
3233
ansible.builtin.include_role:
33-
name: service
34+
name: service

compliance/ansible/roles/service/tasks/main.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
group: root
1919
mode: '0755'
2020
content: |
21-
#!/bin/bash
21+
#!/usr/bin/env bash
2222
2323
set -eo pipefail
2424
@@ -29,6 +29,11 @@
2929
SCRIPT_USER="{{ EMAIL_ADDRESS }}"
3030
SUBMISSION_TOKEN="${1:-unset}"
3131
32+
# If the variable corresponds to a file path, read the token from the file provided.
33+
if [ -f "$SUBMISSION_TOKEN" ]; then
34+
SUBMISSION_TOKEN="$(cat "$SUBMISSION_TOKEN")"
35+
fi
36+
3237
echo "----------------------------------------------------"
3338
3439
# Collect hostname
@@ -43,12 +48,16 @@
4348
] | join(", ")')"
4449
echo "LSCPU found to be $LSCPU"
4550
46-
# Looking output like: 230318033800674 - Pro WS WRX80E-SAGE SE WIFI
47-
LSHW="$(lshw -json | jq -r '
51+
# Looking output like: 1783e116-bf08-36b8-b28e-08bfb836b28d
52+
HARDWARE_UUID="$(dmidecode --type system | grep UUID | awk -F: '{ print $2 }' | tr -d '[:space:]')"
53+
echo "HARDWARE_UUID found to be $HARDWARE_UUID"
54+
55+
# Looking output like: 1783e116-bf08-36b8-b28e-08bfb836b28d - Pro WS WRX80E-SAGE SE WIFI
56+
LSHW="$(lshw -json | jq -r "
4857
.children[]
49-
| select(.description == "Motherboard")
50-
| "\(.serial) - \(.product)"
51-
')"
58+
| select(.description == \"Motherboard\")
59+
| \"${HARDWARE_UUID} - \(.product)\"
60+
")"
5261
echo "LSHW found to be $LSHW"
5362
5463
SERIAL_NUMBER="$(lshw -json | jq -r '
@@ -58,10 +67,6 @@
5867
')"
5968
echo "SERIAL_NUMBER found to be $SERIAL_NUMBER"
6069
61-
# Looking output like: 1783e116-bf08-36b8-b28e-08bfb836b28d
62-
HARDWARE_UUID="$(dmidecode --type system | grep UUID | awk -F: '{ print $2 }')"
63-
echo "HARDWARE_UUID found to be $HARDWARE_UUID"
64-
6570
# Looking output like:
6671
DISKS="$(lsblk -J | jq '{
6772
drives: [
@@ -161,6 +166,7 @@
161166
--data-raw "$RESOURCES"
162167
163168
- name: Set up systemd timer for compliance data collection
169+
when: INSTALL_SYSTEMD_SERVICE
164170
block:
165171
- name: Create systemd service file for compliance data collection
166172
copy:
@@ -221,4 +227,4 @@
221227
systemd:
222228
name: collect_compliance_data.timer
223229
enabled: true
224-
state: started
230+
state: started

examples/si-nixos-configuration.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
config,
3+
lib,
4+
pkgs,
5+
...
6+
}: {
7+
# ========== INSTRUCTIONS ==========
8+
# 1) follow the README instructions until you edit the "installation.vars" file
9+
# 2) prepare your compliance token for the next step (i.e. have it handy!)
10+
# 3) run the following command: "sudo mkdir -p /etc/si-device-compliance"
11+
# 4) run the following command (and replace the relevant token piece): "echo <YOUR-TOKEN-HERE> | sudo tee /etc/si-device-compliance/token.txt"
12+
# 5) follow NixOS-relevant instructions in the "installation.vars" file
13+
# 6) in that file, set the "SUBMISSION_TOKEN" to "/etc/si-device-compliance/token.txt"
14+
# 7) import THIS file into your NixOS configuration using "imports = [./path/to/si-nixos-configuration.nix];"
15+
# 8) rebuild your NixOS configuration
16+
# 9) continue following the README instructions
17+
# ==================================
18+
19+
# Install base packages needed for installation and data collection
20+
environment.systemPackages = with pkgs; [
21+
ansible
22+
bash
23+
curl
24+
dmidecode
25+
git
26+
jq
27+
lshw
28+
];
29+
30+
# Install and setup the antivirus
31+
services.clamav.daemon.enable = true;
32+
services.clamav.scanner.enable = true;
33+
services.clamav.updater.enable = true;
34+
35+
# Install and setup compliance data collection
36+
systemd.services."collect_compliance_data" = {
37+
enable = true;
38+
description = "Collect Compliance Data";
39+
unitConfig = {
40+
Type = "simple";
41+
};
42+
serviceConfig = {
43+
Type = "oneshot";
44+
User = "root";
45+
ExecStart = "/etc/si-device-compliance/collect_compliance_data.sh /etc/si-device-compliance/token.txt";
46+
StandardOutput = append:/etc/si-device-compliance/logs/run.log;
47+
StandardError = append:/etc/si-device-compliance/logs/run.log;
48+
};
49+
};
50+
51+
# Run compliance data collection on boot
52+
systemd.timers."collect_compliance_data" = {
53+
enable = true;
54+
description = "Timer to run compliance data collection 10 minutes after boot";
55+
timerConfig = {
56+
OnBootSec = "10min";
57+
Unit = "collect_compliance_data.service";
58+
};
59+
wantedBy = ["timers.target"];
60+
};
61+
62+
# Run compliance data collection monthly
63+
systemd.timers."collect_compliance_data_monthly" = {
64+
enable = true;
65+
description = "Timer to run compliance data collection every month";
66+
timerConfig = {
67+
OnCalendar = "monthly";
68+
Unit = "collect_compliance_data.service";
69+
};
70+
wantedBy = ["timers.target"];
71+
};
72+
}

installation.vars.example

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ RESULTS_DIR: /etc/si-device-compliance/results
1212
LOGS_DIR: /etc/si-device-compliance/logs
1313
SERVICE_SCRIPT_PATH: /etc/si-device-compliance/collect_compliance_data.sh
1414

15+
# If you are running a distribution without a solid means of imperative package installation,
16+
# (e.g. NixOS), then you can opt-out of installing the AV. However, you are responsible for
17+
# installing it correctly. To do so, set the value to "false".
18+
INSTALL_ANTIVIRUS: true
19+
20+
# If you are running a distribution that disallows imperative systemd service installation, # (e.g.
21+
# NixOS), then you can opt-out of installing service. However, you are responsible for installing
22+
# it correctly, meaning that the compliance script runs on a monthly cadence. To do so, set the
23+
# value to "false".
24+
INSTALL_SYSTEMD_SERVICE: true
25+
1526
# -----------------------------------------
1627
# Compliance Tracking Variables
1728
EMAIL_ADDRESS: [email_id]
29+
30+
# This can either be the literal token or a path to a single-line file containing the token. This
31+
# is particularly helpful if you are checking in configuration files or unit files into source
32+
# control (e.g NixOS). Example location if using a file: "/etc/si-device-compliance/token.txt".
1833
SUBMISSION_TOKEN: [submission_token]
1934

2035
# The root disk of your machine must be encrypted, enter the blk reference to
@@ -33,4 +48,4 @@ ROOT_DISK_ENCRYPTED_PARTITION_BLK: [disk-id]
3348
# machine specifically, you can assume it's true [true/false].
3449
USING_PASSWORD_MANAGER: [true/false]
3550

36-
# -----------------------------------------
51+
# -----------------------------------------

orchestrate-install.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#!/bin/bash
2-
1+
#!/usr/bin/env bash
32
# Call this function with:
43
# ./orchestrate-install.sh <filepath to variables>
54

65
set -eo pipefail
76

7+
if [ "$EUID" -eq 0 ]; then
8+
echo "error: must not run directly as root"
9+
exit 1
10+
fi
11+
sudo -v
12+
813
VARIABLES_FILE="${1:-/tmp/installation.vars}"
914

1015
# Get a value for a variable in order of preference (a) from the environment (b) from the variables file (c) using the default provided.
@@ -160,4 +165,4 @@ check_free_disk_space "$COMPLIANCE_DIR" '5'
160165
check_pre_reqs
161166
pull_configuration_management
162167
execute_configuration_management
163-
execute_cleanup
168+
execute_cleanup

0 commit comments

Comments
 (0)