summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/service_https.py17
-rw-r--r--src/services/api/rest/routers.py6
2 files changed, 22 insertions, 1 deletions
diff --git a/src/conf_mode/service_https.py b/src/conf_mode/service_https.py
index 28985ead9..f66ce043c 100755
--- a/src/conf_mode/service_https.py
+++ b/src/conf_mode/service_https.py
@@ -112,6 +112,9 @@ def verify(https):
else:
Warning('No certificate specified, using build-in self-signed certificates. '\
'Do not use them in a production environment!')
+ if dict_search('certificates.verify_client', https) is not None:
+ if dict_search('certificates.ca_certificate', https) is None:
+ raise ConfigError('CA certificate must be configured for mTLS client verification')
# Check if server port is already in use by a different application
listen_address = ['0.0.0.0']
@@ -212,6 +215,20 @@ def generate(https):
tmp_path.update({'dh_file' : dh_path})
https['certificates'].update(tmp_path)
+ # Write mTLS CA chain if verify-client is configured
+ if dict_search('certificates.verify_client', https) and dict_search('certificates.ca_certificate', https):
+ ca_name = https['certificates']['ca_certificate']
+ pki_ca = dict_search(f'pki.ca.{ca_name}', https)
+ if pki_ca:
+ # Build full chain: intermediate + root CAs for client cert verification
+ loaded_ca_certs = {
+ load_certificate(cert_data['certificate'])
+ for cert_data in dict_search('pki.ca', https, default={}).values()
+ }
+ mtls_ca_path = os.path.join(cert_dir, f'{ca_name}_mtls_ca.pem')
+ ca_chain = '\n'.join(encode_certificate(c) for c in loaded_ca_certs)
+ write_file(mtls_ca_path, ca_chain, user=user, group=group, mode=0o644)
+ https['certificates']['mtls_ca_path'] = mtls_ca_path
render(config_file, 'https/nginx.default.j2', https)
render(systemd_override, 'https/override.conf.j2', https)
diff --git a/src/services/api/rest/routers.py b/src/services/api/rest/routers.py
index 0a43e856b..55967f57d 100644
--- a/src/services/api/rest/routers.py
+++ b/src/services/api/rest/routers.py
@@ -101,8 +101,12 @@ def check_auth(key_list, key):
return key_id
-def auth_required(data: ApiModel, x_api_key: Optional[str] = Header(None), authorization: Optional[str] = Header(None)):
+def auth_required(data: ApiModel, x_api_key: Optional[str] = Header(None), authorization: Optional[str] = Header(None), x_client_verify: Optional[str] = Header(None)):
session = SessionState()
+ # mTLS: client certificate verified by nginx against configured CA
+ if x_client_verify == 'SUCCESS':
+ session.id = 'mtls-client'
+ return
if authorization:
scheme, _, token = authorization.partition(' ')