Security NexiCloud
NexiCloud, part 3: auditing and hardening the platform
An nmap and lynis audit turned up an open DNS resolver, a database reachable from everywhere and Grafana on admin/admin. Here is what I fixed, how I verified it, and what is left.
- nmap
- lynis
- nftables
- fail2ban
- TLS
The brief asked for an "intrusion attempt" and a written report. I treated it as a real audit: scan everything, check configurations with a tool rather than by eye, fix what I found, then scan again to prove the fixes. Thirteen findings, two of them critical.
Part 3 of 3. Part 1: architecture. Part 2: CI/CD, Ansible, monitoring, backups.
Method
| Tool | Command | Target |
|---|---|---|
| nmap | nmap -sT -T4 --open -p- 172.16.1.10-27 | Every TCP port of the 18 containers |
| lynis | lynis audit system --quick, through audit.yml | lb, shop-nginx, shop-php, db-master, gitea, ansible |
| Manual | curl, dig, </dev/tcp/IP/port | Sensitive files, DNS recursion, segmentation |
| Load / DDoS | siege, ab, parallel curl | The HAProxy front end |
All of it from CT 303, the admin container, as an attacker already inside the network would see things. That is the harder case: perimeter firewalls do not help there.
Findings and fixes
| # | Severity | Finding | Fix | Verified by |
|---|---|---|---|---|
| 1 | Critical | MariaDB (3306) reachable from every container | Per-container nftables: 3306 only from shop-php, phpMyAdmin, replica, backup, admin | pct exec 301 -- bash -c '</dev/tcp/172.16.1.20/3306' → refused |
| 2 | Critical | bind9 was an open resolver (allow-recursion { any; }) | Recursion for internal networks only, version hidden, transfers to dns2 only | dig from outside the ACL → refused |
| 3 | High | Grafana on admin/admin | Random password, stored outside Git | curl -u admin:admin → 401 |
| 4 | High | phpMyAdmin reachable from the whole network | Port 80 on 309 limited to the host (VPN) and the admin container | From web1 → refused |
| 5 | High | Vulnerable packages on every container (lynis PKGS-7392) | dist-upgrade through Ansible + unattended-upgrades | Warning gone |
| 6 | Medium | PHP-FPM (9000) open to the subnet | 9000 from shop-nginx only, plus listen.allowed_clients | nmap |
| 7 | Medium | Shop served over plain HTTP | TLS 1.2+ on HAProxy, 301 to HTTPS, HSTS | curl -I http://boutique… → 301 |
| 8 | Medium | No protection against HTTP floods | Rate limit + fail2ban ban (below) | DDoS demo |
| 9 | Medium | Random port open on the CI runner (cache server) | Cache disabled | nmap |
| 10 | Medium | wp-config.php, readme.html, .git potentially served | nginx deny rules, no PHP execution in uploads/ | wp-config.php → 403 |
| 11 | Low | SMTP banner revealing the OS (MAIL-8818) | smtpd_banner = $myhostname ESMTP | Warning gone |
| 12 | Low | Single DNS server (NETW-2705) | Secondary DNS (CT 317), two nameservers everywhere | Primary stopped → still resolves |
| 13 | Low | Root SSH with password possible | Keys only, MaxAuthTries 3, fail2ban sshd everywhere | sshd -T |
Segmentation: a flow matrix, enforced per container
Finding #1 was the important one. The containers sat on one flat subnet and trusted each other completely. Rather than a big perimeter firewall, every container got its own nftables ruleset, default drop, generated by Ansible from a single description of who may talk to whom.
table inet nexicloud {
chain input {
type filter hook input priority 0; policy drop;
iif lo accept
ct state established,related accept
ct state invalid drop
meta l4proto { icmp, ipv6-icmp } accept
tcp dport 22 ip saddr { {{ net_admin | join(', ') }} } accept # host + admin CT
tcp dport 9100 ip saddr {{ ip_supervision }} accept # Prometheus only
{% for r in fw_rules | default([]) %}
{{ r.proto }} dport { {{ r.port }} } ip saddr { {{ r.from | join(', ') }} } accept
{% endfor %}
limit rate 5/minute log prefix "nexi-fw-drop: " level info
}
}The resulting exposure, verified by the second nmap run:
| Container | Open ports | Reachable from |
|---|---|---|
| lb | 80, 443 | Everyone (the only public entry, via host DNAT) |
| lb | 8404, 8405 | Private networks / monitoring |
| web1–3 | 80 | lb, CI runner, monitoring, admin |
| shop-php | 9000 | shop-nginx |
| db-master | 3306 | shop-php, phpMyAdmin, replica, admin |
| db-slave | 3306 | phpMyAdmin, backup, admin |
| registry | 5000 | CI runner, staging, admin |
| all | 22 | Host and admin container, keys only |
| all | 9100 | Monitoring only |
Anti-DDoS at the front door
HAProxy counts requests per source IP over a sliding 10-second window:
acl whitelist src {{ frontal_whitelist | join(' ') }}
stick-table type ip size 100k expire 60s store http_req_rate(10s),conn_cur
http-request track-sc0 src unless whitelist
http-request deny deny_status 429 if { sc_http_req_rate(0) gt 200 } !whitelist
tcp-request connection reject if { src_conn_cur ge 50 } !whitelistMore than 200 requests in 10 seconds gets 429 Too Many Requests; more than 50 simultaneous connections is rejected outright. A fail2ban jail reads the HAProxy log, and an IP that keeps hitting the limit is banned for ten minutes in nftables, so it no longer even reaches HAProxy.
# from a client: 600 requests, 30 in parallel
seq 600 | xargs -P30 -I{} curl -s -o /dev/null -w "%{http_code}\n" http://www.nexicloud.sio:8080/ | sort | uniq -c
# 200 200
# 400 429
pct exec 304 -- fail2ban-client status haproxy-ddos # the client IP is listed as banned
TLS without a public domain
nexicloud.sio is a fictional TLD, so Let's Encrypt is impossible. I created a small internal CA ("NexiCloud Root CA") with OpenSSL, issued a certificate for the site and the shop with proper subjectAltNames, and imported the root into the demo browser. HAProxy enforces TLS 1.2 minimum, disables session tickets and adds HSTS on the shop. In production it would be the same HAProxy with certbot.
lynis, before and after
The index barely moves, and that is fine: lynis weighs many small items (separate /tmp partition, auditd, legal banners). The warnings, the things that matter, went to zero, and the real wins (segmentation, the resolver, default credentials) are not things lynis scores at all. A tool's number is evidence, not the goal.
GDPR, briefly
The shops process personal data (names, addresses, order history), and NexiCloud is their processor under article 28. The report maps each relevant article to something concrete on the platform:
| Article | Requirement | On the platform |
|---|---|---|
| 5-1-f | Integrity and confidentiality | Per-container firewall, HTTPS + HSTS, SSH keys, fail2ban |
| 5-1-e | Storage limitation | Daily backups kept 7 days, weekly snapshots 2 versions |
| 25 | Data protection by design | Zones, secrets out of Git, least-privilege backup and deploy users |
| 32 | Security, including restore and regular testing | Replication, tested restores, automated acceptance, audit |
| 33–34 | Breach notification within 72 h | Alerts and logs (HAProxy, fail2ban, nftables) to date and scope an incident |
What is still open
- Let's Encrypt certificates in production, with automatic renewal.
- Two HAProxy nodes with keepalived, so the front door is not a single point of failure.
- Encrypted, off-site backups (3-2-1).
- auditd and centralised logs, for traceability.
- TLS on MariaDB replication and on PHP → database connections if they ever cross an untrusted network.
- Two-factor authentication on Gitea, Grafana and wp-admin.
What the audit taught me
The two critical findings were not exotic. A database listening on the whole subnet and a DNS server answering everyone are defaults that nobody had questioned. Scanning from the inside, writing down every finding with the command that proves it fixed, and scanning again: that loop is what I take from this project into any infrastructure I touch.