Skip to content
Snippets Groups Projects
Commit f601b512 authored by nimrod's avatar nimrod
Browse files

First draft.

Depends on my fork of flask-simpleldap.
parent 84d359c6
No related branches found
No related tags found
No related merge requests found
Pipeline #1132 passed
* *
!app.py
!requirements.txt
FROM registry.hub.docker.com/library/python:3.9-slim-buster as wheels
# hadolint ignore=DL3008,DL3015
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential \
libldap2-dev \
libsasl2-dev \
;
WORKDIR /wheels
RUN python3 -m pip wheel https://github.com/python-ldap/python-ldap/releases/download/python-ldap-3.3.1/python-ldap-3.3.1.tar.gz
FROM registry.hub.docker.com/library/python:3.9-slim-buster FROM registry.hub.docker.com/library/python:3.9-slim-buster
# hadolint ignore=DL3008 # hadolint ignore=DL3008
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libldap-2.4-2 \ build-essential \
libsasl2-2 \ git \
libldap2-dev \
libsasl2-dev \
&& \ && \
rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/* rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
COPY --from=wheels /wheels/*.whl /wheels/ WORKDIR /app
RUN pip install /wheels/*.whl COPY requirements.txt ./
# hadolint ignore=DL3013 RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir \ COPY * ./
flask \ USER nobody
flask-ldap \ EXPOSE 8080
gunicorn \ ENV FORWARDED_ALLOW_IPS "*"
; HEALTHCHECK CMD wget --spider --quiet http://localhost:8080/ping --user-agent 'Docker Healthcheck' || exit 1
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--log-file", "-", "--workers", "2", "app:app"]
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
LDAP authentication webserver to use with Nginx' auth\_request. LDAP authentication webserver to use with Nginx' auth\_request.
## Configuration
All of the configuration is done with environment variables. For the
complete list see <https://flask-simpleldap.readthedocs.io/en/latest/#configuration>
and
<https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables>.
## License ## License
This software is licensed under the MIT license (see `LICENSE.txt`). This software is licensed under the MIT license (see `LICENSE.txt`).
......
app.py 0 → 100644
"""LDAP authentication webserver to use with Nginx' auth_request."""
# pylint: disable=import-error
import os
from flask import Flask
from flask_simpleldap import LDAP
app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY", os.urandom(16))
app.config["LDAP_SCHEMA"] = os.getenv("LDAP_SCHEMA", "ldapi")
app.config["LDAP_HOST"] = os.getenv("LDAP_HOST", "localhost")
app.config["LDAP_PORT"] = int(os.getenv("LDAP_PORT", "389"))
app.config["LDAP_USERNAME"] = os.getenv("LDAP_USERNAME")
app.config["LDAP_PASSWORD"] = os.getenv("LDAP_PASSWORD")
app.config["LDAP_USE_TLS"] = (
os.getenv("LDAP_USE_TLS", "false").lower() == "true"
)
app.config["LDAP_REQUIRE_CERT"] = (
os.getenv("LDAP_REQUIRE_CERT", "false").lower() == "true"
)
app.config["LDAP_BASE_DN"] = os.getenv("LDAP_BASE_DN")
app.config["LDAP_REALM_NAME"] = os.getenv(
"LDAP_REALM_NAME", "LDAP authentication"
)
app.config["LDAP_OPENLDAP"] = (
os.getenv("LDAP_OPENLDAP", "false").lower() == "true"
)
ldap = LDAP(app)
@app.route("/ping")
def ping():
"""Healthcheck."""
return "pong"
@app.route("/")
def index():
pass
@app.route("/login")
@ldap.basic_auth_required
def login():
return "OK"
if __name__ == "__main__":
app.run()
flask
#flask-simpleldap
git+https://github.com/adarnimrod/flask-simpleldap.git@ldapi-support#egg=flask-simpleldap
gunicorn
python-ldap
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment