Skip to content

SSO using OpenID Connect#3899

Merged
dani-garcia merged 87 commits intodani-garcia:mainfrom
Timshel:sso-support
Aug 8, 2025
Merged

SSO using OpenID Connect#3899
dani-garcia merged 87 commits intodani-garcia:mainfrom
Timshel:sso-support

Conversation

@Timshel
Copy link
Copy Markdown
Contributor

@Timshel Timshel commented Sep 18, 2023

This is based on previous PR (#2787, #2449 and #3154) with work done by @pinpox, @m4w0lf, @Sheap, @bmunro-peralex, @tribut and others I probably missed sorry.

This PR add support for OpenId Connect to handle authentication to an external SSO.
This introduce another way to control who can use the vault without having to use invitation or an LDAP.

A master password is still required and not controlled by the SSO (depending on your point of view this might be a feature ;).

Bitwarden key connector is not supported and due to the license it's highly unlikely that it will ever be:

2.1 Commercial Module License. Subject to Your compliance with this Agreement, Bitwarden hereby grants to You a limited, non-exclusive, non-transferable, royalty-free license to use the Commercial Modules for the sole purposes of internal development and internal testing, and only in a non-production environment.

Usage

This should be agnostic to the SSO used as long as it supports client secret authentication and expose an OpenID Connect Discovery endpoint. (I'm testing it with Keycloak at the moment, a demo test stack is available README.md)

Added some documentation at the root of the project SSO.md that could be later moved to the wiki.

I made some additional modification in my main branch to allow for easier testing (modified Docker image to use prebuilt patched front-end).

On front-end modification, I made patched versions available at Timshel/oidc_web_builds. Two versions are available :

  • One contains the change expected to be merged (named button); all change needs to be compatible with the non-sso version.
  • Second one set #sso as the default redirect url.

Issues

As mentioned in the previous PR one of the main issue is the inability for the organization invitation to work with the SSO redirection. To fix it a patch to the front-end is needed.

⚠️⚠️ ⚠️ If you have issues or need help testing the PR ⚠️ ⚠️ ⚠️

Please open issues in Timshel/vaultwarden in order to keep the discussion here focused on merging this work.
Of course if you believe your issue is important mention this PR so a reference will be visible.

But please try to keep commenting in this PR to a minimum to keep it legible, the previous one has over 200 comments ...

@derfabianpeter
Copy link
Copy Markdown

Super happy to see this PR being worked on. We (ayedo.de) would be willing to offer a sponsoring to prioritize this PR if that helps! Just reach out.

@Timshel Timshel force-pushed the sso-support branch 2 times, most recently from c86e481 to d5f78b4 Compare September 28, 2023 17:06
@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Sep 28, 2023

Just added a configuration example for Gitlab which might be one of easiest way to test this PR :).

@AkechiShiro
Copy link
Copy Markdown

AkechiShiro commented Sep 29, 2023

Hi @Timshel, thanks for your amazing and prolonged work on this feature, is this PR close to be in a ready merge-able state or is there a lot of work left?
I see the latest commit is about documentation, so, all issues mentioned at the beginning were fixed in some way or another ? Or there are still issue to fix ?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Sep 29, 2023

Mainly waiting for maintainer review/feedback now :).

@ruben-herold
Copy link
Copy Markdown

@Timshel thx for your work!!! Hope this will be integrated soon

@pellux-network
Copy link
Copy Markdown

Hoping this gets merged soon!

@AkechiShiro
Copy link
Copy Markdown

AkechiShiro commented Oct 4, 2023

Tagging some maintainers for review on this PR, if they have the available time resource to do so @BlackDex @dani-garcia

EDIT: I don't understand the thumbs-down, because tagging maintainers doesn't mean they have time to handle the PR or review it, it's just a way to mention them, if they don't answer/go MIA, or whatever, feel free to fork on this PR and maintain your own forks, no one is entitled to do any work, they don't want to.

@BlackDex
Copy link
Copy Markdown
Collaborator

BlackDex commented Oct 4, 2023

I do not have much time actually.

