Sub topic 6
Package Management, Repositories, and Updates
This chapter covers the CIS Benchmark section on software sources and patching. It assumes you can use dnf or apt, read systemd unit status, and have root or sudo access to a test server. It also assumes you have scanned the host with OpenSCAP, as covered in the earlier assessment chapter. Examples use RHEL 9 family commands, with Debian and Ubuntu equivalents where they differ.
Why the benchmark cares about packages
A server is only as trustworthy as the software it installs. The CIS recommendations in this area protect three things:
- Origin. Packages come only from repositories you chose and trust.
- Integrity. Every package is checked against a cryptographic signature before it installs.
- Currency. Known vulnerabilities get fixed by updates, applied on a schedule you control.
Most findings in this section are not kernel flags. They are policy settings and habits, so they are easy to pass on a fresh install and easy to drift away from later.
The working model
A package manager downloads metadata from each configured repository. It resolves dependencies, downloads packages, verifies signatures, and then installs them. Each step has a setting that CIS expects you to check.
Check that GPG keys are configured
CIS requires that the package manager verify signatures. On RHEL-family systems, check the imported keys and the global setting:
# List GPG public keys imported into the RPM database
rpm -q gpg-pubkey --qf '%{NAME}-%{VERSION}-%{RELEASE}\t%{SUMMARY}\n'
# gpgcheck must be 1 globally
grep -E '^\s*gpgcheck' /etc/dnf/dnf.conf
# Find any repository that disables checking
grep -rE '^\s*gpgcheck\s*=\s*0' /etc/yum.repos.d/ /etc/dnf/dnf.confThe last command should print nothing. A match means a repository accepts unsigned packages, and you should either fix it or document it as an exception.
A healthy /etc/dnf/dnf.conf looks like this:
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
localpkg_gpgcheck=1localpkg_gpgcheck=1 matters because it makes dnf install ./file.rpm verify the signature of a local file too. Many administrators forget that local installs bypass repository checks unless this is set.
On Debian and Ubuntu, APT verifies repository metadata by default. Review the keyrings and look for insecure overrides:
# Keys trusted for repositories
ls -l /etc/apt/trusted.gpg.d/ /usr/share/keyrings/ 2>/dev/null
# Flags that weaken verification
grep -rEi 'trusted=yes|AllowUnauthenticated|allow-insecure' /etc/apt/Review repositories
CIS asks you to confirm that repositories are configured correctly. In practice, that means you can explain every entry.
# RHEL family: every enabled repository with its source
dnf repolist --enabled -v | grep -E 'Repo-id|Repo-baseurl|Repo-mirrors'
# Debian family: configured sources
grep -rhv '^#' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/nullCheck each of these properties:
- The URL uses HTTPS, or HTTP only for a mirror whose metadata is signed.
- The repository belongs to the vendor or to your internal mirror.
- Third-party repositories such as EPEL have a documented owner and purpose.
- Repository GPG checking is on, and
repo_gpgcheck=1where the vendor supports it.
This is a manual recommendation in the benchmark. No scanner can decide whether a repository is trustworthy for your organization, so record your decision.
Apply updates
CIS expects that updates are installed, but it does not name a number of days. You choose a policy and write it down. A typical policy applies security updates automatically and applies everything else in a maintenance window.
# See what is pending (security only)
sudo dnf updateinfo list security
# Apply security updates only
sudo dnf upgrade --security
# Debian and Ubuntu equivalent
sudo apt update && sudo apt upgradeAfter a kernel or core library update, the old code stays in memory until restart. On RHEL-family hosts, dnf needs-restarting -r reports whether a reboot is required, and dnf needs-restarting -s lists services to restart. Debian-family hosts expose /var/run/reboot-required.
Automatic security updates
For RHEL 9, dnf-automatic handles unattended patching:
sudo dnf install -y dnf-automatic
sudo mkdir -p /etc/systemd/system/dnf-automatic.timer.dSet the behavior in /etc/dnf/automatic.conf:
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
random_sleep = 3600
[emitters]
emit_via = stdioThen enable the timer and check when it runs next:
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timerOn Debian and Ubuntu, the equivalent is the unattended-upgrades package.
Remove what you do not need
Each installed package adds files and possibly a service. The benchmark also recommends removing specific packages, such as legacy clients and servers. Later chapters cover services directly, but you can audit the package side now:
# Packages installed explicitly by a user, not pulled in as dependencies
dnf history userinstalled
# Is a specific package present?
rpm -q telnet-server ypserv tftp-server 2>&1 | grep -v 'is not installed'
# Remove one and its unused dependencies
sudo dnf remove telnet-serverDebian-family hosts use apt list --installed and apt autoremove.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `GPG check FAILED` on install | Key for that repository was never imported | Import the vendor key from a verified source, then retry |
| Scan fails `gpgcheck` rule though `dnf.conf` is correct | A file in `/etc/yum.repos.d/` sets `gpgcheck=0` | Search every `.repo` file, not only `dnf.conf` |
| `dnf-automatic` never runs | Timer enabled but not started, or a unit override is missing | Run `systemctl list-timers` and read `journalctl -u dnf-automatic` |
| Rule passes, but vulnerabilities remain | Package updated but service or kernel not restarted | Check `dnf needs-restarting` and schedule the restart |
| Remediation script breaks an internal repository | Script forced `gpgcheck=1` on an unsigned internal mirror | Sign the internal packages, or record an exception |
Verify with a scan
After the changes, rerun only the relevant rules to confirm the result. Use the rule IDs shown in your earlier report:
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--rule xccdf_org.ssgproject.content_rule_ensure_gpgcheck_globally_activated \
--results pkg-results.xml \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlA pass result for the rule confirms the global setting. Per-repository checks still need the grep command from earlier.
Summary
- Confirm signature checking is on globally, for local packages, and in every
.repofile. - Keep only repositories you can justify, and record who owns each one.
- Choose an update policy, apply security updates on a schedule, and restart what the updates affect.
- Remove packages the server's role does not need.
Exercise
A scan reports that gpgcheck is correctly set to 1 in /etc/dnf/dnf.conf, yet an audit finds a repository that installs unsigned packages. Where should you look, and which command finds the cause?
Show answer
Individual repository files in /etc/yum.repos.d/ can set gpgcheck=0 for their own repository, which overrides the global value. Run grep -rE '^\s*gpgcheck\s*=\s*0' /etc/yum.repos.d/ /etc/dnf/dnf.conf. Any match is the cause. Fix it by setting gpgcheck=1 and importing the vendor key, or record a documented exception if the repository cannot be signed.
Exercise
You enabled dnf-automatic with upgrade_type = security, and the scan shows no pending security updates. A new kernel was installed last night, but the vulnerability scanner still reports the old kernel CVE. What explains this, and how do you confirm it?
Show answer
The new kernel is installed but not running, because a kernel update takes effect only after a reboot. Confirm with uname -r, which shows the running kernel, and with sudo dnf needs-restarting -r, which reports that a reboot is required. Schedule a reboot in a maintenance window.