From decdbbe887b1af9f4ee4ddca5e035b1bfef25340 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Wed, 3 Aug 2022 10:43:52 +0100 Subject: [PATCH 1/4] Update the django requirements to 3.0 The tests already use django 3+ so we should align this everywhere. Signed-off-by: Peter Robinson Add a guide to setup zezere instance Signed-off-by: rdotjain Update .gitignore for conf file Signed-off-by: rdotjain Add endpoint to upload ov Signed-off-by: rdotjain Update endpoint to accept CBOR encoded vouchers Signed-off-by: rdotjain Improve error listing in UI using messages Signed-off-by: rdotjain tweak endpoint to accept multiple vouchers Signed-off-by: rdotjain bug fix: navbar active tab Signed-off-by: rdotjain Add error handling in API call Signed-off-by: rdotjain ui: change button style Signed-off-by: rdotjain update template for multiple ownership vouchers Signed-off-by: rdotjain add server base url in default conf Signed-off-by: rdotjain --- .gitignore | 3 + SETUP.md | 81 +++++++++++++++++++ requirements.txt | 2 +- zezere/default.conf | 1 + zezere/settings.py | 11 +++ zezere/templates/portal/master.html | 14 ++-- .../templates/portal/ownership_voucher.html | 26 ++++++ zezere/urls.py | 3 + zezere/views_portal.py | 66 ++++++++++++++- 9 files changed, 197 insertions(+), 10 deletions(-) create mode 100644 SETUP.md create mode 100644 zezere/templates/portal/ownership_voucher.html diff --git a/.gitignore b/.gitignore index 316a346..b49a9f3 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,6 @@ venv.bak/ # mypy .mypy_cache/ + +# conf file +zezere.conf \ No newline at end of file diff --git a/SETUP.md b/SETUP.md new file mode 100644 index 0000000..82a4941 --- /dev/null +++ b/SETUP.md @@ -0,0 +1,81 @@ +# Setup a zezere instance locally + +1. To install requirements in a Python virtual environment, set it up first. + ```sh + $ virtualenv venv + $ . venv/bin/activate + ``` + +2. Before installing other Python requirements, you need to install Apache httpd first. Follow the instructions from [mod-wsgi project documentation](https://pypi.org/project/mod-wsgi/). +
+In order to satisfy the `psycopg2` dependency please follow instructions from + [psycopg2 project documentation](https://www.psycopg.org/docs/install.html). + +3. Install the requirements + ```sh + $ (venv) pip install . + ``` + +4. Before using the `zezere-manage` tool, a configuration needs to be created. + Default configuration can be used as a base: + + ``` + $ cp zezere/default.conf ./zezere.conf + ``` + +5. Authentication method and secret key needs to be set in order to satisfy the + tool. Also, make sure that the allowed_hosts is what you want. + + ``` + allowed_hosts = localhost, 127.0.0.1 + secret_key = very-secret + auth_method = local + ``` + +6. Now run the migrations, to create a database file. + ```sh + $ python manage.py migrate --noinput + ``` + +7. To collect the static files, run + ``` + $ python manage.py collectstatic + ``` + +8. Now we can create a superuser: + + ``` + $ zezere-manage createsuperuser --username admin --email user@domain.tld + ``` + +9. After a password has been set, we are ready to run Zezere: + + ``` + ./app.sh + ``` + + Use the admin credentials we created to login to localhost:8080 + +
+ +# Setup using Docker +The easiest way to run Zezere is to run the official container and authenticate + with OpenID Connect: + + ``` + $ docker run --detach --rm --name zezere \ + -e OIDC_RP_CLIENT_ID= \ + -e OIDC_RP_CLIENT_SECRET= \ + -e OIDC_OP_AUTHORIZATION_ENDPOINT= \ + -e OIDC_OP_TOKEN_ENDPOINT= \ + -e OIDC_OP_USER_ENDPOINT= \ + -e OIDC_OP_JWKS_ENDPOINT= \ + -e AUTH_METHOD=oidc \ + -e SECRET_KEY=localtest \ + -e ALLOWED_HOSTS=localhost \ + -p 8080:8080 \ + -t quay.io/fedora-iot/zezere:latest + ``` + + The default signing algorithm is `RS256` but it can also be controlled with the + environment variable `OIDC_OP_SIGN_ALGO` \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3d2334b..7881470 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django>=2.1 +django>=3.0 djangorestframework django-ipware psycopg2 diff --git a/zezere/default.conf b/zezere/default.conf index 42bf231..78fc39f 100644 --- a/zezere/default.conf +++ b/zezere/default.conf @@ -4,6 +4,7 @@ debug = no allowed_hosts = localhost, localhost.localdomain secure_cookie = yes # auth_method = local, oidc +# ov_base_url = [oidc.rp] # client_id = diff --git a/zezere/settings.py b/zezere/settings.py index d430ba1..b42b882 100644 --- a/zezere/settings.py +++ b/zezere/settings.py @@ -2,6 +2,7 @@ import os +from django.contrib.messages import constants as messages from .settings_external import get, getboolean from .settings_auth import AUTH_INFO @@ -161,3 +162,13 @@ "django.contrib.staticfiles.finders.FileSystemFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder", ] + +MESSAGE_TAGS = { + messages.DEBUG: "alert-secondary", + messages.INFO: "alert-info", + messages.SUCCESS: "alert-success", + messages.WARNING: "alert-warning", + messages.ERROR: "alert-danger", +} + +OV_BASE_URL = get("global", "ov_base_url", "OV_BASE_URL") diff --git a/zezere/templates/portal/master.html b/zezere/templates/portal/master.html index 1f6de35..43825c4 100644 --- a/zezere/templates/portal/master.html +++ b/zezere/templates/portal/master.html @@ -44,18 +44,21 @@