Also, I'm a bit puzzled with all the different SSO PR's.
And I am a bit hesitant to merge one if that for some reason could break the other or has a totally different way of working.
I'm not sure what to do here because i see people want something like this, but there are multiple ways of getting this working it looks like.

One way would be to create a semi-supported release branch which contains SSO support, but that could get messy keeping it up-to-date. What do you think @dani-garcia ?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Oct 4, 2023

? As mentioned this is the continuation of the previous PRs, it all rely on openidconnect. All of those PR are based on the previous ones when the previous PR owner stopped maintaining it.

I can´t speak for the owner of previous PRs but I believe this make all the others redundant. You could probably close the previous one referencing this one and encourage their owner to reopen if something is missing.

Thanks @bmunro-peralex for closing his PR to make things more legible and of course for his work which is present in this PR :).

@xoxys
Copy link
Copy Markdown
Contributor

xoxys commented Oct 4, 2023

Why not finally add at least one way to support OIDC? You can also flag it as preview feature or something like this to get feedback from the community, but not getting this feature into Vaultwarden after multiple PRs were provided by the community without a review or without getting merged for months until the authors then gave up feels wrong to me for an open source project.

@BlackDex
Copy link
Copy Markdown
Collaborator

BlackDex commented Oct 4, 2023

Why not finally add at least one way to support OIDC? You can also flag it as preview feature or something like this to get feedback from the community, but not getting this feature into Vaultwarden after multiple PRs were provided by the community without a review or without getting merged for months until the authors then gave up feels wrong to me for an open source project.

Well, because One way could be a different way then the others, or could cause a lot of other changes needed to be done if they do not match, or maybe even could overlap and do something totally different. 49 FIles are changed, so I'm not going to be happy if there needs to be major rework done because of adding this feature which is not fully working/supported.

You have to keep in mind that this could break other code in some way. But as said before, i do not have much time to check and validate this. And this is a huge PR and a lot of testing needs to be done, and i this is not specifically on my prio list for now actually. That is why i mentioned a special branch, which builds this version with a different tag and not fully supported in terms of issues with the login from my side.

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Oct 4, 2023

Well, because One way could be a different way then the others, or could cause a lot of other changes needed to be done if they do not match, or maybe even could overlap and do something totally different.

@BlackDex I'll insist but there is no other way (At least not in the currently opened PRs). All those PR are based on the previous ones. They got more refined each time as someone picked-it up.

@tschuyebuhl
Copy link
Copy Markdown

is there any way one can help with testing? or anything that can be done to help get this merged?

@isaiah-v
Copy link
Copy Markdown

isaiah-v commented Oct 4, 2023

I've been watching the progress of this feature. I can't wait for it, but out of curiosity, how does decryption work with this feature? Is it still client side? How do you now decrypt without knowing the password?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Oct 4, 2023

@isaiah-v as mentioned a master password is still required. There is no change on this point.

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Oct 6, 2023

@BlackDex thinking on it I don´t think the semi-supported branch is a good idea.

Main issue for people running this branch is that there might be some change in the migrations that might force to correct DB state manually. Even if it's not difficult (cf Timshel/vaultwarden#db-migration), integrating in a separate branch would not help with this.

Additionally unless you grant me commit rights it means that this would make it more complicated for me to support it and if you have no time for review I can't see how you would semi-support it.

It's important to note that the SSO_ENABLED config act as feature flag, the impact on the non sso version is quite low so merging this should have a low risk for the non sso users.

In the end if people are not running it at the moment it might be because they are waiting for an easier way to run this (but I made updates on main@Timshel/vaultwarden to make it easier) but I would expect it's mainly because they are waiting for it to be reviewed, a solution without any review would not be worth much ...

Since I'm running this myself I will maintain this branch/PR, and will continue to update main@Timshel/vaultwarden with anything I can think of to help people running it. As mentioned before if you have any question don't hesitate but please open it on Timshel/vaultwarden to prevent spamming here (of course mention this PR if you think your issue is important).

In my opinion the next step is for it to be reviewed and then integrated (maybe without being promoted at first).

