mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 13:51:35 +01:00
feat: support for cert based authentication
This commit is contained in:
3
nginx.py
3
nginx.py
@@ -63,9 +63,12 @@ def dump_config(vmList, masterAddress):
|
|||||||
with open("/etc/nginx/nginx.conf", "w") as f:
|
with open("/etc/nginx/nginx.conf", "w") as f:
|
||||||
|
|
||||||
with open("./config/nginx.json") as j:
|
with open("./config/nginx.json") as j:
|
||||||
|
|
||||||
nginxJson = json.load(j)
|
nginxJson = json.load(j)
|
||||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="./templates"))
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="./templates"))
|
||||||
template = env.get_template("nginx.conf.j2")
|
template = env.get_template("nginx.conf.j2")
|
||||||
|
mapsTemplate = env.get_template("nginx_maps.j2")
|
||||||
|
nginxJson["maps"] = mapsTemplate.render()
|
||||||
content = template.render(nginxJson)
|
content = template.render(nginxJson)
|
||||||
|
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ events {
|
|||||||
|
|
||||||
http {
|
http {
|
||||||
|
|
||||||
|
{{ maps }}
|
||||||
|
|
||||||
sendfile on;
|
sendfile on;
|
||||||
tcp_nopush on;
|
tcp_nopush on;
|
||||||
tcp_nodelay on;
|
tcp_nodelay on;
|
||||||
|
|||||||
10
templates/nginx_maps.j2
Normal file
10
templates/nginx_maps.j2
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
map $ssl_client_s_dn $allow_group_main {
|
||||||
|
default "";
|
||||||
|
~CN=Sheppy2 true;
|
||||||
|
~CN=Kathi true;
|
||||||
|
}
|
||||||
|
|
||||||
|
map $ssl_client_s_dn $allow_group_ths {
|
||||||
|
default "";
|
||||||
|
~OU=THS true;
|
||||||
|
}
|
||||||
@@ -14,6 +14,12 @@ server{
|
|||||||
listen 80;
|
listen 80;
|
||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
|
|
||||||
|
{% if cert_optional %}
|
||||||
|
ssl_client_certificate ca_cert.pem;
|
||||||
|
ssl_verify_client optional;
|
||||||
|
ssl_verify_depth 1;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if extra_location %}
|
{% if extra_location %}
|
||||||
location {{ extra_location["location"] }} {
|
location {{ extra_location["location"] }} {
|
||||||
{{ extra_location["content"] }}
|
{{ extra_location["content"] }}
|
||||||
@@ -28,6 +34,7 @@ server{
|
|||||||
proxy_pass http://{{ targetip }}:{{ targetport }};
|
proxy_pass http://{{ targetip }}:{{ targetport }};
|
||||||
proxy_set_header Host $http_host;
|
proxy_set_header Host $http_host;
|
||||||
{{ proxy_pass_blob }}
|
{{ proxy_pass_blob }}
|
||||||
|
{{ cert_header_line }}
|
||||||
{% if basicauth %}
|
{% if basicauth %}
|
||||||
auth_basic "{{ basicauth }}";
|
auth_basic "{{ basicauth }}";
|
||||||
auth_basic_user_file /etc/nginx/{{ basicauth }}.htpasswd;
|
auth_basic_user_file /etc/nginx/{{ basicauth }}.htpasswd;
|
||||||
|
|||||||
14
vm.py
14
vm.py
@@ -134,11 +134,23 @@ class VM:
|
|||||||
|
|
||||||
compositeName = "-".join((self.hostname, subdomain["name"].replace(".","-")))
|
compositeName = "-".join((self.hostname, subdomain["name"].replace(".","-")))
|
||||||
targetport = subdomain.get("port") or 80
|
targetport = subdomain.get("port") or 80
|
||||||
|
|
||||||
|
# build cert group #
|
||||||
|
if subdomain.get("cert-group"):
|
||||||
|
cert_group_name = subdomain.get("cert-group")
|
||||||
|
header_line = "proxy_set_header X-Nginx-Cert-Auth $allow_group_{};".format(cert_group_name)
|
||||||
|
cert_optional = True
|
||||||
|
else:
|
||||||
|
header_line = "proxy_set_header X-Nginx-Cert-Auth false;"
|
||||||
|
cert_optional = False
|
||||||
|
|
||||||
component = template.render(targetip=self.ip, targetport=targetport,
|
component = template.render(targetip=self.ip, targetport=targetport,
|
||||||
servernames=[subdomain["name"]], comment=compositeName,
|
servernames=[subdomain["name"]], comment=compositeName,
|
||||||
proxy_pass_blob=self.proxy_pass_blob, acme=not self.noTerminateACME,
|
proxy_pass_blob=self.proxy_pass_blob, acme=not self.noTerminateACME,
|
||||||
basicauth=subdomain.get("basicauth"),
|
basicauth=subdomain.get("basicauth"),
|
||||||
extra_location=subdomain.get("extra-location"))
|
extra_location=subdomain.get("extra-location"),
|
||||||
|
cert_optional=cert_optional,
|
||||||
|
cert_header_line=header_line)
|
||||||
components.append(component)
|
components.append(component)
|
||||||
|
|
||||||
return components
|
return components
|
||||||
|
|||||||
Reference in New Issue
Block a user