portainer: Unauthorized with SSO Custom OAuth
Bug description Hello! I am having an issue getting my custom OAuth provider to successfully authenticate with Portainer. Currently when I attempt to click the Login button, it does forward me to my OAuth provider. But when I enter my credentials (which are valid), it sends me back to Portainer and then gives an unauthorized error (see logs below).
Expected behavior I can login with SSO using my custom OAuth provider.
Portainer Logs
There are no relevant logs when I check docker logs
.
Here is the error from Chrome:
{
"data": {
"message": "Unable to authenticate through OAuth",
"details": "Unauthorized"
},
"status": 500,
"config": {
"method": "POST",
"transformRequest": [
null
],
"transformResponse": [
null
],
"jsonpCallbackParam": "callback",
"ignoreLoadingBar": true,
"data": {
"code": "de6d660187cc43c5ae6260d1f9b9821a"
},
"url": "api/auth/oauth/validate",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json"
}
},
"statusText": "",
"xhrStatus": "complete",
"resource": {
"code": "de6d660187cc43c5ae6260d1f9b9821a"
}
}
Steps to reproduce the issue:
- Setup a custom OAuth provider
- Attempt to login.
Technical details:
- Portainer version: Portainer CE 2.16.2
- Docker version (managed by Portainer): Docker version 20.10.22, build 3a2c30
- Platform (windows/linux): Linux
- Command used to start Portainer (
docker run -p 9443:9443 portainer/portainer
): Compose File:
portainer:
image: portainer/portainer-ce:2.16.2-alpine
environment:
- PGID=1000
- PUID=1000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /docker/portainer:/data
- /etc/ssl/certs:/etc/ssl/certs # Used to pass in custom CA
deploy:
restart_policy:
condition: any
networks:
- default
- Browser: Chrome 108.0.5359.124 (Official Build) (x86_64)
- Have you reviewed our technical documentation and knowledge base? Yes
Additional context
Here is my OAuth configuration in Portainer:
- Client ID: redacted
- Client secret: redacted
- Authorization URL: https://my-oauth-url.my-domain.tld/openid/authorize
- Access token URL: https://my-oauth-url.my-domain.tld/openid/token
- Resource URL: https://my-oauth-url.my-domain.tld/openid/userinfo
- Redirect URL: https://my-portainer-url.my-domain.tld
- Logout URL: https://my-oauth-url.my-domain.tld/openid/logout
- User identifier: username
- Scopes: openid profile email groups
I do have one more question, what should my callback url be in my OAuth provider? Currently I just used the url of my Portainer instance (e.g. https://my-portainer-url.my-domain.tld reference above in the Redirect URL). Is this correct?
Hopefully someone can provide some help, as I am stumped. I have used this OAuth provider with other applications and not run into this problem, so it seems to either be a configuration with Portainer that I have wrong, or something wrong on the OAuth side like the callback URL.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 16
For someone using Keycloak
If using keycloak, make sure that “Client Authentication” in client settings is enabled. This way you will be able to get a “Client Secret” from the “Credentials” tab in client settings that will be needed later in Portainer.
Use the following settings:
your-client-id
your-secret
port
/realms/your-realm
/protocol/openid-connect/authport
/realms/your-realm
/protocol/openid-connect/tokenport
/realms/your-realm
/protocol/openid-connect/userinfoport
/realms/your-realm
/protocol/openid-connect/logout?redirect_uri=your-portainer-url-encoded
email
openid profile email
Ok I now have this working. Using the undocumented
DEBUG
log level and a hint that it was certificate related from this issue, I was able to find out that it is giving me an X509 error. This is because the cert for my OIDC provider has been signed by a custom CA.So my solution is two fold:
SSL_CERT_FILE
to point to my custom CA.SSO now works perfectly.
@xpac1985 I am not sure if this is the same problem you are having. If this doesn’t solve your issue you may want to open a new ticket.
Hello @joe-eklund
I also think, that the Scope and User Identifier is not configured properly. I am pretty sure that “username” is invalid as User Identifier. Please take a look at the Keycloak documentation.
Please try the following:
If this works then you can start playing around with the user identifier.