Skip to content

Enhance Builtin users SPI security#11763

Merged
ofahimIQSS merged 7 commits into
developfrom
11689-builtin-users-api-auth-enhance
Sep 4, 2025
Merged

Enhance Builtin users SPI security#11763
ofahimIQSS merged 7 commits into
developfrom
11689-builtin-users-api-auth-enhance

Conversation

@GPortas
Copy link
Copy Markdown
Contributor

@GPortas GPortas commented Aug 25, 2025

What this PR does / why we need it:

Security improvements for api-bearer-auth-use-builtin-user-on-id-match

We’ve strengthened the security of the api-bearer-auth-use-builtin-user-on-id-match feature flag. It will now only work when the provided bearer token includes an idp claim that matches the Keycloak Service Provider identifier.

By enforcing this check, the risk of impersonation from other identity providers is significantly reduced, since they would need to be explicitly configured with this specific, non-standard identifier.

Which issue(s) this PR closes:

Notes for the reviewer:

I’ve updated the warning in the documentation related to impersonation risk. With this additional security measure in place, user impersonation is unlikely to occur unless an IdP is intentionally misconfigured.

Suggestions on how to test this:

  1. Run the containerized dev environment under conf/keycloak

  2. Obtain a bearer token by logging into Keycloak with built-in account credentials

curl -X POST http://keycloak.mydomain.com:8090/realms/test/protocol/openid-connect/token -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=test" -d "client_secret=94XHrfNRwXsjqTqApRrwWmhDLDHpIYV8" -d "grant_type=password" -d "username=dataverseAdmin" -d "password=admin1" -d "scope=openid"

  1. Go to https://www.jwt.io/ and paste the access_token. You should see a new "idp" claim including the value "dv-builtin-users-authenticator" from the Keycloak SPI.
Screenshot 2025-08-27 at 09 48 32
  1. Test an API endpoint requiring auth using the generated access token, and make sure it correctly authenticates the user.

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

No

Is there a release notes update needed for this change?:

Yes, attached

Additional documentation:

N/A

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 25, 2025

Coverage Status

coverage: 23.375%. remained the same
when pulling cc6bd1c on 11689-builtin-users-api-auth-enhance
into ab2c661 on develop.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Base automatically changed from 11645-old-oidc-users-api-auth to develop August 25, 2025 19:38
@github-actions

This comment has been minimized.

@GPortas GPortas added GREI Re-arch Issues related to the GREI Dataverse rearchitecture SPA.Q3.2025.9 Deploy External User Auth to the Harvard Dataverse SPA Size: 3 A percentage of a sprint. 2.1 hours. Original size: 3 labels Aug 27, 2025
@GPortas GPortas moved this to Ready for Review ⏩ in IQSS Dataverse Project Aug 27, 2025
@GPortas GPortas marked this pull request as ready for review August 27, 2025 08:52
@GPortas GPortas added the SPA These changes are required for the Dataverse SPA label Aug 27, 2025
@GPortas GPortas requested a review from qqmyers August 27, 2025 08:54
@github-actions
Copy link
Copy Markdown

📦 Pushed preview images as

ghcr.io/gdcc/dataverse:11689-builtin-users-api-auth-enhance
ghcr.io/gdcc/configbaker:11689-builtin-users-api-auth-enhance

🚢 See on GHCR. Use by referencing with full name as printed above, mind the registry name.

@qqmyers qqmyers self-assigned this Aug 27, 2025
@qqmyers qqmyers moved this from Ready for Review ⏩ to In Review 🔎 in IQSS Dataverse Project Aug 27, 2025
@cmbz cmbz added the FY26 Sprint 5 FY26 Sprint 5 (2025-08-27 - 2025-09-10) label Aug 28, 2025

We’ve strengthened the security of the `api-bearer-auth-use-builtin-user-on-id-match` feature flag. It will now only work when the provided bearer token includes an `idp` claim that matches the Keycloak Service Provider identifier.

By enforcing this check, the risk of impersonation from other identity providers is significantly reduced, since they would need to be explicitly configured with this specific, non-standard identifier.
Copy link
Copy Markdown
Member

@qqmyers qqmyers Aug 29, 2025

Choose a reason for hiding this comment

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

Can this be part of the keycloak config, i.e. a static entry added there? Then we don't have to rely on the external provider. This is maybe less relevant for the internal users where you control the code, but it would be more under the site admin's control if there was a static value added to the token by keycloak (that was set for each login type).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. We could consider making the expected idp identifier configurable via a parameter in the SPI. Dataverse could then retrieve this value from a JVM option when verifying the token.

The main advantage I see in this approach is that it prevents the expected idp identifier claim value from being publicly exposed. This could indeed result in a more secure solution. That said, anyone who can successfully authenticate and obtain a token would still be able to decode it and see the idp claim value. Perhaps I’m missing other advantages of your approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wasn't thinking about it being configurable - just using the Keycloak config to add a static value, e.g.
image
Doing this, I don't think there would be any way for someone to configure a shib idp (or build a built-in account source like yours) that could allow impersonation.

Copy link
Copy Markdown
Member

@qqmyers qqmyers left a comment

Choose a reason for hiding this comment

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

Looks OK to me. I left a question about an ~alternate design, but I think what's here is fine to use now/should help security. I did not try to set this up at all so having QA try the whole setup and checking the tests is important.

@github-project-automation github-project-automation Bot moved this from In Review 🔎 to Ready for QA ⏩ in IQSS Dataverse Project Aug 29, 2025
@ofahimIQSS ofahimIQSS self-assigned this Sep 2, 2025
@ofahimIQSS ofahimIQSS moved this from Ready for QA ⏩ to QA ✅ in IQSS Dataverse Project Sep 2, 2025
@ofahimIQSS
Copy link
Copy Markdown
Contributor

Looks good to me - merging!

@ofahimIQSS ofahimIQSS merged commit ffa4619 into develop Sep 4, 2025
16 checks passed
@ofahimIQSS ofahimIQSS deleted the 11689-builtin-users-api-auth-enhance branch September 4, 2025 13:16
@github-project-automation github-project-automation Bot moved this from QA ✅ to Merged 🚀 in IQSS Dataverse Project Sep 4, 2025
@ofahimIQSS ofahimIQSS removed their assignment Sep 4, 2025
@scolapasta scolapasta moved this from Merged 🚀 to Done 🧹 in IQSS Dataverse Project Sep 4, 2025
@pdurbin pdurbin added this to the 6.8 milestone Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FY26 Sprint 5 FY26 Sprint 5 (2025-08-27 - 2025-09-10) GREI Re-arch Issues related to the GREI Dataverse rearchitecture Original size: 3 Size: 3 A percentage of a sprint. 2.1 hours. SPA.Q3.2025.9 Deploy External User Auth to the Harvard Dataverse SPA SPA These changes are required for the Dataverse SPA

Projects

Status: Done 🧹

Development

Successfully merging this pull request may close these issues.

Secure API_BEARER_AUTH_USE_BUILTIN_USER_ON_ID_MATCH with hardcoded 'builtin' OIDC attribute

7 participants