NetBox through Rollcall: the admin certificate signs in to NetBox
With ipam.ui_login_secret_file, the proxy tells NetBox who the admin is (X-Rollcall-User: the certificate's admin name) together with a shared secret (X-Rollcall-Proxy-Secret). NetBox takes the user from that header (REMOTE_AUTH) and creates it on first use; the web server in front of NetBox drops the header from any request that lacks the secret or does not come from the region, so reaching NetBox directly claims no one. Both headers coming from a browser are always dropped by Rollcall; an admin signed in with a token instead of a certificate logs in to NetBox by hand. A secret under 16 characters or an unreadable file leaves the proxy off, with a log line. The lab NetBox install sets it up: REMOTE_AUTH settings, a guarded Caddyfile (readable by caddy only: the secret is in it), the secret in secrets.env, and a rollcall-admins group that may do everything. Rollcall's NetBox user may now view cables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a613014073
commit
44ac453bde
7 files changed
+146
-20
No files matched your search
+28
-1
@@ -6,6 +6,11 @@
|
||||
# NetBox lives under /netbox/ (BASE_PATH) so the region can serve its UI
|
||||
# through Rollcall (cmd/rollcall/nbproxy.go): Rollcall's ipam url is then
|
||||
# http://$MYIP/netbox/, and ROLLCALL_ORIGINS are where browsers post from.
|
||||
# The admin certificate signs in to NetBox through that proxy: NetBox takes
|
||||
# the user from X-Rollcall-User (REMOTE_AUTH), and Caddy drops that header
|
||||
# unless the request comes from ROLLCALL_IP with ROLLCALL_UI_SECRET (copy it
|
||||
# to the region's ipam.ui_login_secret_file). Such users land in the group
|
||||
# rollcall-admins, which may do everything (a lab).
|
||||
#
|
||||
# Run as root inside the container; rerunnable. Secrets are generated here:
|
||||
# /etc/lab-netbox/secrets.env (admin password, Rollcall's API token)
|
||||
@@ -20,6 +25,7 @@ NETBOX_VERSION=${NETBOX_VERSION:-4.7.4}
|
||||
MYIP=${MYIP:-10.213.77.6}
|
||||
SITE=${SITE:-lab}
|
||||
ROLLCALL_ORIGINS=${ROLLCALL_ORIGINS:-"https://10.0.0.234 https://10.213.77.1"}
|
||||
ROLLCALL_IP=${ROLLCALL_IP:-10.213.77.1}
|
||||
PREFIXES=${PREFIXES:-"10.213.77.0/24 10.213.78.0/24 10.213.79.0/24 fd00:213:77::/64 fd00:213:78::/64"}
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -41,6 +47,7 @@ ROLLCALL_PASS=$(r 18)
|
||||
EOF
|
||||
chmod 600 $S
|
||||
fi
|
||||
grep -q '^ROLLCALL_UI_SECRET=' $S || echo "ROLLCALL_UI_SECRET=$(python3 -c 'import secrets;print(secrets.token_urlsafe(32))')" >> $S
|
||||
. $S
|
||||
|
||||
# ------------------------------------------------------------------ PostgreSQL, Valkey
|
||||
@@ -74,6 +81,11 @@ SECRET_KEY = '$NETBOX_SECRET_KEY'
|
||||
API_TOKEN_PEPPERS = {1: '$NETBOX_PEPPER'}
|
||||
TIME_ZONE = 'Europe/Stockholm'
|
||||
BASE_PATH = 'netbox/'
|
||||
REMOTE_AUTH_ENABLED = True
|
||||
REMOTE_AUTH_BACKEND = 'netbox.authentication.RemoteUserBackend'
|
||||
REMOTE_AUTH_HEADER = 'HTTP_X_ROLLCALL_USER'
|
||||
REMOTE_AUTH_AUTO_CREATE_USER = True
|
||||
REMOTE_AUTH_DEFAULT_GROUPS = ['rollcall-admins']
|
||||
CSRF_TRUSTED_ORIGINS = ['http://$MYIP'$(for o in $ROLLCALL_ORIGINS; do printf ", '%s'" "$o"; done)]
|
||||
EOF
|
||||
chown -R netbox:netbox $D/netbox/media $D/netbox/reports $D/netbox/scripts 2>/dev/null || true
|
||||
@@ -89,6 +101,13 @@ systemctl restart netbox netbox-rq
|
||||
cat > /etc/caddy/Caddyfile <<EOF
|
||||
# pxestuff lab/netbox/install.sh
|
||||
http://$MYIP, http://localhost {
|
||||
# who signs in comes only from Rollcall's proxy, with the shared secret
|
||||
@notrollcall not {
|
||||
remote_ip $ROLLCALL_IP
|
||||
header X-Rollcall-Proxy-Secret "$ROLLCALL_UI_SECRET"
|
||||
}
|
||||
request_header @notrollcall -X-Rollcall-User
|
||||
request_header -X-Rollcall-Proxy-Secret
|
||||
redir / /netbox/
|
||||
handle_path /netbox/static/* {
|
||||
root * /opt/netbox/netbox/static
|
||||
@@ -97,6 +116,7 @@ http://$MYIP, http://localhost {
|
||||
reverse_proxy 127.0.0.1:8001
|
||||
}
|
||||
EOF
|
||||
chmod 640 /etc/caddy/Caddyfile && chgrp caddy /etc/caddy/Caddyfile # the secret is in it
|
||||
systemctl enable caddy && systemctl restart caddy
|
||||
|
||||
# ------------------------------------------------------------------ what Rollcall needs
|
||||
@@ -128,13 +148,20 @@ perms = {
|
||||
"rollcall-read": (["ipam.prefix", "ipam.vlan", "ipam.iprange", "extras.tag", "dcim.site"], ["view"]),
|
||||
"rollcall-dcim-write": (["dcim.device", "dcim.interface", "dcim.macaddress"], ["view", "add", "change", "delete"]),
|
||||
"rollcall-dcim-types": (["dcim.manufacturer", "dcim.devicetype", "dcim.devicerole"], ["view", "add"]),
|
||||
"rollcall-dcim-read": (["dcim.location", "dcim.rack"], ["view"]),
|
||||
"rollcall-dcim-read": (["dcim.location", "dcim.rack", "dcim.cable"], ["view"]),
|
||||
}
|
||||
for name, (types, actions) in perms.items():
|
||||
p, _ = ObjectPermission.objects.get_or_create(name=name, defaults={"actions": actions})
|
||||
p.actions = actions; p.enabled = True; p.save()
|
||||
p.object_types.set([ContentType.objects.get_by_natural_key(*t.split(".")) for t in types])
|
||||
p.users.add(rc)
|
||||
from users.models import Group
|
||||
from django.apps import apps
|
||||
admins, _ = Group.objects.get_or_create(name="rollcall-admins") # who the admin certificate signs in
|
||||
p, _ = ObjectPermission.objects.get_or_create(name="rollcall-admins-all", defaults={"actions": ["view", "add", "change", "delete"]})
|
||||
p.actions = ["view", "add", "change", "delete"]; p.enabled = True; p.save()
|
||||
p.object_types.set([ContentType.objects.get_for_model(m) for a in ("dcim", "ipam", "circuits", "tenancy", "virtualization", "extras", "wireless", "vpn") for m in apps.get_app_config(a).get_models()])
|
||||
p.groups.add(admins)
|
||||
site, _ = Site.objects.get_or_create(slug=os.environ["NB_SITE"], defaults={"name": os.environ["NB_SITE"].capitalize()})
|
||||
for cidr in os.environ["NB_PREFIXES"].split():
|
||||
p, _ = Prefix.objects.get_or_create(prefix=cidr, defaults={"description": "Rollcall lab", "scope": site})
|
||||
|
||||
Reference in new issue
Block a user