Post

Install PowerDNS Admin on Debian

Install PowerDNS Admin on Debian

PowerDNS Admin is a web interface for managing your PowerDNS server.

Pre-required Installation

For PostgreSQL backend:

1
sudo apt install python3-psycopg2

Required packages for PowerDNS Admin:

1
sudo apt install -y python3-dev git libsasl2-dev libldap2-dev python3-venv libmariadb-dev

Install Node.js

This guide uses nvm.

Note: nvm requires curl:

1
sudo apt install curl
1
2
3
4
5
6
7
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

# Set up auto-completion
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Install Node.js:

1
2
3
nvm install 22
node -v   # should print v22.11.0
npm -v    # should print 10.9.0

Install yarn

1
2
3
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install -y yarn

Checkout Source Code and Create Virtual Environment

Note: Adjust /opt/web/powerdns-admin to your preferred application directory.

1
2
3
4
5
6
7
8
sudo su
git clone https://github.com/PowerDNS-Admin/PowerDNS-Admin.git /opt/web/powerdns-admin
cd /opt/web/powerdns-admin
python3 -mvenv ./venv

source ./venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

Finalize Configuration

Create the production config and update SECRET_KEY (generate a long random string):

1
2
3
cp /opt/web/powerdns-admin/configs/development.py /opt/web/powerdns-admin/configs/production.py
nano /opt/web/powerdns-admin/configs/production.py
export FLASK_CONF=../configs/production.py

Run DB migration and build assets:

1
2
3
4
5
6
export FLASK_APP=powerdnsadmin/__init__.py
flask db upgrade
flask db migrate -m "Init DB"
yarn install --pure-lockfile
flask assets build
deactivate

Setup systemd Service

Create /etc/systemd/system/powerdns-admin.service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Unit]
Description=PowerDNS-Admin
Requires=powerdns-admin.socket
After=network.target

[Service]
Environment="FLASK_CONF=../configs/production.py"
PIDFile=/run/powerdns-admin/pid
User=pdns
Group=pdns
WorkingDirectory=/opt/web/powerdns-admin
ExecStartPre=+mkdir -p /run/powerdns-admin/
ExecStartPre=+chown pdns:pdns -R /run/powerdns-admin/
ExecStart=/opt/web/powerdns-admin/venv/bin/gunicorn --pid /run/powerdns-admin/pid --bind unix:/run/powerdns-admin/socket 'powerdnsadmin:create_app()'
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Create /etc/systemd/system/powerdns-admin.socket:

1
2
3
4
5
6
7
8
[Unit]
Description=PowerDNS-Admin socket

[Socket]
ListenStream=/run/powerdns-admin/socket

[Install]
WantedBy=sockets.target

Create /etc/tmpfiles.d/powerdns-admin.conf:

1
d /run/powerdns-admin 0755 pdns pdns -

Set ownership:

1
2
sudo chown -R pdns: /run/powerdns-admin
sudo chown -R pdns: /opt/web/powerdns-admin

NGINX Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
server {
    listen 80 default_server;
    server_name "";
    return 301 https://$http_host$request_uri;
}

server {
    listen 443 ssl http2 default_server;
    server_name _;
    error_log /var/log/nginx/error_powerdnsadmin.log error;
    access_log off;

    ssl_certificate path_to_your_fullchain_or_cert;
    ssl_certificate_key path_to_your_key;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_session_cache shared:SSL:10m;

    client_max_body_size 10m;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    location ~ ^/static/ {
        include mime.types;
        root /opt/web/powerdns-admin/powerdnsadmin;
    }

    location / {
        proxy_pass http://unix:/run/powerdns-admin/socket;
        proxy_read_timeout 120;
        proxy_connect_timeout 120;
        proxy_redirect http:// $scheme://;
    }
}

References

This post is licensed under CC BY 4.0 by the author.