> ## Documentation Index
> Fetch the complete documentation index at: https://www.c1.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up a Keycloak connector

> C1 provides identity governance for Keycloak. Integrate your Keycloak instance with C1 to run user access reviews (UARs) and enable just-in-time access requests.

## Availability

This connector supports Keycloak versions up to v22.0.5.

## Capabilities

| Resource  | Sync                                                                     | Provision                                                                |
| :-------- | :----------------------------------------------------------------------- | :----------------------------------------------------------------------- |
| Accounts  | <Icon icon="square-check" iconType="solid" color="#c937ae" />            |                                                                          |
| Groups    | <Icon icon="square-check" iconType="solid" color="#c937ae" />            | <Icon icon="square-check" iconType="solid" color="#c937ae" />            |
| Subgroups | <Icon icon="square-check" iconType="solid" color="#c937ae" /> (optional) | <Icon icon="square-check" iconType="solid" color="#c937ae" /> (optional) |

## Gather Keycloak credentials

Configuring the connector requires you to pass in credentials generated in Keycloak. Gather these credentials before you move on.

<Warning>
  A user with admin access to the Keycloak realm you're integrating with C1 (specifically, the user must have the `manage-clients` role) must perform this task.
</Warning>

### Create a Keycloak client

<Steps>
  <Step>
    In the Keycloak Admin Console, navigate to **Clients**.
  </Step>

  <Step>
    Make sure you're in the correct realm, then click **Create client**.
  </Step>

  <Step>
    Choose a **Client ID** for the client. Save this ID, as we'll use it during the connector setup process.
  </Step>

  <Step>
    Fill out the rest of the client registration form. Make sure to enable **Client authentication**.
  </Step>

  <Step>
    Save your client configuration.
  </Step>

  <Step>
    On the new client's **Credentials** tab, carefully copy and save the **Client secret**.
  </Step>

  <Step>
    Navigate to **Clients** and click the **Clients List** tab, then click the name of your new client.
  </Step>

  <Step>
    On the client's **Settings** tab, scroll down to the **Authentication flow** section and enable **Service accounts roles**.
  </Step>

  <Step>
    Next, move to the client's **Service Account Roles** tab.
  </Step>

  <Step>
    Click **Assign role** and select **Client roles**.
  </Step>

  <Step>
    Assign the following roles to the client:

    * account view-groups
    * `<realm>` manage-users
  </Step>

  <Step>
    Finally, make a note of your Keycloak realm and server URL.
  </Step>
</Steps>

**Done.** Next, move on to the connector configuration instructions.

## Configure the Keycloak connector

<Warning>
  To complete this task, you'll need:

  * The **Connector Administrator** or **Super Administrator** role in C1
  * Access to the set of Keycloak credentials generated by following the instructions above
</Warning>

