diff --git a/Dockerfile b/Dockerfile index cfb72ee..6b77322 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,4 +16,4 @@ WORKDIR /app COPY . /app ENV FLASK_APP=app.py -CMD ["flask", "run", "--host=0.0.0.0"] +CMD ["gunicorn", "--worker-class", "eventlet", "--bind", ":5000", "app:app"] diff --git a/app.py b/app.py index 0e28ecd..81a5352 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ from flask import Flask, Response, request, session, abort, redirect +from flask.logging import default_handler import flask from werkzeug.middleware.proxy_fix import ProxyFix import uw_saml2 @@ -6,6 +7,19 @@ from datetime import timedelta import os import secrets +import logging + + +def configure_logging(): + gunicorn_logger = logging.getLogger('gunicorn.error') + level = logging.DEBUG + if gunicorn_logger: + level = gunicorn_logger.level + logging.getLogger().setLevel(level) + logging.getLogger('uw_saml2').addHandler(default_handler) + + +configure_logging() app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_prefix=1) POSTBACK_ROUTE = '/login' @@ -22,7 +36,7 @@ ) -@app.route('/status') +@app.route('/status') # if we add any more options then refactor all this. @app.route('/status/2fa') @app.route('/status/group/') @app.route('/status/group//2fa') @@ -79,7 +93,6 @@ def login_redirect(return_to=''): return_to - the path to redirect back to after authentication. This and the request.query_string are set on the SAML RelayState. """ - app.logger.error(f'URL ROOT {request.url_root}') query_string = '?' + request.query_string.decode() if query_string == '?': query_string = '' @@ -105,7 +118,6 @@ def login(): session['userid'] = attributes['uwnetid'] session['groups'] = attributes.get('groups', []) session['has_2fa'] = attributes.get('two_factor') - app.logger.info(attributes) relay_state = request.form.get('RelayState') if relay_state and relay_state.startswith('/'): return redirect(urljoin(request.url_root, request.form['RelayState'])) diff --git a/docker-compose.yml b/docker-compose.yml index 7dc9275..ec8c706 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,4 +10,4 @@ services: image: mynginx ports: ["443:443"] volumes: - - ./test/nginx/server.conf:/etc/nginx/conf.d/server.conf \ No newline at end of file + - ./test/nginx/server.conf:/etc/nginx/conf.d/server.conf diff --git a/requirements.txt b/requirements.txt index f5973c1..d4e4e16 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Werkzeug>=0.15 flask uw-saml[python3-saml]>=1.0.3 +gunicorn[eventlet]