Skip to content

How to build your own Debian package

Andreas Vögele edited this page Nov 30, 2024 · 3 revisions

Let's create a virtual machine with LXC, for example.

lxc-create -n test-nginx -t download -- -d debian -r bookworm -a amd64
lxc-start -n test-nginx
env LC_ALL=C lxc-attach -n test-nginx

Install the build dependencies.

apt install -y build-essential debhelper libmojolicious-perl libtemplate-perl wget

Get the source package.

wget -q --no-parent -r -nd -A .dsc,.diff.gz,.orig.tar.gz \
  --accept-regex nginx-auth-saslauthd \
  https://download.opensuse.org/repositories/home:/voegelas/Debian_12/

Build the package.

dpkg-source -x nginx-auth-saslauthd_*.dsc
cd nginx-auth-saslauthd-*
dpkg-buildpackage -rfakeroot -uc -us
cd ..

Install the created package and its runtime dependencies.

apt install -y libnss-systemd nginx sasl2-bin
echo START=yes | tee -a /etc/default/saslauthd
systemctl restart saslauthd.service
dpkg -i nginx-auth-saslauthd_*.deb

Edit /etc/nginx/sites-available/default. Delegate the authentication to the saslauthd daemon with auth_request.

location / {
    try_files $uri $uri/ =404;
    auth_request /auth;
}

location = /auth {
    internal;
    proxy_pass http://unix:/run/nginx-auth/saslauthd.sock:/auth-basic;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Realm "This is a test"; # Only ASCII characters are allowed
}

Reload the configuration.

nginx -t
nginx -s reload

Add a user and set the password to something that you can easily remember, for example "secret".

adduser testuser

Test the saslauthd daemon and nginx.

testsaslauthd -s nginx -u testuser -p 'secret'
wget -S -O - http://localhost/
wget -S -O - http://testuser:secret@localhost/

Don't forget to configure HTTPS on production.