<Tabs>
  <Tab title="Cloud-hosted">
    **Follow these instructions to use a built-in, no-code connector hosted by C1.**

    <Steps>
      <Step>
        In C1, navigate to **Integrations** > **Connectors** and click **Add connector**.
      </Step>

      <Step>
        Search for **Keycloak** and click **Add**.
      </Step>

      <Step>
        Choose how to set up the new Keycloak connector:

        * Add the connector to a currently unmanaged app (select from the list of apps that were discovered in your identity, SSO, or federation provider that aren't yet managed with C1)

        * Add the connector to a managed app (select from the list of existing managed apps)

        * Create a new managed app
      </Step>

      <Step>
        Set the owner for this connector. You can manage the connector yourself, or choose someone else from the list of C1 users. Setting multiple owners is allowed.

        If you choose someone else, C1 will notify the new connector owner by email that their help is needed to complete the setup process.
      </Step>

      <Step>
        Click **Next**.
      </Step>

      <Step>
        Find the **Settings** area of the page and click **Edit**.
      </Step>

      <Step>
        Paste the Keycloak credentials you gathered into the relevant fields.
      </Step>

      <Step>
        Click **Save**.
      </Step>

      <Step>
        The connector's label changes to **Syncing**, followed by **Connected**. You can view the logs to ensure that information is syncing.
      </Step>
    </Steps>

    **Done.** Your Keycloak connector is now pulling access data into C1.
  </Tab>

  <Tab title="Self-hosted">
    **Follow these instructions to use the Keycloak connector, hosted and run in your own environment.**

    When running in service mode on Kubernetes, a self-hosted connector maintains an ongoing connection with C1, automatically syncing and uploading data at regular intervals. This data is immediately available in the C1 UI for access reviews and access requests.

    ### Resources

    * [Official download center](https://dist.conductorone.com/ConductorOne/baton-keycloak): For stable binaries (Windows/Linux/macOS) and container images.

    * [GitHub repository](https://github.com/conductorone/baton-keycloak): Access the source code, report issues, or contribute to the project.

    ### Step 1: Set up a new Keycloak connector

    <Steps>
      <Step>
        In C1, navigate to **Integrations** > **Connectors** > **Add connector**.
      </Step>

      <Step>
        Search for **Baton** and click **Add**.
      </Step>

      <Step>
        Choose how to set up the new Keycloak connector:

        * Add the connector to a currently unmanaged app (select from the list of apps that were discovered in your identity, SSO, or federation provider that aren't yet managed with C1)

        * Add the connector to a managed app (select from the list of existing managed apps)

        * Create a new managed app
      </Step>

      <Step>
        Set the owner for this connector. You can manage the connector yourself, or choose someone else from the list of C1 users. Setting multiple owners is allowed.

        If you choose someone else, C1 will notify the new connector owner by email that their help is needed to complete the setup process.
      </Step>

      <Step>
        Click **Next**.
      </Step>

      <Step>
        In the **Settings** area of the page, click **Edit**.
      </Step>

      <Step>
        Click **Rotate** to generate a new Client ID and Secret.

        Carefully copy and save these credentials. We'll use them in Step 2.
      </Step>
    </Steps>

    ### Step 2: Create Kubernetes configuration files

    Create two Kubernetes manifest files for your Keycloak connector deployment:

    #### Secrets configuration

    ```yaml expandable theme={"theme":{"light":"css-variables","dark":"css-variables"}}
    # baton-keycloak-secrets.yaml
    apiVersion: v1
    kind: Secret
    metadata:
      name: baton-keycloak-secrets
    type: Opaque
    stringData:
      # C1 credentials
      BATON_CLIENT_ID: <C1 client ID>
      BATON_CLIENT_SECRET: <C1 client secret>
      
      # Keycloak credentials
      BATON_KEYCLOAK_CLIENT_ID: <Keycloak client ID>
      BATON_KEYCLOAK_CLIENT_SECRET: <Keycloak client secret>
      BATON_KEYCLOAK_REALM: <Realm of the Keycloak server>
      BATON_KEYCLOAK_SERVER_URL: <Keycloak server URL (defaults to https://keycloak.com/)>

      # Optional: include if you want C1 to provision access using this connector
      BATON_PROVISIONING: true

      # Optional: sync nested group hierarchies (subgroups)
      BATON_SYNC_SUB_GROUPS: true
    ```

    <Note>
      **Syncing subgroups**: Set `BATON_SYNC_SUB_GROUPS` to `true` to sync nested Keycloak group hierarchies. When enabled, subgroup membership relationships are surfaced in C1, allowing you to review and manage access to nested groups.
    </Note>

    See the connector's README or run `--help` to see all available configuration flags and environment variables.

    #### Deployment configuration

    ```yaml expandable theme={"theme":{"light":"css-variables","dark":"css-variables"}}
    # baton-keycloak.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: baton-keycloak
      labels:
        app: baton-keycloak
    spec:
      selector:
        matchLabels:
          app: baton-keycloak
      template:
        metadata:
          labels:
            app: baton-keycloak
            baton: true
            baton-app: keycloak
        spec:
          containers:
          - name: baton-keycloak
            image: ghcr.io/conductorone/baton-keycloak:latest
            imagePullPolicy: IfNotPresent
            env:
            - name: BATON_HOST_ID
              value: baton-keycloak
            envFrom:
            - secretRef:
                name: baton-keycloak-secrets
    ```

    ### Step 3: Deploy the connector

    <Steps>
      <Step>
        Create a namespace in which to run C1 connectors (if desired), then apply the secret config and deployment config files.
      </Step>

      <Step>
        Check that the connector data uploaded correctly. In C1, click **Apps**. On the **Managed apps** tab, locate and click the name of the application you added the Keycloak connector to. Keycloak data should be found on the **Entitlements** and **Accounts** tabs.
      </Step>
    </Steps>

    **Done.** Your Keycloak connector is now pulling access data into C1.
  </Tab>
</Tabs>
