feat(vault01/radius): ask dgsi for vlan id
All checks were successful
Check meta / check_dns (pull_request) Successful in 17s
Check workflows / check_workflows (push) Successful in 18s
Check meta / check_meta (pull_request) Successful in 18s
Check workflows / check_workflows (pull_request) Successful in 18s
Build all the nodes / netcore00 (pull_request) Successful in 26s
Build all the nodes / netaccess01 (pull_request) Successful in 28s
Run pre-commit on all files / pre-commit (pull_request) Successful in 34s
Build all the nodes / ap01 (pull_request) Successful in 42s
Build all the nodes / netcore01 (pull_request) Successful in 25s
Build all the nodes / netcore02 (pull_request) Successful in 25s
Build all the nodes / bridge01 (pull_request) Successful in 59s
Build all the nodes / geo01 (pull_request) Successful in 1m9s
Build all the nodes / geo02 (pull_request) Successful in 1m13s
Build all the nodes / cof02 (pull_request) Successful in 1m16s
Build all the nodes / hypervisor02 (pull_request) Successful in 1m18s
Build all the nodes / hypervisor03 (pull_request) Successful in 1m21s
Build all the nodes / hypervisor01 (pull_request) Successful in 1m22s
Build all the nodes / lab-router01 (pull_request) Successful in 1m22s
Build all the nodes / build01 (pull_request) Successful in 1m24s
Build all the nodes / iso (pull_request) Successful in 1m24s
Build all the nodes / tower01 (pull_request) Successful in 1m4s
Build the shell / build-shell (pull_request) Successful in 33s
Build all the nodes / compute01 (pull_request) Successful in 1m44s
Build all the nodes / rescue01 (pull_request) Successful in 1m27s
Build all the nodes / web02 (pull_request) Successful in 1m5s
Build all the nodes / krz01 (pull_request) Successful in 1m55s
Build all the nodes / vault01 (pull_request) Successful in 1m22s
Build all the nodes / web03 (pull_request) Successful in 1m10s
Build all the nodes / storage01 (pull_request) Successful in 1m44s
Build all the nodes / web01 (pull_request) Successful in 1m32s
Build all the nodes / netcore00 (push) Successful in 31s
Build all the nodes / netaccess01 (push) Successful in 31s
Build all the nodes / netcore01 (push) Successful in 31s
Build all the nodes / netcore02 (push) Successful in 31s
Run pre-commit on all files / pre-commit (push) Successful in 34s
Build all the nodes / ap01 (push) Successful in 45s
Build the shell / build-shell (push) Successful in 26s
Build all the nodes / bridge01 (push) Successful in 1m2s
Build all the nodes / geo02 (push) Successful in 1m17s
Build all the nodes / hypervisor01 (push) Successful in 1m20s
Build all the nodes / cof02 (push) Successful in 1m24s
Build all the nodes / geo01 (push) Successful in 1m27s
Build all the nodes / hypervisor02 (push) Successful in 1m26s
Build all the nodes / lab-router01 (push) Successful in 1m27s
Build all the nodes / build01 (push) Successful in 1m33s
Build all the nodes / hypervisor03 (push) Successful in 1m33s
Build all the nodes / tower01 (push) Successful in 1m34s
Build all the nodes / iso (push) Successful in 1m47s
Build all the nodes / vault01 (push) Successful in 1m56s
Build all the nodes / compute01 (push) Successful in 1m58s
Build all the nodes / rescue01 (push) Successful in 1m57s
Build all the nodes / web02 (push) Successful in 1m30s
Build all the nodes / web03 (push) Successful in 1m32s
Build all the nodes / web01 (push) Successful in 2m2s
Build all the nodes / storage01 (push) Successful in 2m3s
Build all the nodes / krz01 (push) Successful in 2m7s

This commit is contained in:
catvayor 2025-03-12 14:48:23 +01:00
parent 025cc2b56a
commit 7c9f73e921
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
10 changed files with 105 additions and 27 deletions

View file

@ -39,17 +39,11 @@
# before they can authenticate via RADIUS.
radius_required_groups = [ "radius_access@sso.dgnum.eu" ];
# A mapping between Kanidm groups and VLANS
radius_groups = map (
{ vlan, ... }:
{
inherit vlan;
spn = "vlan_${toString vlan}@sso.dgnum.eu";
}
) config.networking.vlans-info;
dgsi_endpoint = "https://profil.dgnum.eu/api/user/";
};
authTokenFile = config.age.secrets."radius-auth_token_file".path;
dgsiTokenFile = config.age.secrets."radius-dgsi_token_file".path;
};
age-secrets.autoMatch = [ "radius" ];

View file

