-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Portainer OAuth login not working with Authentik #8187
Comments
I am not sure if it is related, my authentication configured with github, it was working till yesterday, now while I am trying to authenticate, getting same error. I have tried replacing new client secret, but still same issue. Not sure what happened. |
Ok weird, have you upgraded authentik or portainer to a new version before that happend? |
This was related to DNS resolution issue from my docker container, after fixing DNS issue, I am able to logon using GitHub. |
Ok great, at least one does work 😄. |
Does anyone have the same issue? |
I use authentik OAuth in portainer and have had no issues with it. |
@TMUniversal @Videothek Thanks! |
I've simply followed the steps layed out in the authentik documentation (https://goauthentik.io/integrations/services/portainer/#step-2---portainer):
|
Also, @Videothek, I've noticed that your logout URL differs from what I use (and what it says in the documentation). |
Thanks for your reply. I have put the scopes as described in the documentation. I also have copied the link form my Authentik instace, so this should be fine i guess. So i guess you implemented the SSO without issues? |
Yes, it has been working well for me, through several version upgrades of both portainer and authentik. |
Ok, i guess i have to look into my config or its maybe just a bug. |
I checked my configuration and confirmed that i have set it up just like it shows in the documentation on the authentik website. So if someone have any idea left what this issue could be, i would be very happy 😄. |
Hi there, |
I have not. Although I've confirmed that these also work. Here are my settings, just don't turn on |
Yes sure, my config looks like this: So it seems pretty similar. |
Hi Everyone, I seem to be having this issue as well. It seems from what I can see, that Portainer never calls the Access token URL. Is it possible Authentik isn't formatting the Redirect URL quite right? This is how Portainer receives the auth code for my config: https://docker.-removed-/?code=[-CODE-]&state=e1f8b3cc-fc3c-4491-b44b-514585c115a3#!/auth |
Seems unlikely, since it works for me. Could you provide your authentik and portainer versions, please? Also have a look at my above comment: #8187 (comment) , you may want to add the logout URL. This probably won't fix your problem, but it allows you to log out of both portainer and authentik, or log back in when portainer times out your session. |
Authentik: 2022.12.1 I'll review my Authentic flows maybe, as I have tested Google Auth without issue. I have tested the api using postman and could retrieve the profile that way from Authentik. Edit: On some poking around, I see this 500 error from Portainer, does this suggest anything I need the amend? |
I had the same problem and spend way too much time debugging it. My problem (maybe you have the same issue) is the traefik default certificate, which I use for authentik. Line 64 in 3625ab6
Starting portainer with the cli param "--log-level DEBUG" (yes, this isn't documented!) shows the following entries in the log:
I'm going to replace the certificate with one from lets encrypt and hope, that it will work :) |
I'm not sure how to set the flags within the docker container to troubleshoot further. I have now installed a Let's Encrypt cert and it didn't change anything on my side. Let us know how you get on. |
Yes, please do. I hadn't caught this possibility, but it's not surprising that Portainer would refuse to connect to authentik when the certificate is not valid. Either try an unencrypted connection (just don't use in production), or use a valid certificate. Let me know if you need more details on this, I have traefik set up to do this. Looking forward to hearing about your results! @fredmorais, are you using a valid SSL certificate on your authentik server? |
That's unfortunate, I'd hoped this would work. services:
portainer:
image: portainer/portainer-ee:2.16.2
# Portainer does not require an executable name here, other images might.
command: --log-level DEBUG # ... other cli args |
Yes, thats the way to go! After I changed the default certificate to an lets encrypt certificate it works! Hope this helps some of you! If not you can try to debug it further using the "--log-level" settings :) |
Update from me: |
So i finally got around to look at this issue again. So in my opinion it should be possible to trust self signed certs for local use. Because not everybody wants to publish their portainer login or use "real" fqdns for their local services. Maybe some dev from portainer could look into this? Or just answer this thread why this isnt or shouldnt be possible. Thank you in adnvance 😄. |
Unfortunately, the URL for Portainer does not matter. I've had it set up so that authentik is reachable on a FQDN, while Portainer was accessible locally via its IP Address, although still using https (portainer self-signed). So authentik would be on This configuration worked for me, but I've since put Portainer on a locally accessible fqdn, via a local dns entry. Does this resemble your setup? |
Same issue here, just using caddy, which generates its own self cert. |
Seems like we've got this issue figured out. Portainer rejects self-signed certificates by default, but has no mechanism to trust any / the specific certificate. My solution to this has been to use a LetsEncrypt certificate for my authentik instance, which you can achieve without making your instance public. To do this, you will have to own a domain, and use a dns challenge to get the certificate (certbot/traefik will create a txt entry through your dns provider), since LetsEncrypt won't be able to access your instance. |
So I'm using Authentik,Traefik,PiHole and Portainer on a Proxmox host. |
@Forsskieken try to add the |
Thanks I did and indeed I see some errors... Where is this authorisation token generated or placed? |
I've installed a letsencrypt wildcard certificate to authentik but still oauth did not work. Only fix was removing the |
That doesn't sound like what you would want. |
I've managed to make it work with a self-signed certificate (and a .home TLD) by trusting the CA that created the certificate (in this case my own CA) inside the container. The host machine that is running my containers already trusts my CA so I managed to solve the problem by mounting the existing You can simply do this by adding this line to the volumes part of the docker-compose file of the Portainer setup: Please note that this does require your host machine to already trust the CA that created the certificate. |
This issue has been marked as stale as it has not had recent activity, it will be closed if no further activity occurs in the next 7 days. If you believe that it has been incorrectly labelled as stale, leave a comment and the label will be removed. |
Since no further activity has appeared on this issue it will be closed. If you believe that it has been incorrectly closed, leave a comment mentioning |
Did you resolve this? I am having the exact same issue. It seems that there isn't a route between Portainer and the host machine, but I'm not sure, and the only solution I'm able to find is to use the Authentik server's name instead of the FQDN, which didn't even work for me. |
I've had a similar issue where there was a NAT loopback issue and log level debug has helped as I have recognized the SSL CN from my router rather than the one traefik uses. |
I was getting a "Error: Unauthorized" but after turning "automatic user provisioning" on, I could log in. |
Hi, i'm trying to use the username in Portainer instead of the email address. But how can I use the username as user identifier? I tried user and username but it doesn't work. |
wolfgang posted a lets encrypt for local homelab setting. downside is he uses nginx proxy manager, whereas i am using traefik. i tested it and it does work. u also get valid certs and no longer told its insecure. but i wanted to get this to work for traefik unfortunately. i can however verify for you that the certificate issue is resolved when trying to login to portainer using oauth authentik (i tested and confirmed this myself). If you want to try that instead. but i also 2nd an option to allow makecert certificates for a local lan homelab environment please. |
did you find a way to fix this, I'm having exactly the same issue |
@Forsskieken, @ElectricityMachine, @amour86
I removed the field, restarted the docker daemon and could authenticate to portainer |
Hello, this issue has a final solution? I've exactly the same issue explained in the first post after two years. I've follow the documentation step by step and everything looks good. Authentik and Portainer can be accessed from internet via nginx proxy manager, both instances are published with Let's Encrypt valid certificates. I'm not an expert but Authentik confirm the Application authorized bit Portainer doesn't allow the login. Thanks for the help. |
Hello quincarter, thanks for the hint, just a question, as far as I've untderstood, on your setup both dockers, authentik and portainer are on the same docker virtual network? |
update, solved installing a valid public certificate... |
Yes this is correct |
It appears there are many things that can cause this behavior. Using the debug command and checking portainer's logs can help narrow it down (added command --log-level=DEBUG to my docker compose). In my case, Portainer couldn't resolve the access and resource URLs (had 127.0.0.11:53 server is misbehaving entries). If that's the case for you, please see below. I resolved it by only changing the beginning of Portainer's access token and resource urls (similar to quincarter). I made both entries start with "http://authentik-server:9000/". "authentik-server" is my container's name and runs on port 9000 by default. I use Traefik, so I dont have any conflicts between Authentik and Portainer. So you would need to use yours in that place. I guess Portainer couldn't resolve the https entries from Authentik and it can by using the container's name and port via http. Hope this helps anyone still having this issue. |
Hi everyone. I've been having the same issues as noted throughout this thread, and found a solution. Having read every single comment above mine, I realise this might not be the answer for everyone, but it is something other people can consider trying. At the end of this guide for setting up Authentik with Portainer, the last line of step 3 includes the Launch URL. I foolishly glossed over this when I was creating the application in Authentik (because the Authentik interface says "If left empty, authentik will try to extract the launch URL based on the selected provider.", so I incorrectly assumed it'd just work if left empty). To be clear, I am using Authentik with Traefik with a Lets Encrypt certificate already. I also have an FQDN defined for Portainer and Authentik in my Pi-Hole instance, which is also running on the same Docker host. I realise this is just "RTFM", but hopefully it helps someone else in future... |
After frustrating days of fruitless research I finally found this comment and it worked for me, too! 👍 I checked the logs of portainer (--log-level=DEBUG) and found this: DBG github.com/portainer/portainer/api/http/handler/auth/authenticate_oauth.go:76 > OAuth authentication error | error="Post "https://authentik.mydomain.com/application/o/token/\": dial tcp: lookup authentik.mydomain.com on 127.0.0.11:53: no such host" So I modifying the following access token and resource urls in the portainer authentication settings to http and using the docker container names: Now the authentication works and the portainer web interface opens. However, this feels like a workaround, and I still don't quite understand the root cause of the problem. Why can portainer/authentik not handle https and the FQDN for the token and resource urls? Is there an issue with the traefik or pihole configs? By the way, I still get this error=Unauthorized from the portainer logs: Any ideas how to solve this for good? |
Hello For those who still have this issue with the missing token and the 401 error I found out it was a DNS issue as mentioned by @iAmSaugata I helped me from those two links: Here is how I was able to fix this.
Some people might said it's not a good practice to associate a static ip address to a container but I didn't find a better trade off for now. Then I had a file into the following path: Lastly edit /etc/docker/daemon.json, append dns config (create it if it doesn't exist):
The 8.8.8.8 and 8.8.4.4 are for google dns resolution And the SSO with Authentik for Portainer should work fine (it worked for me 😄 ) |
Hello, i tried to enroll OAuth for Portainer.
I created the entries in my SSO Service as described in the documentation.
I am using Authentik, thats why i were following this link.
I also read through the portainer guide but couldnt get it to work by now.
When i am trying to login to Portainer with OAuth, i am getting the following error:
Portainer returns an 500 error code:
My configuration looks like this:
I have also read through many posts about this error but nothing helped in my case.
Would be great if someone could assist me with fixing this error.
Thank you in adnvace 😄.
The text was updated successfully, but these errors were encountered: