cd ../articles

System Security BTS SIO labs

Building a real web infrastructure: my first Proxmox project

Apache and PHP in one container, MariaDB in another, a firewall, hardened SSH, fail2ban and a chrooted SFTP drop for the developers. The GSB lab, and every mistake I made on it.

  • Apache
  • PHP-FPM
  • MariaDB
  • UFW
  • fail2ban

My first real Proxmox project, as a first-year BTS SIO SISR student: build and secure the infrastructure for a web application, so the developers on the SLAM side have somewhere to deploy. Two containers, a firewall, hardened SSH and an SFTP drop. And a long list of mistakes.

The brief

GSB (Galaxy Swiss Bourdin) is the fictional pharmaceutical company every French BTS SIO student meets sooner or later. It needs an application to manage its staff's expense claims. SLAM students write the PHP; SISR students, me, build and secure what it runs on.

  • Web container: Debian, Apache, PHP
  • Database container: Ubuntu, MariaDB
  • Network: the two must talk, nothing else should
  • Security: firewall, SSH hardening, intrusion prevention
  • Access: developers deploy their code over SFTP
  • Documentation: everything reproducible

Architecture

lamp.svg
The GSB lab: two containers behind the Proxmox host
The GSB lab: two containers behind the Proxmox host
Text version
                 school network (vmbr0)
                        │
              ┌─────────┴─────────┐
              │   Proxmox host    │
              └─────────┬─────────┘
                        │ vmbr1 · internal
          ┌─────────────┴─────────────┐
          ▼                           ▼
  gsb-web  192.168.1.10        gsb-db  192.168.1.11
  Debian · Apache · PHP-FPM    Ubuntu 22.04 · MariaDB
  :80 HTTP  :22 SSH/SFTP  ───▶ :3306 (from gsb-web only)
2LXC containers
~72 hof work, documentation included
4mistakes worth a section

Phase 1: containers

Both created from the Proxmox UI: 2 cores, 2 GB of RAM, 20 GB (web) and 30 GB (database) of disk, on the internal bridge. Then the same baseline on both:

apt update && apt upgrade -y
hostnamectl set-hostname gsb-web        # gsb-db on the other one
timedatectl set-timezone Europe/Paris
apt install -y sudo vim curl

Phase 2: the web server

Apache hands PHP to PHP-FPM through proxy_fcgi, instead of the old mod_php. It is faster and runs PHP as its own pool.

apt install -y apache2 php-fpm php-mysql php-xml php-mbstring
a2enmod proxy_fcgi setenvif rewrite headers
a2enconf php*-fpm          # matches the installed version, e.g. php8.2-fpm
systemctl restart apache2
php -v
/etc/apache2/sites-available/gsb.conf
<VirtualHost *:80>
    ServerName gsb.lan
    DocumentRoot /var/www/gsb/public

    <Directory /var/www/gsb/public>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog  ${APACHE_LOG_DIR}/gsb_error.log
    CustomLog ${APACHE_LOG_DIR}/gsb_access.log combined
</VirtualHost>
a2ensite gsb.conf && a2dissite 000-default.conf
systemctl reload apache2

-Indexes stops Apache from listing directory contents, a classic information leak.

Phase 3: the database

apt install -y mariadb-server
mysql_secure_installation   # root password, no anonymous users, no remote root, no test DB

Database and application user. The user may only connect from the web container's address, not from anywhere:

CREATE DATABASE gsb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'gsb_app'@'192.168.1.10' IDENTIFIED BY '<long random password>';
GRANT SELECT, INSERT, UPDATE, DELETE ON gsb.* TO 'gsb_app'@'192.168.1.10';
FLUSH PRIVILEGES;

MariaDB listens on localhost by default. In /etc/mysql/mariadb.conf.d/50-server.cnf, bind it to the internal interface only:

bind-address = 192.168.1.11

Test from the web container:

apt install -y mariadb-client
mysql -h 192.168.1.11 -u gsb_app -p gsb

Phase 4: security

Firewall (UFW)

# gsb-web: SSH and HTTP
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw enable

# gsb-db: SSH, and MariaDB from the web container only
ufw default deny incoming
ufw allow 22/tcp
ufw allow from 192.168.1.10 to any port 3306 proto tcp
ufw enable

SSH hardening

/etc/ssh/sshd_config.d/10-hardening.conf
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no      # once every admin key is in place
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
X11Forwarding no
AllowUsers admin slamdev
sshd -t && systemctl restart ssh    # -t validates the config first

fail2ban

fail2ban watches the logs and bans an IP after repeated failures.

/etc/fail2ban/jail.local
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 3

[sshd]
enabled = true
backend = systemd
systemctl enable --now fail2ban
fail2ban-client status sshd

On Debian 12 and later, SSH logs go to the journal, not /var/log/auth.log, hence backend = systemd.

Phase 5: SFTP for the developers

The SLAM team uploads code with SFTP, jailed in the web directory with no shell access.

groupadd sftpdev
useradd -m -g sftpdev -s /usr/sbin/nologin slamdev
passwd slamdev

# the chroot root must be owned by root and not writable by others
chown root:root /var/www/gsb && chmod 755 /var/www/gsb
mkdir -p /var/www/gsb/public
chown slamdev:www-data /var/www/gsb/public && chmod 2775 /var/www/gsb/public
/etc/ssh/sshd_config.d/20-sftp.conf
Match Group sftpdev
    ChrootDirectory /var/www/gsb
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no
    PasswordAuthentication yes
sftp slamdev@192.168.1.10
sftp> cd public
sftp> put -r app/

Testing

TestExpectedResult
Apache serves PHPpage renders, clean error logOK
Web → DB on 3306connects as gsb_appOK
Other host → DB on 3306refused by UFWOK
3 bad SSH passwordsIP banned by fail2banOK
SFTP as slamdevsees only /public, no shellOK

Mistakes I made

UFW before the SSH rule

Locked out. Recovered through the Proxmox console, then added the rule first.

MariaDB only listening on localhost

The web container could not connect. Fixed with bind-address on the internal IP, not 0.0.0.0.

Wrong permissions on the web root

Apache could not read the files. Group www-data plus the setgid bit on public/ fixed it for good.

Untested chroot

My first SFTP user could browse the whole filesystem. A chroot only works if its root is owned by root and not group-writable; sshd refuses it otherwise, and checks that rule on every path component.

What I took away

Separate the tiers

Web and database apart means one compromised layer does not give you the other for free.

Defaults are not secure

Every open port and every wildcard grant is a decision. Make it on purpose.

Logs first

Apache, journal and MariaDB logs answered every "why does it not work".

Write it down

The notes from this lab became the template for every later write-up on this site.

What I would add next

HTTPS on the virtual host, scheduled database dumps with a tested restore, monitoring, and a deployment pipeline instead of SFTP. A year later I built all four for NexiCloud.