Replace dead upstream images with custom build services; add retry logic
dtagdevsec/mailoney and dtagdevsec/elasticpot are unavailable on Docker Hub
("manifest unknown"), causing the entire deployment to abort and cascade-
interrupt all other image pulls.
- Convert smtp and elasticsearch to build services with custom Python
honeypots: smtp emulates Postfix ESMTP (EHLO/AUTH/MAIL/RCPT logging),
elasticsearch emulates ES 7.17 HTTP API (logs recon probes like /_cat/,
/_cluster/, /_nodes/, /_security/)
- Both use ARG BASE_IMAGE so they participate in per-decky distro variation
- Add _compose_with_retry() to deployer: 3 attempts with exponential backoff
(5s → 10s → 20s) for transient network failures; permanent errors
("manifest unknown", "pull access denied") are detected and not retried
- Update test_services.py and test_composer.py: smtp/elasticsearch moved
from UPSTREAM_SERVICES to BUILD_SERVICES (314 tests passing)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
13
templates/smtp/Dockerfile
Normal file
13
templates/smtp/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
ARG BASE_IMAGE=debian:bookworm-slim
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
python3 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY smtp_honeypot.py /opt/smtp_honeypot.py
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
EXPOSE 25 587
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
3
templates/smtp/entrypoint.sh
Normal file
3
templates/smtp/entrypoint.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
exec python3 /opt/smtp_honeypot.py
|
||||
117
templates/smtp/smtp_honeypot.py
Normal file
117
templates/smtp/smtp_honeypot.py
Normal file
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
SMTP honeypot — emulates a realistic ESMTP server (Postfix-style).
|
||||
Logs EHLO/AUTH/MAIL FROM/RCPT TO attempts as JSON, then denies auth.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from datetime import datetime, timezone
|
||||
|
||||
HONEYPOT_NAME = os.environ.get("HONEYPOT_NAME", "mailserver")
|
||||
LOG_TARGET = os.environ.get("LOG_TARGET", "")
|
||||
|
||||
|
||||
def _forward(event: dict) -> None:
|
||||
if not LOG_TARGET:
|
||||
return
|
||||
try:
|
||||
host, port = LOG_TARGET.rsplit(":", 1)
|
||||
with socket.create_connection((host, int(port)), timeout=3) as s:
|
||||
s.sendall((json.dumps(event) + "\n").encode())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _log(event_type: str, **kwargs) -> None:
|
||||
event = {
|
||||
"ts": datetime.now(timezone.utc).isoformat(),
|
||||
"service": "smtp",
|
||||
"host": HONEYPOT_NAME,
|
||||
"event": event_type,
|
||||
**kwargs,
|
||||
}
|
||||
print(json.dumps(event), flush=True)
|
||||
_forward(event)
|
||||
|
||||
|
||||
class SMTPProtocol(asyncio.Protocol):
|
||||
def __init__(self):
|
||||
self._transport = None
|
||||
self._peer = ("?", 0)
|
||||
self._buf = b""
|
||||
|
||||
def connection_made(self, transport):
|
||||
self._transport = transport
|
||||
self._peer = transport.get_extra_info("peername", ("?", 0))
|
||||
_log("connect", src=self._peer[0], src_port=self._peer[1])
|
||||
transport.write(f"220 {HONEYPOT_NAME} ESMTP Postfix (Debian/GNU)\r\n".encode())
|
||||
|
||||
def data_received(self, data):
|
||||
self._buf += data
|
||||
while b"\r\n" in self._buf:
|
||||
line, self._buf = self._buf.split(b"\r\n", 1)
|
||||
self._handle_line(line.decode(errors="replace").strip())
|
||||
|
||||
def _handle_line(self, line: str) -> None:
|
||||
cmd = line.split()[0].upper() if line.split() else ""
|
||||
|
||||
if cmd in ("EHLO", "HELO"):
|
||||
domain = line.split(None, 1)[1] if " " in line else ""
|
||||
_log("ehlo", src=self._peer[0], domain=domain)
|
||||
self._transport.write(
|
||||
f"250-{HONEYPOT_NAME}\r\n"
|
||||
f"250-PIPELINING\r\n"
|
||||
f"250-SIZE 10240000\r\n"
|
||||
f"250-VRFY\r\n"
|
||||
f"250-ETRN\r\n"
|
||||
f"250-AUTH PLAIN LOGIN\r\n"
|
||||
f"250-ENHANCEDSTATUSCODES\r\n"
|
||||
f"250-8BITMIME\r\n"
|
||||
f"250 DSN\r\n".encode()
|
||||
)
|
||||
elif cmd == "AUTH":
|
||||
_log("auth_attempt", src=self._peer[0], command=line)
|
||||
self._transport.write(b"535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6\r\n")
|
||||
self._transport.close()
|
||||
elif cmd == "MAIL":
|
||||
_log("mail_from", src=self._peer[0], value=line)
|
||||
self._transport.write(b"250 2.1.0 Ok\r\n")
|
||||
elif cmd == "RCPT":
|
||||
_log("rcpt_to", src=self._peer[0], value=line)
|
||||
self._transport.write(b"250 2.1.5 Ok\r\n")
|
||||
elif cmd == "DATA":
|
||||
self._transport.write(b"354 End data with <CR><LF>.<CR><LF>\r\n")
|
||||
elif cmd == "VRFY":
|
||||
_log("vrfy", src=self._peer[0], value=line)
|
||||
self._transport.write(b"252 2.0.0 Cannot VRFY user\r\n")
|
||||
elif cmd == "QUIT":
|
||||
self._transport.write(b"221 2.0.0 Bye\r\n")
|
||||
self._transport.close()
|
||||
elif cmd == "NOOP":
|
||||
self._transport.write(b"250 2.0.0 Ok\r\n")
|
||||
elif cmd == "RSET":
|
||||
self._transport.write(b"250 2.0.0 Ok\r\n")
|
||||
elif cmd == "STARTTLS":
|
||||
# Pretend we don't support upgrading mid-session
|
||||
self._transport.write(b"454 4.7.0 TLS not available due to local problem\r\n")
|
||||
else:
|
||||
_log("unknown_command", src=self._peer[0], command=line)
|
||||
self._transport.write(b"502 5.5.2 Error: command not recognized\r\n")
|
||||
|
||||
def connection_lost(self, exc):
|
||||
_log("disconnect", src=self._peer[0] if self._peer else "?")
|
||||
|
||||
|
||||
async def main():
|
||||
_log("startup", msg=f"SMTP honeypot starting as {HONEYPOT_NAME}")
|
||||
loop = asyncio.get_running_loop()
|
||||
server = await loop.create_server(SMTPProtocol, "0.0.0.0", 25)
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user