Repository navigation
Recipe: Find out why a service keeps dying
app-billing.service falls over every so often, the journal says Permission denied, and ausearch hands you a few hundred denials from the last hour. Most of them have nothing to do with it. This recipe gets you the ones that do.
Drop this in /etc/sentry-v2/policies.d/50-app-billing.toml:
[[policy]]
name = "app-billing-failed"
[policy.when]
signal = "unit_failed"
units = ["app-billing.service"]
[[policy.do]]
action = "notify"notify changes nothing on the host. Strictly, you don't need the policy at all, because every failure gets a bundle anyway. What it adds is a decision with this policy's name in the bundle, so you can filter on it downstream.
# sentry-v2ctl policy validate
# systemctl reload sentry-v2# sentry-v2ctl incidents --unit app-billing.service
# sentry-v2ctl show <ID> | jq '.incident.correlations[] | {confidence, reasons, domain: .avc.scontext_type, perms: .avc.perms, target: .avc.tcontext, class: .avc.tclass}'Each correlation is a denial Sentry-v2 thinks belongs to this failure, with a score and the reasons. Look at the reasons before the score:
-
pid in unit cgroupmeans the denied process was inside this unit when the kernel refused it. That's as close to proof as the audit log gets. -
scontext type matches unit domainandcomm matches ExecStartwithout the cgroup reason are a lead. Something running the same binary in the same domain was denied. Usually it's this unit; on a host with template units it might be a sibling.
A denial from a process that was in another unit's cgroup when it arrived stays out of the bundle, however loud it is.
Pull exactly those denials out of the audit log and let audit2allow explain them:
# sentry-v2ctl show <ID> | jq -r '.incident.correlations[].avc.serial' \
| while read -r id; do ausearch --input-logs -a "$id" --raw; done \
| audit2allow -wRead what it says. More often than not, the answer is a label or a boolean, not a new policy module:
-
A file in the wrong place, or with the wrong label.
restorecon -von it, orsemanage fcontextif it lives somewhere non-standard. -
A feature that's off.
audit2allow -wnames the boolean; check it withgetsebooland set it withsetsebool -P. - Something the policy really doesn't allow. That's when a local module is the answer, and you'll know exactly what's in it.
Sentry-v2 won't load policy for you, from the CLI or from Cockpit. audit2allow -M output loaded unread is how a mislabelled file becomes a permanent hole.
- Correlation: the window, the weights and the arithmetic.
- FAQ: what happens when it gets it wrong?