Skip to content

Commit dce35ab

Browse files
committed
Add Docker support for easier deployments + uppercase REALM
Author: alfonsrv <alfonsrv@protonmail.com> Developer Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me. (c) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: github/alfonsrv <alfonsrv@protonmail.com>
1 parent f61979e commit dce35ab

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed

docker/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM python:3.11-slim
2+
LABEL maintainer="github/alfonsrv <alfonsrv@protonmail.com>"
3+
4+
ENV APACHE_CONFDIR=/etc/apache2
5+
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends git \
8+
apache2 libapache2-mod-wsgi-py3 \
9+
krb5-k5tls \
10+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
11+
12+
RUN a2enmod wsgi \
13+
&& a2enmod ssl \
14+
&& a2enmod headers \
15+
&& a2enmod setenvif
16+
17+
RUN ln -sf /proc/self/fd/1 /var/log/apache2/access.log && \
18+
ln -sf /proc/self/fd/1 /var/log/apache2/error.log
19+
20+
COPY config/kdc-wsgi.conf ${APACHE_CONFDIR}/sites-available/
21+
22+
# Download + install kdcproxy and get install path to replace in apache config
23+
RUN git clone https://github.com/latchset/kdcproxy.git /tmp/kdcproxy \
24+
&& pip install /tmp/kdcproxy \
25+
&& KDC_PROXY_PATH=$(python -c "import site; print(site.getsitepackages()[0])")/kdcproxy \
26+
&& sed -ri -e "s!KDC_PROXY_PATH!${KDC_PROXY_PATH}!g" /etc/apache2/sites-available/*.conf \
27+
&& sed -ri -e "s!SERVER_NAME!${SERVER_NAME}!g" /etc/apache2/sites-available/*.conf
28+
29+
RUN a2dissite 000-default.conf \
30+
&& a2ensite kdc-wsgi.conf
31+
32+
CMD ["apachectl", "-D", "FOREGROUND"]

docker/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# KDC Proxy Docker Container 🐋
2+
3+
* Rename `config/sample-kdcproxy.conf` to `config/kdcproxy.conf`
4+
* Configure Domain Controller IP addresses via `extra_hosts` in `docker-compose.yml`
5+
* Configure Realm and Domain Controller DNS Names in `config/kdcproxy.conf`
6+
* Run `docker-compose up` and configure to run as service
7+
* Run either behind reverse proxy or as a directly exposed server (bring your own certificates)

docker/certs/.gitkeep

Whitespace-only changes.

docker/config/kdc-wsgi.conf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<VirtualHost *:443>
2+
ServerName SERVER_NAME
3+
ErrorLog ${APACHE_LOG_DIR}/error.log
4+
CustomLog ${APACHE_LOG_DIR}/access.log combined
5+
6+
SSLEngine on
7+
SSLCertificateFile /certs/cert.crt
8+
SSLCertificateKeyFile /certs/cert.key
9+
10+
# Prevent showing the default Apache2 website
11+
RedirectMatch ^/(?!(?i:KdcProxy))(.*)$ https://opensource.org/
12+
13+
# Python WSGI KDC Proxy setup
14+
WSGIDaemonProcess kdcproxy \
15+
processes=2 \
16+
threads=15 \
17+
maximum-requests=1000 \
18+
display-name=%{GROUP}
19+
WSGIImportScript KDC_PROXY_PATH/__init__.py \
20+
process-group=kdcproxy \
21+
application-group=kdcproxy
22+
WSGIScriptAliasMatch "(?i)^/KdcProxy" \
23+
KDC_PROXY_PATH/__init__.py
24+
WSGIScriptReloading Off
25+
26+
# Set headers if available
27+
<IfModule mod_setenvif.c>
28+
SetEnvIf X-Forwarded-Host (.*) REAL_HOST_HEADER=$1
29+
<IfModule mod_headers.c>
30+
RequestHeader set Host "%{REAL_HOST_HEADER}e"
31+
</IfModule>
32+
</IfModule>
33+
34+
<LocationMatch "(?i)^/KdcProxy">
35+
Satisfy Any
36+
Order Deny,Allow
37+
Allow from all
38+
WSGIProcessGroup kdcproxy
39+
WSGIApplicationGroup kdcproxy
40+
</LocationMatch>
41+
</VirtualHost>

docker/config/sample-kdcproxy.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[global]
2+
# Use default libkrb5 configuration; if you load the mit config module in the master configuration file,
3+
# kdcproxy will also read the config using libkrb5 (usually /etc/krb5.conf). If this module is used, kdcproxy
4+
# will respect the DNS settings from the [libdefaults] section and the realm configuration from the [realms] section.
5+
# For more information, see the documentation for MIT's krb5.conf.
6+
configs = mit
7+
8+
# Use DNS SRV lookup to automatically resolve domain
9+
use_dns = False
10+
11+
[CONTOSO.LOC]
12+
# The realm configuration parameters may list multiple servers separated by a space.
13+
# The order the realms are specified in will be respected by kdcproxy when forwarding requests. The port number is optional.
14+
#
15+
# Possible schemes are:
16+
# * kerberos://
17+
# * kerberos+tcp://
18+
# * kerberos+udp://
19+
# * kpasswd://
20+
# * kpasswd+tcp://
21+
# * kpasswd+udp://
22+
23+
kerberos = kerberos+tcp://test-dc1.contoso.loc:88
24+
kpasswd = kpasswd+tcp://test-dc1.contoso.loc:464

docker/docker-compose.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
version: '3'
3+
services:
4+
kdcproxy:
5+
build:
6+
context: .
7+
dockerfile: ./Dockerfile
8+
container_name: kdcproxy-apache
9+
restart: unless-stopped
10+
ports:
11+
- "443:443"
12+
environment:
13+
- KDCPROXY_CONFIG=/config/kdcproxy.conf
14+
- SERVER_NAME=${SERVER_NAME:-selfsign.rausys.de}
15+
volumes:
16+
- config:/config:ro
17+
- certs:/certs:ro
18+
extra_hosts:
19+
- "test-dc1.contoso.loc:10.10.10.10"
20+
21+
omgwtfssl:
22+
image: paulczar/omgwtfssl
23+
container_name: kdcproxy-ssl
24+
restart: "no"
25+
volumes:
26+
- certs:/certs
27+
environment:
28+
- SSL_SUBJECT=${SERVER_NAME:-selfsign.rausys.de}
29+
- SSL_KEY=/certs/cert.key
30+
- SSL_CSR=/certs/cert.csr
31+
- SSL_CERT=/certs/cert.crt
32+
33+
volumes:
34+
config:
35+
driver: local
36+
driver_opts:
37+
type: none
38+
o: bind
39+
device: ./config
40+
certs:
41+
driver: local
42+
driver_opts:
43+
type: none
44+
o: bind
45+
device: ./certs

kdcproxy/parse_pyasn1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def decode_proxymessage(data):
100100
realm = str(realm, "utf-8")
101101
except TypeError: # Python 2.x
102102
realm = str(realm)
103+
realm = realm.upper()
103104
else:
104105
realm = None
105106
flags = req.getComponentByName('flags')

0 commit comments

Comments
 (0)