Add cleanup-host.sh to revoke the AppArmor-fix sudoers grant after deploy

Mirrors bootstrap-host.sh in reverse: removes the sudoers rule and the
fix-lxc-apparmor.sh script it installed, so the elevated grant only stands
for the duration of an active deployment instead of indefinitely.
create-graylog-lxc.sh already degrades cleanly to its manual fallback when
the automation isn't present, so this is a safe no-op-adjacent revoke.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
byrsapty 2026-07-22 22:21:04 +03:00
parent d98a63c0f1
commit 2510bba21c
3 changed files with 35 additions and 0 deletions

View file

@ -320,6 +320,14 @@ alert templates already do it.
`sudo -n fix-lxc-apparmor.sh` automatically and only falls back to the
manual instructions above if that sudoers rule isn't present yet.
**Revoking it again:** run `cleanup-host.sh` as root once the deployment
is done - it removes both the sudoers rule and the script, so the
elevated grant only stands for the duration of an active deployment
rather than indefinitely. `create-graylog-lxc.sh` degrades cleanly back
to the manual fallback if it's ever run again without the automation in
place; re-run `bootstrap-host.sh` whenever you need it back (e.g. before
recreating a container from scratch).
- **`vm.max_map_count`**: OpenSearch requires >= 262144. This is a
host-wide kernel parameter, not namespaced per LXC, so it can't be set
from inside the container either. `install-graylog.sh` only verifies it

View file

@ -324,6 +324,14 @@ Graylog відхиляє його з помилкою Jackson-поліморфі
сам викликає `sudo -n fix-lxc-apparmor.sh` і повертається до ручної
інструкції вище лише якщо цього sudoers-правила ще немає.
**Відкликання назад:** запустіть `cleanup-host.sh` від root, коли
деплой завершено — він видаляє і sudoers-правило, і скрипт, тож
підвищений грант існує лише на час активного деплою, а не постійно.
`create-graylog-lxc.sh` коректно повертається до ручного fallback, якщо
запуститься без цієї автоматизації; запускайте `bootstrap-host.sh`
повторно, коли знадобиться знову (наприклад, перед пересозданням
контейнера з нуля).
- **`vm.max_map_count`**: OpenSearch вимагає >= 262144. Це
загальносистемний параметр ядра хоста, не прив'язаний до конкретного
LXC, тож встановити його зсередини контейнера теж неможливо.

19
cleanup-host.sh Normal file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# Run as root after deployment is done - reverses bootstrap-host.sh by
# removing the temporary AppArmor-fix automation (sudoers rule + script).
# Keeps the elevated grant's lifetime scoped to "while actively deploying"
# rather than standing indefinitely.
#
# Safe to run even if bootstrap-host.sh was never run (both rm -f calls are
# no-ops on missing files). After this, create-graylog-lxc.sh falls back to
# printing the manual AppArmor fix instructions again, same as before
# bootstrap-host.sh existed - re-run bootstrap-host.sh whenever you need the
# automated path again (e.g. before recreating a container from scratch).
set -euo pipefail
[ "$(id -u)" -eq 0 ] || { echo "Must run as root." >&2; exit 1; }
rm -f /etc/sudoers.d/claude-deploy-apparmor
rm -f /usr/local/sbin/fix-lxc-apparmor.sh
echo "Removed AppArmor-fix automation (sudoers rule + script)."