Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Forked from jmvrbanac/gunicorn_options.yml
Created May 10, 2017 23:46
Show Gist options
  • Save kgriffs/289206f07e23b9a30d29a2b23e28c41c to your computer and use it in GitHub Desktop.
Save kgriffs/289206f07e23b9a30d29a2b23e28c41c to your computer and use it in GitHub Desktop.
Capture Client Certificate CN from Gunicorn
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
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