Keycloak Installation

On this page

  1. Create the Keycloak database
  2. Configure the Helm chart
  3. Deploy Keycloak
  4. Access the Keycloak admin interface
  5. Create the NBS realm
  6. Configure service clients
    1. DI client
    2. NND client
    3. SRTE client
    4. XML-HL7 parser client

The Keycloak Helm chart provides authentication for modernization-api, nbs-gateway, data-ingestion-api, and nnd.

Create the Keycloak database

Any compatible SQL client can be used, including SQL Server Management Studio (SSMS).

  1. Using your SQL client, authenticate into the RDS instance where NBS is running:
    • DB Endpoint – DB Endpoint
    • Usernameadmin
    • Passworddatabase_admin_password
  2. Run the script below (from <Helm extract directory>/charts/keycloak/nbs_keycloak.sql) to create the Keycloak database and database user. Replace 'EXAMPLE_KCDB_PASS8675309' with a complex password that meets your organization’s standards. Store this password securely — you will need it in the values.yaml file in the next section.

    use master
      IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'keycloak')
      BEGIN
        CREATE DATABASE keycloak
     END
    GO
      USE keycloak
    GO
    
    BEGIN
    CREATE LOGIN NBS_keycloak WITH PASSWORD = 'EXAMPLE_KCDB_PASS8675309';
    CREATE USER NBS_keycloak FOR LOGIN NBS_keycloak;
    EXEC sp_addrolemember N'db_owner', N'NBS_keycloak'
    END
    

    Validation: Keycloak database is created

    keycloak-database-creation

Configure the Helm chart

  1. In {Helm extract directory}/charts/keycloak/values.yml, update the following parameters:

    Parameter Template Value Example / Description
    adminUser admin Keycloak admin account for the Web UI. Keep the template value or change to match organizational naming conventions.
    adminPassword EXAMPLE_KC_PASS8675309 Password for the Keycloak admin user. Use a complex password matching organizational standards.
    KC_DB mssql mssql
    KC_DB_URL jdbc:sqlserver://EXAMPLE_DB_ENDPOINT:1433;databaseName=keycloak;encrypt=true;trustServerCertificate=true; jdbc:sqlserver://mydbendpoint:1433;databaseName=keycloak;encrypt=true;trustServerCertificate=true;
    KC_DB_USERNAME NBS_keycloak Keycloak database account. Keep the template value or change to match organizational naming conventions.
    KC_DB_PASSWORD EXAMPLE_KCDB_PASS8675309 Must match the password set in step 2 of the previous section.
    efsFileSystemId EXAMPLE_EFS_ID EFS file system ID from the AWS console or CLI. Provides persistent storage for themes.

Deploy Keycloak

  1. Authenticate to the EKS cluster:

    aws eks --region us-east-1 update-kubeconfig --name <clustername> # e.g. cdc-nbs-sandbox
    
  2. From the charts directory, install the Keycloak Helm chart. This step takes at least 5 minutes while the init container becomes available. See the README in Helm/charts/keycloak for details.

    Helm install keycloak --namespace default -f keycloak/values.yaml keycloak
    

    keycloak-database-tables

  3. Verify the pod is running before proceeding:

    kubectl get pods -n default
    

Access the Keycloak admin interface

Port forwarding is not supported by CloudShell by default. Run these commands from a system that has both network access to the EKS endpoint and a browser. If you completed the installation from CloudShell, switch to a jumpbox or desktop with network connectivity to the EKS endpoint.

  1. Set up port forwarding:

    export POD_NAME=$(kubectl get pods --namespace default -o name);
    echo "Visit http://127.0.0.1:8080/auth to use your application";
    kubectl --namespace default port-forward "$POD_NAME" 8080;
    
  2. In a browser, navigate to http://127.0.0.1:8080/auth and select Administrative console.

    keycloak-ui-interface

  3. Sign in using the adminUser and adminPassword values configured in the Helm chart.

    keycloak-ui-login keycloak-ui-2-login

Create the NBS realm

  1. Create a new realm to contain the NBS-specific client and user/group configurations.

    nbs-create-new-realm

  2. Upload {Helm extract directory}/charts/keycloak/extra/01-NBS-realm-with-DI-client.json and click Create. This imports the NBS realm and clients.

    nbs-create-new-realm-2 nbs-create-new-realm-3

  3. Verify the realm and clients are created successfully.

    nbs-realm-di-client-creation

Configure service clients

The imported configuration seeds a random client secret for each service client. You may regenerate or use a secure local client secret. Repeat the import and retrieval steps below for each client.

DI client

  1. Navigate to the NBS Realm in the left menu and click Clients.
  2. Select di-keycloak-client and open the Credentials tab.
  3. Click the eye icon to reveal the secret and copy it.
  4. Store the secret for use by the applications (for example, in AWS Secrets Manager at keycloak/client/secret/di).

    di-client-id di-client-secret

NND client

  1. In the NBS Realm, open Realm settings, click the Action dropdown, and select Partial Import.

    nnd-realm nnd-realm-partial-import

  2. Upload <Helm extract directory>/charts/keycloak/extra/05-nbs-users-nnd-client.json and click Create.
  3. Navigate to the NBS Realm in the left menu and click Clients.
  4. Select nnd-keycloak-client and open the Credentials tab.
  5. Click the eye icon to reveal the secret and copy it.
  6. Store the secret (for example, in AWS Secrets Manager at keycloak/client/secret/nnd).

    nnd-client-id nnd-client-secret

SRTE client

  1. In the NBS Realm, open Realm settings, click the Action dropdown, and select Partial Import.
  2. Upload <Helm extract directory>/charts/keycloak/extra/06-nbs-users-srte-data-client.json and click Create.
  3. Navigate to the NBS Realm in the left menu and click Clients.
  4. Select srte-data-keycloak-client and open the Credentials tab.
  5. Click the eye icon to reveal the secret and copy it.
  6. Store the secret (for example, in AWS Secrets Manager at keycloak/client/secret/srte).

XML-HL7 parser client

  1. In the NBS Realm, open Realm settings, click the Action dropdown, and select Partial Import.
  2. Upload <Helm extract directory>/charts/keycloak/extra/10-nbs-users-xml-hl7-parser-service.json and click Create.
  3. Navigate to the NBS Realm in the left menu and click Clients.
  4. Select xml-hl7-parser-keycloak-client and open the Credentials tab.
  5. Click the eye icon to reveal the secret and copy it.
  6. Store the secret (for example, in AWS Secrets Manager at keycloak/client/secret/xml-hl7-parser).

Table of contents


Back to top

© Centers for Disease Control and Prevention (CDC). All Rights Reserved.