feat(templates): migrate six cred emitters to native shape
Phase 2/3 of DEBT-039. Switches FTP, POP3, IMAP, SMTP, Redis, and
LDAP from the legacy `username=` + `password=` SD-block shape to the
universal credential shape (`principal=` + `secret_printable=` +
`secret_b64=`) the new Credential storage model expects.
Pattern is uniform across all six services:
_log("auth_attempt", username=u, principal=u, **encode_secret(pw))
Each service emits the canonical SD keys. The ingester's native-shape
branch (introduced in 2f47f67) now writes their cred attempts
directly without going through the legacy adapter. Once Phase 3
removes the adapter the contract becomes single-shape.
Per-service notes:
- POP3 / IMAP — `status="success"|"failed"` renamed to
`outcome="success"|"failure"` to match Credential.outcome's
vocabulary; the ingester reads outcome directly.
- SMTP — AUTH path migrated; in addition the existing mail_from
event now exposes a parsed `domain=` field alongside the original
`value=` so future "what domains do attackers spoof from" analytics
have an indexed field. Not stored in Credential — regular Log row.
- Redis — was silently dropped by the legacy adapter (no `username`
field). Native branch handles `principal=None` correctly. BONUS
FIX: the Redis 6+ ACL syntax `AUTH <user> <pw>` now captures the
ACL username as principal (was previously discarded).
- LDAP — was silently dropped by the legacy adapter (no `password`
recognition for the `bind` event). Now lands as
`principal=<dn>`. BONUS FIX.
Tests (tests/services/test_cred_emitters.py, 9 cases):
- per-service native-shape ingest path produces correct Credential
rows; outcome maps for POP3/IMAP; principal=None for legacy Redis
AUTH; principal=dn for LDAP.
- mail_from event does NOT trigger a credential write (it's a
Log-only observation, not auth).
- 0xff/NUL/ANSI bytes in passwords survive losslessly through
secret_b64 even when secret_printable is sanitized.
Phase 3 deletes the legacy adapter once all migrations land — the
adapter has no live emitters to handle anymore.
This commit is contained in:
@@ -12,7 +12,13 @@ Banner advertises Dovecot so nmap fingerprints correctly.
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from syslog_bridge import SEVERITY_WARNING, syslog_line, write_syslog_file, forward_syslog
|
||||
from syslog_bridge import (
|
||||
SEVERITY_WARNING,
|
||||
encode_secret,
|
||||
forward_syslog,
|
||||
syslog_line,
|
||||
write_syslog_file,
|
||||
)
|
||||
|
||||
NODE_NAME = os.environ.get("NODE_NAME", "mailserver")
|
||||
SERVICE_NAME = "imap"
|
||||
@@ -431,14 +437,15 @@ class IMAPProtocol(asyncio.Protocol):
|
||||
parts = args.split(None, 1)
|
||||
username = parts[0].strip('"') if parts else ""
|
||||
password = parts[1].strip('"') if len(parts) > 1 else ""
|
||||
_enc = encode_secret(password)
|
||||
if VALID_USERS.get(username) == password:
|
||||
self._state = "AUTHENTICATED"
|
||||
_log("auth", src=self._peer[0], username=username, password=password,
|
||||
status="success")
|
||||
_log("auth", src=self._peer[0], username=username, principal=username,
|
||||
outcome="success", **_enc)
|
||||
self._w(f"{tag} OK [CAPABILITY IMAP4rev1] Logged in\r\n")
|
||||
else:
|
||||
_log("auth", src=self._peer[0], username=username, password=password,
|
||||
status="failed", severity=SEVERITY_WARNING)
|
||||
_log("auth", src=self._peer[0], username=username, principal=username,
|
||||
outcome="failure", severity=SEVERITY_WARNING, **_enc)
|
||||
self._w(f"{tag} NO [AUTHENTICATIONFAILED] Authentication failed.\r\n")
|
||||
|
||||
def _cmd_list(self, tag: str, cmd: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user