From ebdfac1230d2f30f8b6308f7ed8533e8f0278005 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Wed, 21 Apr 2021 22:55:24 +0300 Subject: [PATCH] Replace flask-simpleldap with flask-ldap-auth. Simpler binding (just specify the URI), so no patch required. --- Dockerfile | 1 - app.py | 12 ++++++++---- requirements.txt | 3 +-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4272d03..7662e29 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ FROM registry.hub.docker.com/library/python:3.9-slim-buster RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ build-essential \ - git \ libldap2-dev \ libsasl2-dev \ && \ diff --git a/app.py b/app.py index 2b01829..9518698 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,15 @@ """LDAP authentication webserver to use with Nginx' auth_request.""" # pylint: disable=import-error -from flask import Flask -from flask_simpleldap import LDAP +import os +from flask import Flask, token +from flask_ldap_auth import login_required app = Flask(__name__) -ldap = LDAP(app) +app.config["SECRET_KEY"] = os.getenv("SECRET_KEY", os.urandom(16)) +app.config["LDAP_AUTH_SERVER"] = os.getenv("LDAP_AUTH_SERVER", "ldapi:///") +app.config["LDAP_TOP_DN"] = os.getenv("LDAP_TOP_DN") +app.register_blueprint(token, url_prefix="/auth") @app.route("/ping") @@ -20,7 +24,7 @@ def index(): @app.route("/login") -@ldap.basic_auth_required +@login_required def login(): return "OK" diff --git a/requirements.txt b/requirements.txt index 4f04f73..81308f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ flask -#flask-simpleldap -git+https://github.com/adarnimrod/flask-simpleldap.git@ldapi-support#egg=flask-simpleldap +flask-ldap-auth gunicorn python-ldap -- GitLab