cd ../articles

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

ToolCommandTarget
nmapnmap -sT -T4 --open -p- 172.16.1.10-27Every TCP port of the 18 containers
lynislynis audit system --quick, through audit.ymllb, shop-nginx, shop-php, db-master, gitea, ansible
Manualcurl, dig, </dev/tcp/IP/portSensitive files, DNS recursion, segmentation
Load / DDoSsiege, ab, parallel curlThe 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

nexicloud-security.svg
The audit: method and findings
The audit: method and findings
#SeverityFindingFixVerified by
1CriticalMariaDB (3306) reachable from every containerPer-container nftables: 3306 only from shop-php, phpMyAdmin, replica, backup, adminpct exec 301 -- bash -c '</dev/tcp/172.16.1.20/3306' → refused
2Criticalbind9 was an open resolver (allow-recursion { any; })Recursion for internal networks only, version hidden, transfers to dns2 onlydig from outside the ACL → refused
3HighGrafana on admin/adminRandom password, stored outside Gitcurl -u admin:admin → 401
4HighphpMyAdmin reachable from the whole networkPort 80 on 309 limited to the host (VPN) and the admin containerFrom web1 → refused
5HighVulnerable packages on every container (lynis PKGS-7392)dist-upgrade through Ansible + unattended-upgradesWarning gone
6MediumPHP-FPM (9000) open to the subnet9000 from shop-nginx only, plus listen.allowed_clientsnmap
7MediumShop served over plain HTTPTLS 1.2+ on HAProxy, 301 to HTTPS, HSTScurl -I http://boutique… → 301
8MediumNo protection against HTTP floodsRate limit + fail2ban ban (below)DDoS demo
9MediumRandom port open on the CI runner (cache server)Cache disablednmap
10Mediumwp-config.php, readme.html, .git potentially servednginx deny rules, no PHP execution in uploads/wp-config.php → 403
11LowSMTP banner revealing the OS (MAIL-8818)smtpd_banner = $myhostname ESMTPWarning gone
12LowSingle DNS server (NETW-2705)Secondary DNS (CT 317), two nameservers everywherePrimary stopped → still resolves
13LowRoot SSH with password possibleKeys only, MaxAuthTries 3, fail2ban sshd everywheresshd -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.

nftables-nexicloud.nft.j2 (excerpt)
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:

ContainerOpen portsReachable from
lb80, 443Everyone (the only public entry, via host DNAT)
lb8404, 8405Private networks / monitoring
web1–380lb, CI runner, monitoring, admin
shop-php9000shop-nginx
db-master3306shop-php, phpMyAdmin, replica, admin
db-slave3306phpMyAdmin, backup, admin
registry5000CI runner, staging, admin
all22Host and admin container, keys only
all9100Monitoring only

Anti-DDoS at the front door

HAProxy counts requests per source IP over a sliding 10-second window:

haproxy.cfg.j2 · fe_http
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 } !whitelist

More 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

66–68 → 67–70hardening index, 6 audited containers
3 → 0warnings per container
~45 → 41–45remaining suggestions

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:

ArticleRequirementOn the platform
5-1-fIntegrity and confidentialityPer-container firewall, HTTPS + HSTS, SSH keys, fail2ban
5-1-eStorage limitationDaily backups kept 7 days, weekly snapshots 2 versions
25Data protection by designZones, secrets out of Git, least-privilege backup and deploy users
32Security, including restore and regular testingReplication, tested restores, automated acceptance, audit
33–34Breach notification within 72 hAlerts and logs (HAProxy, fail2ban, nftables) to date and scope an incident

What is still open

  1. Let's Encrypt certificates in production, with automatic renewal.
  2. Two HAProxy nodes with keepalived, so the front door is not a single point of failure.
  3. Encrypted, off-site backups (3-2-1).
  4. auditd and centralised logs, for traceability.
  5. TLS on MariaDB replication and on PHP → database connections if they ever cross an untrusted network.
  6. 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.