Your question
I’ve updated Stalwart to 1.0 and the Bulwark client 1.19.1
From a user standpoint, everything is working great. But I bumped into something funny.
For Bulwark to be able to enable admin permissions to a user, it needs to now use an internal oauth-client in Stalwart. That’s fine, I made that, pointed the Bulwark at that instead of my Keycloak. However, when I try to then log in, it seems to only recognize the internal directory within Stalwart, and is not forwarding to my external Keycloak OIDC login page. Nor is there an option to log in via SSO.
Contextual Info:
Stalwart, with its own keycloak client for OIDC
Bulwark, with its own keycloak client for OIDC, and tried an internal oauth-client in stalwart.
Both are set to auto-forward to SSO login pages. Neither allow local-user login to themselves.
And, as I did not read the docs. I updated Stalwart first, and then went to do Bulwark and the first line was “do bulwark first”. My bad.
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 never brokers sign-ins for an external OIDC provider, so an internal OAuth client can’t forward users to Keycloak. This is how the docs describe it, not something I’ve confirmed against Bulwark’s behaviour.
An internal OAuthClient is served by Stalwart’s own authorization server, which shows Stalwart’s own sign-in. The Keycloak directory is only a resource server setup: Stalwart validates the tokens Keycloak issues and maps them to accounts. It doesn’t redirect anyone to Keycloak. The docs say that when a client authenticates via an OIDC directory, the application has to talk to the provider directly. That matches what you’re seeing, where Bulwark pointed at the internal client only offers the internal directory.
To get Keycloak login together with admin permissions, Bulwark would need to keep using its own Keycloak client. Stalwart would then have to grant the resulting token full permissions. The docs describe three ways a valid token from an OIDC directory gets access:
- If the token’s client claim (
azp, client_id, cid or appid) equals the oauthClientId of an installed Application, it gets the account’s full permissions.
- If the token carries interoperable scopes (mail, calendars, contacts, files), it is limited to those.
- If it carries neither, the directory’s
unscopedTokens setting decides. It defaults to reject. full grants every permission, including management. The docs warn this is unsafe unless the audience check is strict.
Check these on your Keycloak directory in Stalwart:
acceptedAudiences must contain the aud value Keycloak puts in Bulwark’s access tokens.
claimUsername and usernameDomain must map the token to the right account.
- Bulwark’s tokens must reach the permission level you want through one of the three routes above.
Whether Bulwark’s admin features work with a Keycloak token is a question about Bulwark itself. The Stalwart docs don’t cover it, so a community member may need to confirm that part.
Relevant docs:
Updating Stalwart before Bulwark is unlikely to be the cause of this particular behaviour.
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.
Sadly I am not a fan of lowering the audience checking. I’ll just keep using the admin login in Bulwark, and maybe see if we can get a “admin” scope check added for tokens so that I don’t need to use an internal oauth client in Stalwart.
Hi,
The internal OAuth client can’t forward to Keycloak because Stalwart’s own authorization server only signs users in against Stalwart itself; it doesn’t act as a broker for an upstream identity provider. Once your domain is served by the Keycloak directory, tokens for that domain have to come from Keycloak.
Admin access with Keycloak tokens doesn’t require relaxing the audience check. A token from Keycloak gets the account’s full permissions (management included, if the account has them) when it carries none of the interoperable mail/calendars/contacts/files scopes and the directory has unscopedTokens set to full. Keep skipAudienceValidation off and list in acceptedAudiences only the audience Keycloak puts in Bulwark’s tokens, ideally one added with an audience mapper on Bulwark’s Keycloak client so no other client’s tokens carry it. Bulwark can then stay on its Keycloak client. The tradeoffs are described here: OpenID Connect | Stalwart
A dedicated admin scope would be a nice addition; if you’d like to see it, please post it in Feature Ideas - Stalwart Support
Yea, I got to the same solution, so at least I can read the docs well enough. I just really didn’t like using the “unsafe” tagged option. Was trying to jury-rig some way to make it work otherwise. I think I will go suggest it there. If we can get Stalwart to check external-oauth client scopes for admin like it does for files, calendar, mail, and contacts, we could more easily lock down administrative controls. Though I do also like having to tag it internal to Stalwart too. Leave all the checks in place.
Hi,
The admin scope you were after is in the next weekly Stalwart release, along with a couple of narrower ones. Keycloak tokens can carry urn:stalwart:oauth:scope:full, which gives the token everything the account may do, administration included, without unscopedTokens = full. There are also urn:stalwart:oauth:scope:security (passwords, 2FA, app passwords, API keys, connected apps) and urn:stalwart:oauth:scope:settings (account settings, encryption and public keys) for clients that only manage the user’s own account. They’re always limited by the account’s permissions, and the audience check stays as strict as you have it now.
On the Keycloak side, create them as client scopes named exactly like that and add full only to Bulwark’s client, as an optional scope. Never make it a default scope of the realm, because any client that can obtain it gets the same access. Check that Keycloak lists them in its scopes_supported metadata, since Bulwark only requests scopes the issuer advertises. Bulwark has to request them when it signs in, which needs a change on Bulwark’s side. Once that’s in place, unscopedTokens can go back to reject or interoperable.
The same release removes firstParty from internal OAuth clients; the scopes replace it.
Oh. That’s wonderful! I appreciate the tag here to let me know it’s coming out.