Etckeeper on Kicksecure
This article is part of my Self-Hosting with Kicksecure series.
1. Introduction⌗
Before making any system changes, I want to decide on a way to record every change I make so that:
- I can easily reproduce my work if I ever have to reinstall or migrate to another machine
- I can easily identify problematic configs and revert them
- I don’t forget the reasoning behind a particular security decision or config change in 6 months
- I can identify what changes I made as opposed to changes made by software or other people
- I can compare the current state of my configs against a ‘known-good’ config
The /etc directory will contain most of my configs. Outside of /etc I will need to pay attention to my dotfiles which I like to manage with GNU Stow.
Etckeeper is a neat piece of software that turns /etc into a git repository. It automatically commits changes before and after package installations, and I can manually commit my own changes too.
2. Installation⌗
Kicksecure protects itself by isolating system maintainence tasks from daily activity. This means administrative tasks like installing new software cannot be performed from the standard user account, even with sudo. You have to reboot and select an option to boot into a session with the sysmaint account, make your changes, and then reboot back into the standard user session to continue with daily usage.
Having booted with sysmaint, I install Etckeeper from the Debian repositories:
apt install etckeeper
3. Etckeeper Basics⌗
Do the standard git stuff:
git config --global user.email "person@email.com"
git config --global user.name "I'm a person with a name!"
I start by initializing the repository:
```bash
cd /etc
etckeeper init
And making my initial commit:
etckeeper commit "Initial configuration snapshot"
Etckeeper hooks into apt. When I install or remove packages, it automatically commits them to the git repo. So I don’t need to worry about doing a commit myself! I only need to commit after I make manual changes in /etc.
For configuration changes I make outside of apt:
# within /etc
git add .
etckeeper commit "Descriptive message about what changed"
4. Viewing History⌗
Standard git commands work:
cd /etc
git log --oneline
View a specific change:
git show COMMIT_HASH
Compare two states:
git diff COMMIT_HASH1 COMMIT_HASH2
5. The .gitignore File⌗
Some files in /etc shouldn’t be tracked: temporary files, secrets, or auto-generated content.
On my server I ended up configuring a ZFS RAID. Here’s an example of excluding tracking of my ZFS cache with a few other things in /etc/.gitignore:
# Ignore auto-generated ZFS cache
/zfs/zfs-list.cache/
# Example: ignore temporary files
*.tmp
*.swp
After editing:
git add .gitignore
etckeeper commit "Updated gitignore to exclude my auto-generated ZFS cache"
6. Backups⌗
Always back up your changes so you have access to these records if your system breaks! In my case, I back up to a local ‘bare repository’ on my BTRFS backup drive. I explain how I set up this drive on Kicksecure in a later post.
Additionally, because I’d like to be able to identify known-good states of my configs even if an attacker compromises my server or network, I sanatize + compress + back up my data (or just the hashes for big files) to an air-gapped system regularly using something similar to a data diode. The air gap setup is beyond the scope of this post, but I thought the suggestion might interest readers!
Here’s how I back up my /etc repo:
6.1. Create a Bare Repository⌗
On my already mounted BTRFS storage:
mkdir -p /mnt/storage_name/host_vault/kicksecure-etckeeper.git
git init --bare /mnt/storage_name/host_vault/kicksecure-etckeeper.git
6.2. Add as Remote⌗
cd /etc
git remote add localvault /mnt/storage_name/host_vault/kicksecure-etckeeper.git
6.3. Push Changes⌗
git push -u localvault main
Future pushes:
git push localvault
6.4. Push After Every Commit⌗
This became a habit:
etckeeper commit "Made a change" && git push localvault
7. What to Track⌗
Here’s what I have tracked so far in /etc:
/etc/fstab- Mount point config/etc/crypttab- Encrypted drive config/etc/ufw/- Firewall rules/etc/ssh/- SSH configuration/etc/permission-hardener.d/- Kicksecure permission whitelists/etc/systemd/system/- Custom systemd units/etc/modprobe.d/- Kernel module configuration