Give scripts and CI their own credentials, either created in your identity provider or registered by Self-Hosted Base through OAuth 2.0 Dynamic Client Registration.

OAuth apps

An OAuth app is a client ID and secret that scripts and CI use instead of a person’s sign-in. It gets a token with the client credentials grant, and Self-Hosted Base treats requests with that token as the app: the app has its own role, and runs it starts are attributed to it.

Choose who creates apps with apps.provider:

apps.provider Apps are created Use when
none (default) In your identity provider, by its admins Your IdP doesn’t support Dynamic Client Registration, or you manage clients there anyway.
dcr By users, through Self-Hosted Base Your IdP lets applications create and manage OAuth clients through an API, such as Keycloak.

Either way, the proxy in front of Self-Hosted Base must accept the apps’ tokens. See Authentication.

Apps created in your IdP (none)

Create a client with the client credentials grant in your IdP, and use its ID and secret. Creating, listing, or deleting apps through Self-Hosted Base, from the CLI or the UI, fails with FAILED_PRECONDITION and says apps are managed in your identity provider. Clients you created in the IdP still authenticate through the proxy.

With authorization on, an app is identified by the subject its tokens carry, and gets authz.defaultRole the first time it makes a request.

Apps registered by Self-Hosted Base (dcr)

This needs OAuth Dynamic Client Registration (RFC 7591) and client management (RFC 7592) at your IdP. Self-Hosted Base registers the client at your IdP and returns its secret once. Self-Hosted Base keeps each app’s ID, name, creator, and the credentials it needs to manage the client, in its database. It doesn’t keep the secret. Deleting an app deletes the client at the IdP.

Keycloak

  1. Make every token carry the audience your proxy checks. Create a client scope with an audience mapper (for example audience selfhosted-base) and add it to the realm’s default client scopes, so dynamically registered clients get it too.

  2. Create an initial access token for client registration (Realm settings → Client registration → Initial access token, or kcadm.sh create clients-initial-access -r <realm> -s count=1000 -s expiration=0), and store it:

    kubectl -n union create secret generic selfhosted-base-dcr --from-literal=token='<initial access token>'
  3. Configure Self-Hosted Base:

    apps:
      provider: dcr
      dcr:
        registrationEndpoint: https://<keycloak>/realms/<realm>/clients-registrations/openid-connect
        initialAccessToken:
          existingSecret: selfhosted-base-dcr

    Leave apps.dcr.scope unset on Keycloak. Keycloak then gives each registered client the realm’s default client scopes, including the audience scope from step 1. A scope set here becomes the client’s only scope, and Keycloak adds it to a token only when the token request asks for it, so the SDK’s app sign-ins would get tokens without the audience.

  4. Let oauth2-proxy accept the apps’ tokens: --oidc-extra-audience=<audience> and --insecure-oidc-allow-unverified-email=true, since client-credentials tokens have no email.

Use an app

Create it as a user who may manage apps (an admin with authorization on). The response carries the secret, once. Then run with it:

import flyte

flyte.init(
    endpoint="dns:///<host>",
    auth_type="ClientSecret",
    client_id="<client id>",
    client_credentials_secret="<client secret>",
    org="onebox", project="default", domain="development",
)

Requests with the app’s token act as the app. The proxy verifies the token and tells Self-Hosted Base who the caller is, and Self-Hosted Base recognizes a registered app by what the proxy reports: a subject that is the app’s client ID (Okta; Auth0’s <client id>@clients), or Keycloak’s service-account-<client id> username. Self-Hosted Base doesn’t read the token itself.

Gotchas

Symptom Cause and fix
Creating an app fails with PERMISSION_DENIED from the identity provider The initial access token is missing, expired, or used up. Create a new one.
An app’s token is redirected to the IdP The proxy doesn’t accept it. See the oauth2-proxy troubleshooting in Authentication.
Runs by an app show as a user The proxy reports an identity Self-Hosted Base doesn’t recognize as the app, or an email (users have one, apps don’t). Check the headers the proxy sets: the subject should be the client ID, or on Keycloak the preferred username service-account-<client id> (oauth2-proxy sends it in X-Forwarded-Preferred-Username with --pass-user-headers).