semaphore: v2.9.56 breaks oidc auth with keycloak

When updating from v2.9.45 to v2.9.56, our existing integration with keycloak breaks.

The error shown in the docker logs is time="2024-03-24T17:38:23Z" level=error msg="oauth2: \"invalid_grant\" \"Code not valid\"". On the UI side, signing in with SSO just returns you to the login page but does not actually log the user in.

A downgrade to 2.9.45 fixes the issue.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 39 (1 by maintainers)

Most upvoted comments

Thank you @fiftin. Very generous of you to provide this quick solution. adding the redirect_url fixed it. Just curious how is it different from omitting the redirect_url and letting it use the default as suggested in the doc: ${web_host}/api/auth/oidc/${provider}/redirect, shouldn’t this expand to the same value as long as web_host is defined correctly? did the behaviour of the default values changed in the newer versions?

i’ve in my config: web_host: https://semaphore.example.com redirect_url: https://semaphore.example.com/api/auth/oidc/okta/redirect

@rsch136 looks like you have broken config. Please check that you have cookie_hash in your config file or SEMAPHORE_COOKIE_HASH environment variable. It must be generated by command head -c32 /dev/urandom | base64.

Sorry @fiftin deployment is done and the service has been restarted. It’s also fixed now for us. Thanks for your work.

@fiftin sorry for the delay. I copied the relevant error from our authentik-backend:

{
    "message": "Invalid redirect URI used by provider",
    "expected": [
        "https://automation.XXX.de/api/auth/oidc/XXX-authentik/redirect/"
    ],
    "provider": {
        "pk": 7,
        "app": "authentik_providers_oauth2",
        "name": "automation.XXX.de",
        "model_name": "oauth2provider"
    },
    "http_request": {
        "args": {},
        "path": "/application/o/token/",
        "method": "POST",
        "user_agent": "Go-http-client/2.0"
    },
    "redirect_uri": "https://automation.XXX.de/api/auth/oidc/XXX-authentik/redirect//api/auth/oidc/XXX-authentik/redirect"
}
User
{
    "pk": 1,
    "email": "",
    "username": "AnonymousUser",
    "is_anonymous": true
}

I’m just deploying the new version of ansible-semaphore to check if it is already fixed.

I have updated to 2.9.65 and all is working fine for me

@rsch136 looks like you have broken config. Please check that you have cookie_hash in your config file or SEMAPHORE_COOKIE_HASH environment variable. It must be generated by command head -c32 /dev/urandom | base64.

@fiftin we were following this docu: https://docs.semui.co/administration-guide/openid

Didn’t previously have any issue with cookie hashes. Do you have a link?

@mhzawadi, @fiftin - yes, regular login with user and password. No OpenId.

My semaphore config below, then screen grabs of Keycloak. let me know if you need anything else

   "oidc_providers":{
      "horwood":{
         "display_name":"Sign in with keycloak",
         "provider_url":"https://keycloak/realms/PVE01",
         "client_id":"semaphore-real",
         "client_secret":"SECRETKEY",
         "redirect_url": "https://semaphore/api/auth/oidc/horwood/redirect"
      }
   },
image image image

Hmm everything over v2.9.45 seems to also break oidc with authentik as IDP. Here is the relevant part of our config.json

"oidc_providers": {
        "XXX": {
            "display_name": "Authentik",
            "provider_url": "https://authentik.XXX.de/application/o/XXX/",
            "client_id": "XXX",
            "client_secret": "XXX",
            "redirect_url": "https://automation.XXX.de/api/auth/oidc/XXX/redirect/",
            "scopes": ["openid", "profile", "email"],
            "username_claim": "preferred_username",
            "name_claim": "preferred_username"
            }
        },