Skip to content

maj fix certificates - #1157

Open
jma wants to merge 2 commits into
rero:stagingfrom
jma:maj-fix-certificates
Open

maj fix certificates#1157
jma wants to merge 2 commits into
rero:stagingfrom
jma:maj-fix-certificates

Conversation

@jma

@jma jma commented Aug 4, 2026

Copy link
Copy Markdown
Contributor
  • fix(shibboleth): update SWITCH edu-ID identity provider certificates
  • fix(certificates): generate development certificates instead of versioning them

The signing certificates of both edu-ID identity providers had expired, in
January 2021 for production and October 2020 for the test environment. Replace
them with the current ones, valid until 2033, taken from the SWITCH federation
metadata and checked against their SHA-256 fingerprints.

The test certificate was also truncated by one line, which made it impossible
to parse.

Co-Authored-By: Johnny Mariéthoz <johnny.mariethoz@rero.ch>
@jma
jma marked this pull request as ready for review August 11, 2026 09:26
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The project now generates development HTTPS certificates with mkcert or OpenSSL. Bootstrap and server scripts use these certificates. Docker images generate their own self-signed certificates during builds. Versioned certificate and key files are excluded from packaging. SAML service-provider credentials are optional and IdP certificate loading uses configured paths. SWITCHaai options remain hidden when credentials are incomplete. Tests use temporary generated certificates and cover this behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title mentions certificates but is too vague and does not identify the certificate updates or development certificate changes. Use a concise title that names the certificate updates and the change to generated development certificates.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description directly covers both certificate updates and generated development certificates, which match the pull request changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jma

jma commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

@jma I will review pull request #1157.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/ui/test_utils.py (1)

73-76: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the one-sided missing-key cases.

The guard must reject a configuration when either key is absent. This test removes both keys at once, so it does not detect an and regression or a configuration with only one key. (raw.githubusercontent.com)

Add separate assertions for only x509cert and only private_key.

Suggested coverage
-    app.config["SHIBBOLETH_SERVICE_PROVIDER"] = {"entity_id": "entity_id"}
-    assert get_switch_aai_providers() == []
+    for service_provider in (
+        {"entity_id": "entity_id", "x509cert": "cert"},
+        {"entity_id": "entity_id", "private_key": "key"},
+        {"entity_id": "entity_id"},
+    ):
+        app.config["SHIBBOLETH_SERVICE_PROVIDER"] = service_provider
+        assert get_switch_aai_providers() == []
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ui/test_utils.py` around lines 73 - 76, Extend the
get_switch_aai_providers() tests to cover each one-sided configuration
separately: assert an empty provider list when only entity_id and x509cert are
present, and again when only entity_id and private_key are present. Keep the
existing both-keys-missing assertion and ensure each case replaces the
service-provider configuration independently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pyproject.toml`:
- Line 269: Add scripts/gen-certs to MANIFEST.in alongside the other
individually listed scripts so source distributions include the executable
required by the certs task.

In `@scripts/server`:
- Around line 62-65: Move the certificate path assignments and the preflight
check using cert and key before the Celery worker startup block in
scripts/server. Ensure missing certificates trigger the existing error message
and exit before Celery is launched, while preserving the existing cleanup and
startup behavior for valid certificates.

---

Nitpick comments:
In `@tests/ui/test_utils.py`:
- Around line 73-76: Extend the get_switch_aai_providers() tests to cover each
one-sided configuration separately: assert an empty provider list when only
entity_id and x509cert are present, and again when only entity_id and
private_key are present. Keep the existing both-keys-missing assertion and
ensure each case replaces the service-provider configuration independently.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1232d8b3-85a4-48f0-9b09-04c0d6a9e741

📥 Commits

Reviewing files that changed from the base of the PR and between 52e3a96 and 901cfcb.

⛔ Files ignored due to path filters (2)
  • docker/haproxy/haproxy_cert.pem is excluded by !**/*.pem
  • docker/nginx/sp.pem is excluded by !**/*.pem
📒 Files selected for processing (28)
  • .dockerignore
  • .gitignore
  • INSTALL.md
  • MANIFEST.in
  • data/idp_certificates/eduid.crt
  • data/idp_certificates/eduidtest.crt
  • data/idp_certificates/idp.crt
  • docker/haproxy/Dockerfile
  • docker/haproxy/haproxy.cfg
  • docker/nginx/Dockerfile
  • docker/nginx/sp.key
  • docker/nginx/test.crt
  • docker/nginx/test.key
  • pyproject.toml
  • scripts/bootstrap
  • scripts/gen-certs
  • scripts/server
  • sonar/modules/shibboleth_authenticator/auth.py
  • sonar/modules/shibboleth_authenticator/config.py
  • sonar/modules/shibboleth_authenticator/ext.py
  • sonar/modules/utils.py
  • sonar/theme/templates/sonar/accounts/login.html
  • sonar/theme/templates/sonar/accounts/signup.html
  • tests/conftest.py
  • tests/ui/shibboleth_authenticator/conftest.py
  • tests/ui/shibboleth_authenticator/test_shibboleth_auth.py
  • tests/ui/test_utils.py
  • tests/ui/test_views.py
💤 Files with no reviewable changes (4)
  • docker/nginx/test.crt
  • docker/nginx/test.key
  • docker/nginx/sp.key
  • data/idp_certificates/idp.crt

Comment thread pyproject.toml
Comment thread scripts/server Outdated
…oning them

Three private keys were versioned in this public repository, exposed since
2018 and 2019: the TLS key of the development server, its duplicate in the
HAProxy bundle, and the SAML service provider key. All the versioned
certificates had expired as well, which left the HTTPS development server
unusable by any modern browser.

Certificates are now generated where they are needed:

- `scripts/gen-certs` produces the development server pair in `.certs/`, using
  mkcert when available so that browsers accept it without warning, and falling
  back to openssl elsewhere. It is called by the bootstrap, which never
  regenerates an existing pair unless `--force-certs` is given, and skips the
  step on deploy.
- The nginx and HAProxy images generate their own certificate at build time.
  HAProxy needs a separate stage, its base image ships no openssl command.
- The tests build an ephemeral key pair in a temporary directory, so the suite
  no longer depends on any certificate file.

The service provider key pair has no default any more. It identifies the
instance to the identity providers, so it has to be registered in the SWITCH
edu-ID resource registry and cannot be generated locally: each environment
provides its own and references it in `invenio.cfg`. Until then SAML stays
disabled and the SWITCHaai button is hidden rather than leading to an error.

The identity providers certificates directory becomes configurable, which also
removes the constraint of running the application from the repository root.

`scripts/server` now verifies the certificates before starting anything. The
check used to run after the celery worker had been spawned, and the cleanup trap
was registered later still, so a missing pair left an orphaned worker behind.
The worker PID was also captured in a differently spelled variable than the one
the trap and the final wait read; spelling it consistently makes both cover the
worker on a normal exit too.

Co-Authored-By: Johnny Mariéthoz <johnny.mariethoz@rero.ch>
@jma
jma force-pushed the maj-fix-certificates branch from 901cfcb to 498f656 Compare August 11, 2026 13:27
@jma
jma requested a review from rerowep August 17, 2026 09:01
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.

5 participants