@ -75,6 +75,11 @@ in
description = "File to the auth token for the service account.";
};
dgsiTokenFile = mkOption {
type = path;
description = "File to the token for DGSI.";
};
extra-mods = mkOption {
type = attrsOf path;
default = { };
@ -188,6 +193,7 @@ in
# Copy the kanidm configuration
cat <<EOF > /var/lib/radius/kanidm.toml
auth_token = "$(cat "${cfg.authTokenFile}")"
dgsi_token = "$(cat "${cfg.dgsiTokenFile}")"
EOF
cat ${settingsFormat.generate "kanidm.toml" cfg.settings} >> /var/lib/radius/kanidm.toml

View file

@ -1,16 +0,0 @@
diff --git a/kanidm/radius/utils.py b/kanidm/radius/utils.py
index cbd3fe1f0..41fbd05c4 100644
--- a/kanidm/radius/utils.py
+++ b/kanidm/radius/utils.py
@@ -25,11 +25,6 @@ def check_vlan(
raise ValueError("Need to pass this a kanidm_client")
for radius_group in kanidm_client.config.radius_groups:
- logging.debug(
- "Checking vlan group '%s' against user group %s",
- radius_group.spn,
- group.spn,
- )
if radius_group.spn == group.spn:
logging.info("returning new vlan: %s", radius_group.vlan)
return radius_group.vlan

View file

@ -0,0 +1,89 @@
diff --git a/pykanidm/kanidm/radius/__init__.py b/pykanidm/kanidm/radius/__init__.py
index e707cf602..167d8e006 100644
--- a/kanidm/radius/__init__.py
+++ b/kanidm/radius/__init__.py
@@ -8,6 +8,7 @@ import logging
import os
from pathlib import Path
import sys
+import requests
from typing import Any, Dict, Optional, Union
from kanidm.exceptions import NoMatchingEntries
@@ -15,7 +16,6 @@ from kanidm.types import AuthState, RadiusTokenResponse
from .. import KanidmClient
from . import radiusd
-from .utils import check_vlan
CONTAINER_CONFIG_FILE_PATH = "/data/radius.toml"
@@ -147,13 +147,15 @@ def authorize(
logging.info("User %s doesn't have a group from the required list.", name)
return radiusd.RLM_MODULE_REJECT
- # look up them in config for group vlan if possible.
- # TODO: work out the typing on this, WTF.
- uservlan: int = reduce(
- check_vlan,
- tok.groups,
- kanidm_client.config.radius_default_vlan,
- )
+ dgsi_info = requests.get(kanidm_client.config.dgsi_endpoint + "/" + name, headers={
+ "Authorization": "Token " + kanidm_client.config.dgsi_token
+ })
+ if dgsi_info.status != 200:
+ logging.error("dgsi: error getting vlan of %s : %s.", name, dgsi_info.status)
+ return radiusd.RLM_MODULE_FAIL
+
+ uservlan: int = dgsi_info.json().get("vlan_id", default=kanidm_client.config.radius_default_vlan);
+
if uservlan == int(0):
logging.info("Invalid uservlan of 0")
diff --git a/pykanidm/kanidm/radius/utils.py b/pykanidm/kanidm/radius/utils.py
deleted file mode 100644
index cbd3fe1f0..000000000
--- a/kanidm/radius/utils.py
+++ /dev/null
@@ -1,37 +0,0 @@
-""" class utils """
-
-from typing import Optional
-import logging
-import os
-
-from .. import KanidmClient
-from ..types import RadiusTokenGroup
-
-
-def check_vlan(
- acc: int,
- group: RadiusTokenGroup,
- kanidm_client: Optional[KanidmClient] = None,
-) -> int:
- """checks if a vlan is in the config,
-
- acc is the default vlan
- """
- logging.debug("acc=%s", acc)
- if kanidm_client is None:
- if "KANIDM_CONFIG_FILE" in os.environ:
- kanidm_client = KanidmClient(config_file=os.environ["KANIDM_CONFIG_FILE"])
- else:
- raise ValueError("Need to pass this a kanidm_client")
-
- for radius_group in kanidm_client.config.radius_groups:
- logging.debug(
- "Checking vlan group '%s' against user group %s",
- radius_group.spn,
- group.spn,
- )
- if radius_group.spn == group.spn:
- logging.info("returning new vlan: %s", radius_group.vlan)
- return radius_group.vlan
- logging.debug("returning already set vlan: %s", acc)
- return acc
--
2.48.1

View file

@ -18,8 +18,8 @@ buildPythonPackage {
pyproject = true;
patches = [
./02-remove-noisy-logs.patch
./03-set-log-level.patch
./04-request-dgsi-vlan.patch
];
sourceRoot = "source/pykanidm";

View file

@ -11,7 +11,10 @@
}:
let
pythonPath = python3.pkgs.makePythonPath [ pykanidm ];
pythonPath = python3.pkgs.makePythonPath [
pykanidm
python3.pkgs.requests
];
in
stdenv.mkDerivation rec {

Binary file not shown.

View file

@ -7,6 +7,7 @@
[
# List of secrets for vault01
"radius-auth_token_file"
"radius-dgsi_token_file"
"radius-ca_pem_file"
"radius-cert_pem_file"
"radius-dh_pem_file"