@AkechiShiro
Copy link
Copy Markdown

I will definitely try to host the branch of your fork that contains sso-support and see if I run into any issues, I will report them on your repo @Timshel

@dandanthedev
Copy link
Copy Markdown

+1, please merge!

@griefie
Copy link
Copy Markdown

griefie commented Oct 10, 2023

It seems that there is a lot of hesitation on investing time into reviewing this and i can understand this. However - the longer the delay the bigger the diff guys. The branch clearly works and simply needs a bit more love. Besides it already looks like a lot of work went into this and the older preceding branches. Why not make it a beta build? Even 2.0.0-beta? The closer it is to the main stream, the quicker will be the feedback and the improvement. Let's not forget this is open source, where ideas thrive and not corporate where ideas die ;)

@derfabianpeter
Copy link
Copy Markdown

We're still happy to sponsor this PR if it helps

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Oct 11, 2023

Rebased and added the @BlackDex suggestion in #3154 (comment) to make the SSO button visible when running the docker-compose.

@gjuuz
Copy link
Copy Markdown

gjuuz commented Aug 11, 2025

@Timshel
thanks for this explaination.

@BlackDex
is there a possibility to get this implemented ? It would be difficult to explain all people to first complete sso before they can enter their vaultwarden credentials.
It would be very helpful to redirect the login page to sso only.

@TheDarkula
Copy link
Copy Markdown

@Timshel I see here that there is a SSO_SCOPES environment variable.
Will there be something like SSO_ADMIN_CLAIM/SSO_USER_CLAIM for specifying roles?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Aug 12, 2025

@TheDarkula not sure what the env variable are supposed to do, but if you want role mapping I already opened #6158 to add access to the admin console depending on role and will open one for Organization and groups sync later on.

@gjuuz
Copy link
Copy Markdown

gjuuz commented Aug 12, 2025

@Timshel
found something related to the sso issue:

It seems like this has something to do with the url length of the sso callback. Its opening the bitwarden app if i cut the link down to 2046 limit.

there is also a chromium issue opened about this:
https://issues.chromium.org/issues/41322340

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Aug 12, 2025

@gjuuz this would explain things since I wrap the code in a JWT token to be able to pass more information.
I'll check if I can't do things differently with latest client version, thx.

@gjuuz
Copy link
Copy Markdown

gjuuz commented Aug 12, 2025

@Timshel
Thanks that would be great :)

@TheDarkula
Copy link
Copy Markdown

@Timshel Excellent, thank you! That is exactly what I meant :)

There is one more feature I am after, which is allowing nested roles.

In Open WebUI, they have this:
OAUTH_ROLES_CLAIM - The claim that contains the roles. Defaults to roles. Can also be nested, for example user.roles.

Is that what SSO_ROLES_TOKEN_PATH is meant for?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Aug 20, 2025

@gjuuz opened #6205 with the modification to stop wrapping the returned code in a JWT Token this should fix the issues around token length.

While working on it realized that the PKCE implementation was wonky.
It was not validating the challenge sent by the Bitwarden clients but generating a challenge server side with does not help much with security. So made the change to validate the Bitwarden challenge before calling the providers, this does mean it will be checked even if SSO_PKCE is disabled (Had some issue to pass it to the provider but might have a solution).

If you are running OIDCWarden then there is an update with this.
But the timshel/vaulwarden distribution is more or less deprecated since I can't really spend the time to maintain both "fork" and open new PR.

@prk0ghy
Copy link
Copy Markdown

prk0ghy commented Sep 6, 2025

@Timshel @dani-garcia thank you so much, you are amazing!

@Crow-Control
Copy link
Copy Markdown

@Timshel does this also allow for backchannel logout from the OIDC provider?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Sep 25, 2025

@PrivatePuffin Not at the moment, It should be possible to roll the device token to invalidate all sessions, might take a look 🤔.

@mdddev
Copy link
Copy Markdown

mdddev commented Oct 10, 2025

@isaiah-v as mentioned a master password is still required. There is no change on this point.

Hi @isaiah-v , may I ask if this is still the case?

@robin-thoni
Copy link
Copy Markdown

@isaiah-v as mentioned a master password is still required. There is no change on this point.

Hi @isaiah-v , may I ask if this is still the case?

SSO just allows you to download the encrypted version of your vault. So, unless you implement Key Connector (assuming vaultvarden supports it, which I don't think it does), yes a master password will still be required to decrypt it.

@mdddev
Copy link
Copy Markdown

mdddev commented Oct 10, 2025

Thank your for the speedy reply!

@dvtkrlbs
Copy link
Copy Markdown

@isaiah-v as mentioned a master password is still required. There is no change on this point.

Hi @isaiah-v , may I ask if this is still the case?

SSO just allows you to download the encrypted version of your vault. So, unless you implement Key Connector (assuming vaultvarden supports it, which I don't think it does), yes a master password will still be required to decrypt it.

Yes someone needs to add Key Connector support to vaultwarden to be able to ditch master password on SSO setting. If I have time I plan to try an impl. The problem iirc is the key connector binary from bitwarden is limited license so we would need to write a clean room impl of that binary and the endpoints it would require on vaultwarden.

@DihaHub
Copy link
Copy Markdown

DihaHub commented Dec 2, 2025

Since this is merged and closed, is Key Connector already implemented?

@sandervandegeijn
Copy link
Copy Markdown

Update from our side: pentest is agreed upon and scheduled. We will give the results to the maintainers and if possible publish it publicly.

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Dec 2, 2025

@DihaHub, as mentioned, with the license issue I do not plan to work on it and I'm unaware of anyone working on it.

An alternative could be trusted devices (where I believe most of the key handling is done client side, but I could be wrong 😅).
But I don't have the support to spend time on it at the moment.

And since I'm already spamming everyone, I'll mention that since v2025.9.1-1 the web-client from Vaultwarden and from Timshel/oidc_web_vault should be cross compatible.
Might interest those who want to run mainline Vaultwarden but with a default redirection to the #sso page (override distribution). As always if you encounter any problem don't hesitate to open an issue (moved to Timshel/OIDCWarden)

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Dec 3, 2025

@sandervandegeijn I would wait until #6205 is merged before running the pen-test.

@DihaHub
Copy link
Copy Markdown

DihaHub commented Dec 9, 2025

@DihaHub, as mentioned, with the license issue I do not plan to work on it and I'm unaware of anyone working on it.

An alternative could be trusted devices (where I believe most of the key handling is done client side, but I could be wrong 😅). But I don't have the support to spend time on it at the moment.

And since I'm already spamming everyone, I'll mention that since v2025.9.1-1 the web-client from Vaultwarden and from Timshel/oidc_web_vault should be cross compatible. Might interest those who want to run mainline Vaultwarden but with a default redirection to the #sso page (override distribution). As always if you encounter any problem don't hesitate to open an issue (moved to Timshel/OIDCWarden)

Please excuse my ignorance, but I thought OIDCwarden had been merged into Vaultwarden and is being further developed there. But did I understand correctly that the best solution is still to use OIDCwarden in combination with OIDC_web_Vault?

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Dec 9, 2025

@DihaHub depends on what you need, there is still not yet merged features: Timshel/OIDCWarden#additional-features

@sandervandegeijn
Copy link
Copy Markdown

Pentest is done, it's a long read and I have shared it with the maintainers of Vaultwarden. I can't disclose it integrally because there are too many details about our infrastructure in there. I can share the main findings which are not impactful (good job by the devs and @Timshel !)

image

Job well done, we are going to deploy this setup to production within a few weeks :)

@Timshel
Copy link
Copy Markdown
Contributor Author

Timshel commented Feb 2, 2026

@sandervandegeijn I'll note that SIGNUPS_VERIFY already exists :).

@Rainson12
Copy link
Copy Markdown

@sandervandegeijn I'll note that SIGNUPS_VERIFY already exists :).

I also want to note that disabling of local user account registration is possible SIGNUPS_ALLOWED=false in such case accounts would be registered automatically when signing in via SSO

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.