agentbbs/scripts/set-irc-password.sh
Anthony Ettinger 25266845e0 irc: enforce per-member SASL passwords + irssi setup on landing page
Auth model change: ergo-auth-member now verifies the SASL passphrase against a
per-member pbkdf2 hash (/var/lib/ergo/irc-passwd) in addition to BBS membership,
replacing the old "membership is the credential, passphrase ignored" gate that
let anyone who knew a member name connect as them. Rewrote deploy/ergo/auth-script.sh
in python3 (drops jq/curl dep); setup.sh already installs it as ergo-auth-member.

- scripts/set-irc-password.sh: set/rotate a member's IRC password (or --all to
  backfill); also syncs The Lounge saslPassword so the web client keeps working.
- setup.sh landing page: new "IRC from a desktop client" section with irssi/HexChat/
  WeeChat SASL setup (connect by network name ProfullstackBBS, not hostname).
- docs/irc.md: document password auth, the helper, the 6697 cloud-firewall note,
  and an irssi quick-start.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 14:11:29 +00:00

109 lines
3.5 KiB
Bash

#!/usr/bin/env python3
# set-irc-password.sh — set or rotate a member's AgentBBS IRC password.
#
# Writes a pbkdf2-sha256 hash to the Ergo password store
# (/var/lib/ergo/irc-passwd, ergo:ergo 0600) that ergo-auth-member verifies on
# SASL login, and (if a The Lounge user file exists for the member) updates that
# user's saslPassword so the web client keeps working without member action.
#
# Usage:
# set-irc-password.sh <member> [password] # password generated if omitted
# set-irc-password.sh --all # provision any member missing one
#
# Run as root on the BBS box. The member must already be a BBS member; this only
# sets the secret — membership itself is still gated by /irc-auth.
import sys, os, json, glob, secrets, hashlib, pwd, grp
PASSWD_FILE = os.environ.get("ERGO_IRC_PASSWD", "/var/lib/ergo/irc-passwd")
LOUNGE_USERS = os.environ.get("AGENTBBS_LOUNGE_USERS", "/var/lib/thelounge/users")
ITERS = 200_000
def hash_pw(pw):
salt = secrets.token_bytes(16)
dk = hashlib.pbkdf2_hmac("sha256", pw.encode(), salt, ITERS)
return f"pbkdf2_sha256${ITERS}${salt.hex()}${dk.hex()}"
def load_store():
store = {}
if os.path.exists(PASSWD_FILE):
for ln in open(PASSWD_FILE):
ln = ln.strip()
if ln and not ln.startswith("#"):
name, sep, h = ln.partition(":")
if sep:
store[name] = h
return store
def write_store(store):
uid = pwd.getpwnam("ergo").pw_uid
gid = grp.getgrnam("ergo").gr_gid
os.makedirs(os.path.dirname(PASSWD_FILE), exist_ok=True)
tmp = PASSWD_FILE + ".tmp"
with open(tmp, "w") as f:
f.write("# <account>:pbkdf2_sha256$<iterations>$<salt_hex>$<hash_hex>\n")
for name in sorted(store):
f.write(f"{name}:{store[name]}\n")
os.chmod(tmp, 0o600)
os.chown(tmp, uid, gid)
os.replace(tmp, PASSWD_FILE)
def sync_lounge(member, pw):
p = os.path.join(LOUNGE_USERS, member + ".json")
if not os.path.exists(p):
return
try:
d = json.load(open(p))
except Exception as e:
print(f"WARN: could not update Lounge config for {member}: {e}", file=sys.stderr)
return
changed = False
for n in d.get("networks", []):
if "saslPassword" in n or n.get("saslAccount"):
n["saslPassword"] = pw
changed = True
if changed:
st = os.stat(p)
with open(p, "w") as f:
json.dump(d, f, indent=2)
os.chown(p, st.st_uid, st.st_gid)
os.chmod(p, 0o600)
print(f" (updated The Lounge saslPassword for {member}; restart thelounge to apply)")
def set_one(member, pw, store):
store[member] = hash_pw(pw)
sync_lounge(member, pw)
def main(argv):
if not argv:
print(__doc__.strip())
return 2
store = load_store()
if argv[0] == "--all":
members = sorted(os.path.basename(p)[:-5] for p in glob.glob(os.path.join(LOUNGE_USERS, "*.json")))
done = []
for m in members:
if m not in store:
pw = secrets.token_urlsafe(9)
set_one(m, pw, store)
done.append((m, pw))
write_store(store)
for m, pw in done:
print(f"{m}\t{pw}")
print(f"provisioned {len(done)} member(s) that were missing a password")
return 0
member = argv[0]
pw = argv[1] if len(argv) > 1 else secrets.token_urlsafe(9)
set_one(member, pw, store)
write_store(store)
print(f"{member}\t{pw}")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))