diff --git a/10-systems/bots/mardisopsbot.md b/10-systems/bots/mardisopsbot.md index 3d1e7cd..d091296 100644 --- a/10-systems/bots/mardisopsbot.md +++ b/10-systems/bots/mardisopsbot.md @@ -19,37 +19,53 @@ > the **VM `tg_bots` (192.168.1.254, hostname `tgbots`)** — NOT on the > external VPS `tgbots` (192.168.1.178, hostname `vmk`). -## Live deployment (deployed and verified 2026-09-10) +## Live deployment (v2 deployed and verified 2026-09-10 07:32 UTC) - **Host**: VM `tg_bots`, 192.168.1.254 (libvirt on bserv 192.168.1.130) - **User**: `ubuntu` (password in gnexus-creds secret "tgbots"; sudo uses the same password) - **Project Path**: `/home/ubuntu/bots/MardisOpsBot` -- **Main Script**: `bot.py` (venv: `/home/ubuntu/bots/MardisOpsBot/venv`, +- **Main Script**: `bot.py` v2 (venv: `/home/ubuntu/bots/MardisOpsBot/venv`, Python 3.10) - **Config**: `.env` in project dir (bot token, not documented here) - **Dependencies**: python-telegram-bot 22.8, python-dotenv, apscheduler (requirements.txt; pip 26.2.1 in venv) +## v2 features (deployed 2026-09-10 07:32 UTC) +- **`/backup` command**: creates a timestamped ZIP backup of + `/home/ubuntu/bots/MardisBot` code files (excludes `venv/`, `__pycache__/`, + `.env`) into the project dir. +- **ZIP-update**: admins can send a ZIP archive; the bot validates it + (must contain `bot.py` at root or single top-level subdir), extracts code + files, preserves `.env` and `venv/`, and keeps a rollback copy of the + previous `bot.py`. +- Sandbox logic tests: `test_sandbox.py` — 18/18 passed on 2026-09-10 + (run in `/tmp/mardisops_sandbox`, do not touch the live MardisBot dir). + ## systemd service - **Service Name**: `mardisops.service` — active (running), enabled - **Unit File**: `/etc/systemd/system/mardisops.service` -- **Deployed**: 2026-09-10 07:08 UTC (Main PID verified running) +- **Deployed**: v2 at 2026-09-10 07:32 UTC (restart verified) +- **Hardening**: `PrivateTmp=true`, `ProtectSystem=full`, + `ProtectHome=read-only`, + `ReadWritePaths=/home/ubuntu/bots/MardisOpsBot /home/ubuntu/bots/MardisBot` + (the MardisBot path is required for /backup and ZIP-update writes). - **Hardening note**: `NoNewPrivileges=true` was removed from the unit on 2026-09-10 07:12 UTC — it blocked sudo inside the service ("no new privileges" error, rc=1 on /status). Do not re-add it while the bot relies on sudo for systemctl/journalctl. ## sudoers grant -- `/etc/sudoers.d/99-mardisops-sudoers` (root:root, 0440, `visudo -c` OK) - allows user `ubuntu` NOPASSWD for: `systemctl status/is-active/is-enabled/show - mardisbot.service`, `systemctl restart mardisbot.service`, and +- `/etc/sudoers.d/99-mardisops-sudoers` (root:root, 0440, `visudo -c` OK, + updated 2026-09-10 07:32 UTC) allows user `ubuntu` NOPASSWD for: + `systemctl status/is-active/is-enabled/show mardisbot.service`, + `systemctl restart/stop/start mardisbot.service`, and `journalctl -u mardisbot.service *`. ## Access model - First 3 Telegram users who send `/start` become admins; user_ids are persisted in `/home/ubuntu/bots/MardisOpsBot/admins.json` (survives restarts). Everyone else is silently ignored. -- As of 2026-09-10 07:12 UTC one admin is enrolled: user_id 78389352. +- As of 2026-09-10 07:32 UTC one admin is enrolled: user_id 78389352. ## Service management ```bash @@ -58,6 +74,6 @@ sudo systemctl restart mardisops.service ``` -## Startup log (verified 2026-09-10) +## Startup log (verified 2026-09-10 07:32 UTC) - `ops bot starting; admins=[78389352] (max 3)` - `polling started` diff --git a/90-maintenance/pending-changes/20260910073239-2f4c8088.json b/90-maintenance/pending-changes/20260910073239-2f4c8088.json new file mode 100644 index 0000000..1b963d0 --- /dev/null +++ b/90-maintenance/pending-changes/20260910073239-2f4c8088.json @@ -0,0 +1,19 @@ +{ + "id": "20260910073239-2f4c8088", + "kind": "doc", + "target": "10-systems/bots/mardisopsbot.md", + "summary": "MardisOpsBot v2 deployed: /backup + ZIP-update, sudoers stop/start, unit ReadWritePaths; tests 18/18", + "reason": "v2 deployed to VM tg_bots: /backup + ZIP-update added, sudoers gained stop/start, unit gained ReadWritePaths for MardisBot dir; sandbox tests 18/18 passed. Verified live via SSH.", + "payload": { + "content": "---\ntitle: MardisOpsBot\ndescription: Telegram ops bot for monitoring and controlling mardisbot.service\nhost: tg_bots-vm\nstatus: active\nlast_reviewed: 2026-09-10\nowner: gmikcon\nconfidence: 100\nreview_interval: 90\nsource_of_truth: live_system\n---\n\n# MardisOpsBot\n\nTelegram ops bot for monitoring and controlling `mardisbot.service` (see\n`10-systems/bots/mardisbot.md`).\n\n> **Naming warning:** there are TWO similarly named hosts. This bot lives on\n> the **VM `tg_bots` (192.168.1.254, hostname `tgbots`)** — NOT on the\n> external VPS `tgbots` (192.168.1.178, hostname `vmk`).\n\n## Live deployment (v2 deployed and verified 2026-09-10 07:32 UTC)\n- **Host**: VM `tg_bots`, 192.168.1.254 (libvirt on bserv 192.168.1.130)\n- **User**: `ubuntu` (password in gnexus-creds secret \"tgbots\"; sudo uses the\n same password)\n- **Project Path**: `/home/ubuntu/bots/MardisOpsBot`\n- **Main Script**: `bot.py` v2 (venv: `/home/ubuntu/bots/MardisOpsBot/venv`,\n Python 3.10)\n- **Config**: `.env` in project dir (bot token, not documented here)\n- **Dependencies**: python-telegram-bot 22.8, python-dotenv, apscheduler\n (requirements.txt; pip 26.2.1 in venv)\n\n## v2 features (deployed 2026-09-10 07:32 UTC)\n- **`/backup` command**: creates a timestamped ZIP backup of\n `/home/ubuntu/bots/MardisBot` code files (excludes `venv/`, `__pycache__/`,\n `.env`) into the project dir.\n- **ZIP-update**: admins can send a ZIP archive; the bot validates it\n (must contain `bot.py` at root or single top-level subdir), extracts code\n files, preserves `.env` and `venv/`, and keeps a rollback copy of the\n previous `bot.py`.\n- Sandbox logic tests: `test_sandbox.py` — 18/18 passed on 2026-09-10\n (run in `/tmp/mardisops_sandbox`, do not touch the live MardisBot dir).\n\n## systemd service\n- **Service Name**: `mardisops.service` — active (running), enabled\n- **Unit File**: `/etc/systemd/system/mardisops.service`\n- **Deployed**: v2 at 2026-09-10 07:32 UTC (restart verified)\n- **Hardening**: `PrivateTmp=true`, `ProtectSystem=full`,\n `ProtectHome=read-only`,\n `ReadWritePaths=/home/ubuntu/bots/MardisOpsBot /home/ubuntu/bots/MardisBot`\n (the MardisBot path is required for /backup and ZIP-update writes).\n- **Hardening note**: `NoNewPrivileges=true` was removed from the unit on\n 2026-09-10 07:12 UTC — it blocked sudo inside the service\n (\"no new privileges\" error, rc=1 on /status). Do not re-add it while the\n bot relies on sudo for systemctl/journalctl.\n\n## sudoers grant\n- `/etc/sudoers.d/99-mardisops-sudoers` (root:root, 0440, `visudo -c` OK,\n updated 2026-09-10 07:32 UTC) allows user `ubuntu` NOPASSWD for:\n `systemctl status/is-active/is-enabled/show mardisbot.service`,\n `systemctl restart/stop/start mardisbot.service`, and\n `journalctl -u mardisbot.service *`.\n\n## Access model\n- First 3 Telegram users who send `/start` become admins; user_ids are\n persisted in `/home/ubuntu/bots/MardisOpsBot/admins.json` (survives\n restarts). Everyone else is silently ignored.\n- As of 2026-09-10 07:32 UTC one admin is enrolled: user_id 78389352.\n\n## Service management\n```bash\nsudo systemctl status mardisops.service\nsudo journalctl -u mardisops.service -f\nsudo systemctl restart mardisops.service\n```\n\n## Startup log (verified 2026-09-10 07:32 UTC)\n- `ops bot starting; admins=[78389352] (max 3)`\n- `polling started`" + }, + "status": "applied", + "created_at": "2026-09-10T07:32:39Z", + "updated_at": "2026-09-10T07:32:41Z", + "applied_at": "2026-09-10T07:32:41Z", + "validation": { + "status": "ok", + "issue_count": 0, + "issues": [] + } +}