-
-
Save kgriffs/289206f07e23b9a30d29a2b23e28c41c to your computer and use it in GitHub Desktop.
Capture Client Certificate CN from Gunicorn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bind: 0.0.0.0:8000 | |
workers: 1 | |
worker_class: "example.worker:CustomWorker" | |
timeout: 30 | |
ca_certs: ca.crt | |
certfile: server.crt | |
keyfile: server.key | |
cert_reqs: 2 | |
do_handshake_on_connect: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gunicorn.workers.sync import SyncWorker | |
class CustomWorker(SyncWorker): | |
def handle_request(self, listener, req, client, addr): | |
subject = dict(client.getpeercert().get('subject')[0]) | |
headers = dict(req.headers) | |
headers['X-USER'] = subject.get('commonName') | |
req.headers = list(headers.items()) | |
super(CustomWorker, self).handle_request(listener, req, client, addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment