Authenticate Harbor with Keycloak via OIDC

Secure your Harbor registry using Keycloak as an OpenID Connect (OIDC) identity provider. This guide walks you through configuring Keycloak and Harbor for single sign-on (SSO), and Docker CLI access.


Prerequisites

  • Keycloak accessible at: https://keycloak.maksonlee.com
  • Harbor instance at: https://harbor.maksonlee.com
  • A Keycloak realm (e.g. maksonlee.com)
  • HTTPS configured for both services

  1. Create a Client in Keycloak

In your Keycloak realm:

  • Navigate to Clients → Create client
  • Use these general settings:
FieldValue
Client typeOpenID Connect
Client IDharbor
Nameharbor
  • Click Next and configure capabilities:
CapabilityValue
Client authenticationOn
AuthorizationOff
Standard flowEnabled
All others (CIBA, Token Exchange, Device Grant, etc.)Disabled
  • Login Settings
FieldValue
Root URLhttps://harbor.maksonlee.com
Valid redirect URIshttps://harbor.maksonlee.com/c/oidc/callback
Valid post logout redirect URIs(optional)
Web originshttps://harbor.maksonlee.com
  • Click Save.

After Saving: Get the Client Secret

  • Open the harbor client
  • Go to the Credentials tab
  • Copy the Client Secret — needed in Harbor

  1. Configure Harbor for OIDC

In Harbor’s web UI:

  • Go to Administration → Configuration → Authentication
  • Set the following:
FieldValue
Auth ModeOIDC
Primary Auth ModeEnable
OIDC Provider Namekeycloak
OIDC Endpointhttps://keycloak.maksonlee.com/realms/maksonlee.com
OIDC Client IDharbor
OIDC Client Secret(from Keycloak)
OIDC Scopeopenid,profile,email
Username Claimpreferred_username
Verify CertificateYes
Automatic OnboardingYes
OIDC Session LogoutOptional

  1. Log In via Keycloak

Visit https://harbor.maksonlee.com. The login screen should now show:

Click LOGIN WITH keycloak to sign in.

  • Users are redirected to Keycloak for authentication
  • First-time users are auto-onboarded (if enabled)

  1. Docker CLI Authentication & CLI Secret

Harbor does not allow you to use your Keycloak password or token directly in docker login. Instead, you must manually generate a CLI Secret from the web UI.

How to Get the CLI Secret

  • Log in to Harbor via the UI using OIDC
  • Click your username (top-right corner) → User Profile
  • Go to the Account Settings tab
  • Click Generate next to CLI Secret
  • Copy the generated secret

Use it in the Docker CLI:

docker login harbor.maksonlee.com
Username: <your OIDC username>
Password: <CLI Secret>

The secret is base64-encoded and stored in ~/.docker/config.json after login.

CLI Behavior

ScenarioResult
CLI login with CLI Secret✅ Works
Harbor restarts or token expires❌ Harbor loses OIDC token, CLI login fails
CLI Secret still valid✅ You do not need to re-generate it
Fix✅ Re-login via Harbor Web UI to refresh the backend token
Best for automation❌ Not ideal — use Robot Accounts for CI/CD

For official instructions on CLI login with OIDC, see:
Harbor OIDC Authentication Docs – Docker CLI Login

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top