Skip to content

Implement SAML login#71

Draft
BeritJanssen wants to merge 31 commits intodevelopfrom
feature/saml-login
Draft

Implement SAML login#71
BeritJanssen wants to merge 31 commits intodevelopfrom
feature/saml-login

Conversation

@BeritJanssen
Copy link
Collaborator

@BeritJanssen BeritJanssen commented Jul 15, 2025

This branch adds the dependencies to configure paths for SAML login on the backend, and adds a login button on the frontend.

It also adds Dockerfiles for bacckend and frontend and a docker-compose.yaml, which spins up @tymees ' fantastic development-IDP. Wrt @jgonggrijp 's #58 : the files here are actually nicely picking up where that PR leaves off, i.e., they are intended for use in development, after the project has been successfully generated.

Also: updated Angular, because, why not? and what could possibly go wrong? 😆 The added tsconfig.json (to include the "useDefineForClassFields": false setting) and renames of app.component -> app, as well as changing afterRender -> afterEveryRender are caused by that change.

So in summary, a bit of feature creep here, but also hopefully some functionality / updates to help.

NB: Due to #73 , it's necessary to manually set a date in frontend/src/environments/version.ts before this can be run with docker-compose up.

@BeritJanssen BeritJanssen marked this pull request as draft July 15, 2025 10:22
{% if cookiecutter.basic_authentication == "Yes, please!" %}
dj_rest_auth
django-allauth
django-allauth<65.3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary not to go too high here, as otherwise settings for SAML clash with settings for allauth.

Copy link
Member

@tymees tymees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm only tagged, but I have some minor nitpicks for the test-idp docker config.

Sorry for the unprompted review

{% endif %}
{% if cookiecutter.saml_authentication == "Yes, please!" %}
test-idp:
image: ghcr.io/centrefordigitalhumanities/development-idp/development-idp:develop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking develop isn't recommended; I have broken that build at times.

Please use the latest tag. (It did not exist before, like, 5 minutes ago, so thanks for the hint I forgot to merge something)

image: ghcr.io/centrefordigitalhumanities/development-idp/development-idp:develop
ports:
- 127.0.0.1:7000:7000
volumes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you are using the test-idp in sqlite mode; you might want to create a volume for /app/db such that you don't have to recreate the SAML SP entry every time the container gets updated; Or provide the relevant ENV settings to use PSQL

- type: bind
source: backend/user/tests/saml/idp_certificates
target: /app/certificates
command: sh -c "python manage.py migrate && python manage.py loaddata main/fixtures/initial.json main/fixtures/admin-user.json && python manage.py runserver 0.0.0.0:7000"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: the latest image's entrypoint should do all this, so it's better to remove this imo

This isn't a great idea imho, it's a bit of a cheat to get the container to do something it can't do automatically, and can break stuff later down the line.
I think this was done this way to automatically load in the needed data, which I can understand.

To that end, in the latest version I've made the supplied entrypoint capable of doing this. It check if the initial data is not yet in the DB, and if so, will do the loaddata's automatically.

So, this custom command should be redundant now?

If you didn't want to include the battery of test-users, you can disable that part of the bootstrapping by adding

env:
- NOTESTUSERBOOTSTRAP=true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I didn't get the docker/startup.sh to work yet, but wanted to trigger those commands, and on top of that, eventually, also want to include another custom)fixture which adds a service provider of the generated application for testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough;

I'm just worried that, in the future, I get complaints I broke something because I changed the startup routine. (And as this is a template, it would be hell to fix everywhere).

I could look into a way to supply custom fixtures to the image, to autoload. Something like 'mount a file in /bootstrap and the app will load that as well'. Would that be enough to start using the supplied startup script?

@BeritJanssen
Copy link
Collaborator Author

BeritJanssen commented Jul 18, 2025

Thanks for the feedback, @tymees ! I incorporated some of your comments, but left the longish command for now. This is as far as I've gotten. I'd hoped to add a fixture, as mentioned, to auto-add the service provider, but cannot figure out how to export the appropriate model.

TODO:

  • add a ServiceProvider fixture for testing. For now: create a service provider by logging into the test-idp at localhost:7000/admin (admin/admin) and add a ServiceProvider object. I used entity_id=saml/metadata/ (full url didn't work) and paste the metadata from http://localhost:8000/users/saml/metadata/ into the metadata field (pasting the url itself gives an error upon saving).
  • (optional but perhaps cleaner?): move the test data now in backend/user/tests/saml to functional-tests (since technically this will be used for functional and not unit tests)
  • figure out the problem after clicking the "Solis login" button from localhost:4200/login: NotImplementedError from http://localhost:7000/saml/idp/login/process/
Screenshot 2025-07-17 at 16 10 11
  • after login in works: work on logout
  • add documentation - some of it can be found in this branch, but especially when running without Docker (for which the instruction is now basically docker compose up after doing cookiecutter git-or-local-path-to-this-repo), there are no pointers here, but I hope @tymees can help if somebody would rather run frontend, backend, database and test-idp locally (I didn't).

I'd hoped to finish this branch before handing it over (I understood that @bbonf will take over all things SAML?), but seeing as I accidentally also Dockerized and updated the Angular version along the way, I kind of ran out of time.

@@ -0,0 +1,23 @@
FROM docker.io/python:3.11-alpine3.20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is development-oriented, I suggest using buildpack-deps instead. it's much larger, but it has git and other tools built-in and the overal cost to the developer is low because it is used as a common base for most development-oriented images.

Disable ssr; because it creates index.csr.html instead of index.html now and we aren't even really using ssr anyway
@oktaal oktaal force-pushed the feature/saml-login branch from c237326 to 20143dd Compare October 24, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants