Issue Description
I am trying to set up an external web application to access my e-mails (it’s Bulwark Webmail, dunno if you know it
).
Since the v1.0, accessing security-related settings require additional permissions, which means creating a First-Party OIDC client in Stalwart.
However, this configuration works if I use internal/LDAP/SQL directory, but not an external OIDC provider.
That’s why I open this issue.
Expected Behavior
This is how I imagined the thing (correct me if I’m wrong).
If I create an OIDC client in Stalwart and then instruct Bulwark to login through Stalwart, the latter should redirect me to my external OIDC provider using the WebUI client token.
Once logged in, Stalwart should display its authorization flow, asking me if I want to authorize Bulwark to access my account, then Bulwark should login and display security-related settings (like app passwords).
Actual Behavior
If Bulwark directly connects to my external OIDC provider: login works but security-related settings are not available
If Bulwark logins with Stalwart through a First-Party OIDC client: Stalwart asks me to login with a username/password, but not using my external SSO provider
Reproduction Steps
- Install Stalwart with an external SSO
- Install an external webapp (like Bulwark on its own (sub)domain)
- Create two clients in the external SSO : one public for Stalwart, one private for the webapp
- Create a First-party OIDC Client in Stalwart for Bulwark, with the same client ID and secret as Bulwark (so it’s also the same as the client in the external provider)
- Configure Bulwark to use the external provider
- Try now. It does not work. Stalwart debug logs says it’s because Bulwark does not asks for the email/contacts/files/calendar scopes against the external provider.
- Change the external SSO in Stalwart to interoperable mode
- Bulwark succeeds to login, but no security related settings
- Configure Bulwark so it tries to login against Stalwart
- Stalwart ask for non-existant username/password through its own login form
Stalwart Version
v1.x
Installation Method
Docker
Database Backend
RocksDB
Blob Storage
RocksDB
Search Engine
Internal
Directory Backend
OIDC
Additional Context
Related Bulwark Mail issue: [Bug]: Unable to access security-related options when using external SSO for Stalwart · Issue #1387 · bulwarkmail/webmail · GitHub
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on
Stalwart can’t do what you expect in steps 9 and 10. For a domain served by an OIDC directory, Stalwart doesn’t broker the sign-in. The external provider is the authorization server and Stalwart only validates the tokens it issues. Stalwart’s built-in authorization server, which a first-party OAuthClient belongs to, only authenticates against Stalwart’s own directories (internal, LDAP or SQL). That’s why it shows a username and password form that matches nobody. The recovery administrator is the only account that can sign in there. A first-party OAuthClient therefore can’t give an external-SSO user elevated access.
For tokens from your external provider, the docs say access depends on the token’s client and scopes:
- A token whose client claim (
azp, client_id, cid or appid) equals the oauthClientId of an installed Application, or identifies that Application’s Client ID Metadata Document, gets the account’s full permissions. The WebUI works this way.
- A token with interoperable scopes (mail, contacts, calendars, files) is limited to those scopes. This is probably why Bulwark’s login works but the security settings are missing.
- A token with neither is handled by the directory’s
unscopedTokens setting, which is reject by default.
In theory, if Bulwark’s token from your provider carried a client id that matches an installed Application’s oauthClientId, it would get full permissions. The docs only describe this for Stalwart’s own Applications, such as the WebUI. I found nothing saying a third-party app can be registered this way. I can’t confirm that it works, or that it is intended or safe, for Bulwark.
The docs don’t describe a supported way to give an external web app the security settings (such as app passwords) for OIDC-directory accounts. A staff member may be able to say whether that’s a limitation or planned.
Docs:
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.
Someone from the linked Github issue said that registering a stub application with the same client ID as the external webapp make things to work.
But it seems to be a workaround, and not a viable solution in the long-term.
Hi,
Signing in to Bulwark through Stalwart can’t send you on to your SSO provider. Stalwart’s own authorization server only signs users in against Stalwart and doesn’t act as a broker for an upstream identity provider, so once a domain is served by an OpenID Connect directory its tokens have to come from that provider. The login form you get there is meant for local accounts and the recovery administrator.
That leaves Bulwark talking to your provider directly, which you already have working. What’s missing is full access for its tokens. A token from the provider gets the account’s full permissions in two cases: its client claim (azp, client_id and similar) matches the oauthClientId of an Application installed on the server, or it carries none of the mail, contacts, calendars and files scopes and the directory has unscopedTokens set to full. The stub application from the Bulwark issue works through the first case. It does the job, but an Application needs a real bundle to download and serve, so I wouldn’t build on it.
The second case is the one I’d use. Set unscopedTokens to full and keep skipAudienceValidation off. Then, at your provider, give Bulwark’s client an audience of its own (in Keycloak that’s an audience mapper on the client) and list only that value in acceptedAudiences. Tokens issued to Bulwark get full access, and tokens issued to other applications at the provider are refused because their audience doesn’t match. The tradeoffs are described here: OpenID Connect | Stalwart
The first-party OAuthClient you created in Stalwart only applies to sign-ins through Stalwart’s own authorization server, so you can delete it unless the recovery administrator or local accounts sign in to Bulwark through it.
Hi,
Stalwart’s own authorization server only signs users in against Stalwart itself, so it never sends you on to your external provider. That’s why the first-party client route ended at a password form. With an OIDC directory, Bulwark’s tokens have to come from your provider, and until now those tokens could only carry the mail, contacts, calendars and files scopes, none of which reach app passwords or the other account settings.
The next weekly Stalwart release adds three Stalwart scopes that external tokens can carry:
urn:stalwart:oauth:scope:security: password, 2FA, app passwords, API keys and connected apps
urn:stalwart:oauth:scope:settings: account settings, encryption and public keys
urn:stalwart:oauth:scope:full: everything the account may do, administration included
A scope never gives an account more than its own permissions. To use them, create the scopes at your provider under exactly these names, assign them to Bulwark’s client there as optional scopes, and make sure the provider lists them in its scopes_supported metadata. Bulwark then has to request them when it signs in, which needs a change in Bulwark; the issue you linked is the place to ask for it. App passwords created through a security token are limited to the permissions that token holds, so if Bulwark creates them with the account’s full permissions, it needs full.
The firstParty flag on OAuth clients is gone in the same release, replaced by these scopes. The stub Application with Bulwark’s client id keeps working, but it gives every token carrying that client id full access; the scopes let you decide exactly what Bulwark gets.