Commit 9275119d authored by nimrod's avatar nimrod
Browse files

First draft.

Depends on my fork of flask-simpleldap.
parent 84d359c6
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
*
!app.py
!requirements.txt
+13 −21
Original line number Diff line number Diff line
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
# hadolint ignore=DL3008
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
        libsasl2-2 \
        build-essential \
        git \
        libldap2-dev \
        libsasl2-dev \
    && \
    rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
COPY --from=wheels /wheels/*.whl /wheels/
RUN pip install /wheels/*.whl
# hadolint ignore=DL3013
RUN pip install --no-cache-dir \
        flask \
        flask-ldap \
        gunicorn \
    ;
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY * ./
USER nobody
EXPOSE 8080
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"]
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,13 @@

LDAP authentication webserver to use with Nginx' auth\_request.

## Configuration

All of the configuration should be 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

This software is licensed under the MIT license (see `LICENSE.txt`).

app.py

0 → 100644
+29 −0
Original line number Diff line number Diff line
"""LDAP authentication webserver to use with Nginx' auth_request."""
# pylint: disable=import-error

from flask import Flask
from flask_simpleldap import LDAP

app = Flask(__name__)
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()

requirements.txt

0 → 100644
+5 −0
Original line number Diff line number Diff line
flask
#flask-simpleldap
git+https://github.com/adarnimrod/flask-simpleldap.git@ldapi-support#egg=flask-simpleldap
gunicorn
python-ldap