diff --git a/README.md b/README.md index 58cde129e22dc7d6d443cc379c80f5150962b182..2832e81e09b3a14ae19751433a73a346cf7b2073 100644 --- a/README.md +++ b/README.md @@ -108,5 +108,8 @@ This is the procedure for that. (this should say 'No changes detected', but do this step anyway as a check) > docker exec -it atdb-ldv python manage.py migrate --settings atdb.settings.docker_sdc - + +#### Integrating Astronauth + +See the integration instructions in the [astronauth repo](https://git.astron.nl/astron-sdc/astronauth) diff --git a/atdb/Dockerfile b/atdb/Dockerfile index 858f3465f847b30dd9268c782f62ca39cc5d4c90..0004e0d801204223b54e0b173a32695f0515513f 100644 --- a/atdb/Dockerfile +++ b/atdb/Dockerfile @@ -1,18 +1,16 @@ -FROM python:3.6.7-alpine -ENV PYTHONUNBUFFERED 1 -RUN apk update && apk add bash && apk add nano && apk add mc +FROM python:3.10-slim +RUN apt-get update && apt-get install --no-install-recommends -y bash nano mc libmagic1 git + RUN mkdir /src WORKDIR /src COPY . /src/ -# install dependencies -RUN \ - apk add --no-cache python3 postgresql-libs && \ - apk add --no-cache --virtual .build-deps gcc python3-dev musl-dev postgresql-dev && \ - pip install -r requirements/prod.txt && \ - apk --purge del .build-deps +RUN pip install --upgrade pip +RUN pip install -r requirements/prod.txt + +RUN python manage.py collectstatic --settings=atdb.settings.dev --noinput # run gunicorn -CMD exec gunicorn atdb.wsgi_docker_sdc:application --bind 0.0.0.0:8000 --workers 4 +CMD exec gunicorn atdb.wsgi_docker_sdc:application --bind 0.0.0.0:8000 --workers 4 --timeout 120 diff --git a/atdb/atdb/settings/base.py b/atdb/atdb/settings/base.py index d50d1746a64ba3f36c017bc0861f2b7454ac51fd..34afccd7d57b985c3745a4d1ef5d5abf5a7c664e 100644 --- a/atdb/atdb/settings/base.py +++ b/atdb/atdb/settings/base.py @@ -31,7 +31,16 @@ INSTALLED_APPS = [ 'bootstrap_pagination', 'django_tables2', 'bootstrap3', - 'fontawesome-free' + 'fontawesome-free', + + ## These are required for ASTRONauth + 'django.contrib.sites', + "astronauth", # it is important that astronauth is included before allauth + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + 'allauth.socialaccount.providers.keycloak', + ] MIDDLEWARE = [ @@ -202,3 +211,29 @@ AGGREGATES = ['failed','active','total'] QUERY_LIMIT_MULTI_CHANGE = 1000 MAX_MONITORING_HISTORY_HOURS = 7 * 24 SERVICES_LATE_WARNING_SECONDS = 1800 + +# astronauth settings +SITE_ID = 1 + +AUTHENTICATION_BACKENDS = [ + # Needed to login by username in Django admin, regardless of `allauth` + "django.contrib.auth.backends.ModelBackend", + # `allauth` specific authentication methods, such as login by e-mail + "allauth.account.auth_backends.AuthenticationBackend", +] + +SOCIALACCOUNT_PROVIDERS = { + 'keycloak': { + 'KEYCLOAK_URL': 'https://sdc-dev.astron.nl/auth', # replace by https://keycloak.astron.nl/auth for production + 'KEYCLOAK_REALM': 'SDC', # change this depending on which realm to use + 'SCOPE': ['openid', 'profile', 'email'] + } +} + +try: + LOGIN_REDIRECT_URL = os.environ['LOGIN_REDIRECT_URL'] +except: + LOGIN_REDIRECT_URL = 'https://sdc-dev.astron.nl:5554/atdb/' + +SESSION_COOKIE_NAME = 'my_service_name_session_id' +CSRF_COOKIE_NAME = 'my_service_csrftoken' diff --git a/atdb/atdb/settings/dev.py b/atdb/atdb/settings/dev.py index 3e9765a64d78277b567ed66c1a53796418fd56ff..8c9925a1c09fb042fa2979d79353f4c43a2247ad 100644 --- a/atdb/atdb/settings/dev.py +++ b/atdb/atdb/settings/dev.py @@ -13,7 +13,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'USER': 'atdb_admin', 'PASSWORD': 'atdb123', - 'NAME': 'atdb_ldv_27jan2023', + 'NAME': 'atdb_ldv_astronauth_6feb2023', 'HOST': 'localhost', 'PORT': '5432', }, @@ -23,3 +23,14 @@ DATABASES = { # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [] + +# astronauth settings +SOCIALACCOUNT_PROVIDERS = { + 'keycloak': { + 'KEYCLOAK_URL': 'https://sdc-dev.astron.nl/auth', # replace by https://keycloak.astron.nl/auth for production + 'KEYCLOAK_REALM': 'SDC', # change this depending on which realm to use + 'SCOPE': ['openid', 'profile', 'email'] + } +} + +LOGIN_REDIRECT_URL = "http://localhost:8000/atdb" diff --git a/atdb/atdb/settings/docker_sdc.py b/atdb/atdb/settings/docker_sdc.py index 35ce0aaea3b8bf46b966d7536a43ee14c744be69..a4307fa8d426f4c197531ae667546a6f94222e7c 100644 --- a/atdb/atdb/settings/docker_sdc.py +++ b/atdb/atdb/settings/docker_sdc.py @@ -37,3 +37,4 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [] + diff --git a/atdb/atdb/urls.py b/atdb/atdb/urls.py index b5e26030204398c859780fb37edeeff0d684c834..772e9a544afa52cd65eca218472d4589309da4c0 100644 --- a/atdb/atdb/urls.py +++ b/atdb/atdb/urls.py @@ -6,4 +6,5 @@ urlpatterns = [ path('atdb/', include('taskdatabase.urls')), path('atdb/admin/', admin.site.urls), path('atdb/api-auth/', include('rest_framework.urls')), + path("atdb/astronauth/", include("astronauth.urls")), # include astronauth ] diff --git a/atdb/requirements/base.txt b/atdb/requirements/base.txt index ac71b471c94cb22ea3a47e7a4ae72571378190e4..f19e4afbc35ca8e24dde82ca0c7e9929a0b5f5f2 100644 --- a/atdb/requirements/base.txt +++ b/atdb/requirements/base.txt @@ -1,12 +1,17 @@ +astronauth==0.3.3 Django==3.1.4 -djangorestframework==3.12.2 -django-filter==2.3.0 -psycopg2-binary==2.9.3 +django-allauth==0.52.0 +django-bootstrap-pagination==1.7.0 +django-bootstrap3==14.2.0 django-cors-headers==3.6.0 django-extensions==3.1.0 -django-bootstrap-pagination==1.7.0 -whitenoise==5.0.1 -six==1.15.0 +django-filter==2.3.0 django-tables2==2.3.4 -django-bootstrap3==14.2.0 -fontawesome-free==5.15.2 \ No newline at end of file +djangorestframework==3.12.2 +fontawesome-free==5.15.2 +oauthlib==3.2.2 +psycopg2-binary==2.9.3 +python3-openid==3.2.0 +requests-oauthlib==1.3.1 +six==1.15.0 +whitenoise==5.0.1 \ No newline at end of file diff --git a/atdb/taskdatabase/templates/astronauth/base.html b/atdb/taskdatabase/templates/astronauth/base.html new file mode 100644 index 0000000000000000000000000000000000000000..c87a64cc18dab20d4f2c5807f516780f9e9fc0a2 --- /dev/null +++ b/atdb/taskdatabase/templates/astronauth/base.html @@ -0,0 +1,25 @@ +{% load static %} +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="utf-8"> + + <title>{% block head_title %}{% endblock %} - ASTRONauth</title> + + <link rel="stylesheet" type="text/css" href="{% static 'taskdatabase/style.css' %}"/> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> + <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'> + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous"> + + <link rel="stylesheet" href="{% static 'astronauth/css/dias.css' %}"> + <link rel="stylesheet" href="{% static 'astronauth/css/custom.css' %}"> + +</head> + +<body> + {% include "astronauth/navbar.html" %} + {% block content %}{% endblock %} +</body> + +</html> diff --git a/atdb/taskdatabase/templates/astronauth/navbar.html b/atdb/taskdatabase/templates/astronauth/navbar.html new file mode 100644 index 0000000000000000000000000000000000000000..4acbe6f4fb664372c171e09a9715f1868da2cb7d --- /dev/null +++ b/atdb/taskdatabase/templates/astronauth/navbar.html @@ -0,0 +1,58 @@ +{% load static %} +{% load account %} + + + <nav class="navbar navbar-expand-lg navbar-light bg-light"> + <div class="container-fluid"> + + <ul class="nav navbar-nav"> + <!-- Header --> + <li><a class="navbar-brand" href="{% url 'index' %}"> + <img src="{% static 'taskdatabase/new_ldv_logo.png' %}" height="30" alt=""> + ATDB</a> + </li> + + <li><a class="nav-link" href="{% url 'index' %}">Tasks</a></li> + {% comment %} + <li><a class="nav-link" href="{% url 'postprocessing-tasks' %}">PostProcessing</a></li> + {% endcomment %} + + {% if user.is_authenticated %} + <li><a class="nav-link" href="{% url 'task-details'%}">Task Details</a></li> + {% endif %} + + <li><a class="nav-link" href="{% url 'dashboard' 'active_nores_nofilter' %}">Dashboard</a></li> + + <li><a class="nav-link" href="{% url 'query' %}">Filter</a></li> + + <li><a class="nav-link" href="{% url 'quality' %}">Quality</a></li> + <li><a class="nav-link" href="{% url 'validation' %}">Validation</a></li> + <li><a class="nav-link" href="{% url 'failures' %}">Failures</a></li> + <li><a class="nav-link" href="{% url 'archived' %}">Archived</a></li> + <li><a class="nav-link" href="{% url 'monitoring' %}">Monitoring</a></li> + <li><a class="nav-link" href="{% url 'diagram' %}">Diagram</a></li> + + {% if user.is_superuser %} + <li><a class="nav-link" href="{% url 'config' %}">Configuration</a></li> + <li><a class="nav-link" href="{% url 'admin:index' %}" target="_blank">Admin</a></li> + {% endif %} + + </ul> + + <ul class="nav navbar-nav"> + {% if "/login/" in request.path or "/logout/" in request.path %} + {# don't render antyhing #} + {% elif user.is_authenticated %} + + <li class="h-navbar-list__item"> + <a class="button button--secondary margin-right" href="{% url 'account_logout' %}">Sign Out {{ user.get_username }}</a> + </li> + {% else %} + <li class="h-navbar-list__item"> + <a class="button button--secondary margin-right" href="{% url 'account_login' %}">Sign In</a> + </li> + {% endif %} + </ul> + </div> + + </nav> \ No newline at end of file diff --git a/atdb/taskdatabase/templates/taskdatabase/base.html b/atdb/taskdatabase/templates/taskdatabase/base.html index 384c0fd7bb0b3ec8abc7aeada1e07463a54ea59b..92f5949b590c7ed3f554f986f9e6fab8a3e274e5 100644 --- a/atdb/taskdatabase/templates/taskdatabase/base.html +++ b/atdb/taskdatabase/templates/taskdatabase/base.html @@ -30,56 +30,10 @@ {% block extra_js %}{% endblock %} - </head> <body onload="readFromLocalStorage('search_box')"> - <nav class="navbar navbar-expand-lg navbar-light bg-light"> - <div class="container-fluid"> - <ul class="nav navbar-nav"> - <!-- Header --> - <li><a class="navbar-brand" href="{% url 'index' %}"> - <img src="{% static 'taskdatabase/new_ldv_logo.png' %}" height="30" alt=""> - ATDB</a> - </li> - - <li><a class="nav-link" href="{% url 'index' %}">Tasks</a></li> -{% comment %} - <li><a class="nav-link" href="{% url 'postprocessing-tasks' %}">PostProcessing</a></li> -{% endcomment %} - - {% if user.is_authenticated %} - <li><a class="nav-link" href="{% url 'task-details'%}">Task Details</a></li> - {% endif %} - - <li><a class="nav-link" href="{% url 'dashboard' 'active_nores_nofilter' %}">Dashboard</a></li> - - <li><a class="nav-link" href="{% url 'query' %}">Filter</a></li> - - <li><a class="nav-link" href="{% url 'quality' %}">Quality</a></li> - <li><a class="nav-link" href="{% url 'validation' %}">Validation</a></li> - <li><a class="nav-link" href="{% url 'failures' %}">Failures</a></li> - <li><a class="nav-link" href="{% url 'archived' %}">Archived</a></li> - - <li><a class="nav-link" href="{% url 'monitoring' %}">Monitoring</a></li> - - <li><a class="nav-link" href="{% url 'diagram' %}">Diagram</a></li> - - {% if user.is_superuser %} - <li><a class="nav-link" href="{% url 'config' %}">Configuration</a></li> - <li><a class="nav-link" href="{% url 'admin:index' %}" target="_blank">Admin</a></li> - {% endif %} - - </ul> - - {% if user.is_authenticated %} - <a class="nav-link" href="{% url 'logout' %}" target="_blank">Logout {{ user.get_username }}</a> - {% endif %} - {% if not user.is_authenticated %} - <a class="nav-link" href="{% url 'login' %}" target="_blank">Login</a> - {% endif %} - </div> - </nav> + {% include "astronauth/navbar.html" %} {% for message in messages %} <div class="container-fluid p-0"> diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 8c8de66b1d0dafac2abab405d6b114d636197657..d83edee3d12a3c73aea22a2b867adc843165b3ba 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 6 Februari 2023 + <p class="footer"> Version 6 Februari 2023 - 14:00 </div>