Adding a Cloudera Harmony Catalog

Connect Cloudera SQL Stream Builder (SSB) to the Iceberg tables of a Cloudera Harmony Catalog through the Iceberg REST API. Define the tables with Flink DDL, which works for a catalog in any cluster. You can also add a catalog in the same cluster as Cloudera Streaming Analytics as a data source.

Ensure that a Cloudera Harmony Catalog is available to your deployment, and collect its REST endpoint, the warehouse name, and the Iceberg namespace of the tables.

Ensure that an administrator has granted you Apache Ranger permissions on the tables that your jobs use. For the permissions, see Ranger policies for SSB users.

You can connect in the following ways:

  • Recommended: define each table with Flink DDL that connects to the external REST endpoint of the catalog with OAuth2. This way works for a Cloudera Harmony Catalog in any cluster, including the same cluster as Cloudera Streaming Analytics.
  • If the catalog runs in the same cluster as Cloudera Streaming Analytics, you can add the catalog on the Data Sources page with the internal URI of the catalog. This catalog type works only with the internal URI. Using the internal URI is not recommended.

Ranger policies for SSB users

The Cloudera Harmony Catalog denies every request unless an Apache Ranger policy allows it. SSB does not manage these policies. Which identity the policies must allow depends on how you connect:

  • For tables that you define with DDL and OAuth2, the catalog sends Ranger the user who owns the access key. An administrator must add Ranger policies for each SSB user whose jobs use the catalog.
  • For a catalog that you add on the Data Sources page, Ranger checks the SPIFFE IDs of the SSB and Flink service accounts, not the user. An administrator must add Ranger policies that allow these SPIFFE IDs.

Add the policies to the Ranger service of the Cloudera Harmony Catalog, for example udf_harmony_catalog_[***INSTANCE-NAME***]. Confirm the name in Ranger Admin, which you open from the Cloudera Unified Data Fabric landing page. The resources of a policy are hierarchical: catalog, namespace, and table.

Grant only the permissions that the jobs of the user need, as shown in the following table:

Table 1. Ranger permissions for SSB jobs
To do this Policy resource Permission
Find the catalog Catalog catalog-list
Find the namespace Catalog and namespace namespace-list
Read a table Catalog, namespace, and table table-list, table-data-read
Write to a table, for example with INSERT INTO Catalog, namespace, and table The read permissions and table-data-write
Create a table, for example when the table in catalog-table does not exist yet Catalog, namespace, and table; and catalog and namespace table-create on the table, and namespace-metadata-full on the namespace
Create a namespace Catalog namespace-create

In the table resource, list the tables that the jobs use instead of *. A new policy takes effect after about 30 to 60 seconds. If a policy is missing, the catalog returns 403 with a Principal '[***USER***]' is not authorized message.

For information about working with the Ranger policies of the catalog, see Granting Ranger access for Cloudera Harmony Catalog in the Cloudera Harmony Catalog documentation.

Cloudera Harmony Catalog in the same cluster

The Cloudera Harmony catalog type appears when the Iceberg connector is available in the engine instance. Using the internal URI is not recommended. Define the tables with CREATE TABLE DDL, the external URI, and OAuth2, as described in the next section. The Data Sources page works only for a catalog in the same cluster.

  1. In the Streaming SQL Console, click Projects in the left navigation pane, and click the name of your project. To open the Streaming SQL Console, see Accessing Cloudera SQL Stream Builder.
  2. In the Explorer, open the menu of Catalog under Data Sources, and click New Catalog.
  3. In Catalog Type, select Cloudera Harmony.
  4. In Name, enter a name for the catalog.
  5. In URI, enter the internal REST endpoint of the catalog, for example http://[***HARMONY-SERVICE***].[***NAMESPACE***].svc.cluster.local:8181/api/catalog.
  6. In Warehouse, enter the name of the catalog in the Cloudera Harmony Catalog. The default catalog is harmonycatalog.
  7. Optional: Set the Database Filter and Table Filter.
  8. Click Validate, and then click Create.

You can create and query Iceberg tables in the catalog. For more information, see Creating Iceberg tables.

Cloudera Harmony Catalog in another cluster, or with DDL

Use these steps for a catalog in another cluster. They also work, and are recommended, for a catalog in the same cluster.

  1. Get the certificates of the external REST endpoint of the catalog and of the Anywhere Cloud Console, and save them together in one PEM file. The connector connects to the catalog, and to the Anywhere Cloud Console for access tokens:
    openssl s_client -showcerts -connect [***HARMONY-EXTERNAL-API-HOST***]:443 </dev/null \
    | openssl x509 -outform PEM > ./harmony.pem
    
    openssl s_client -showcerts -connect [***CONSOLE-HOST***]:443 </dev/null \
    | openssl x509 -outform PEM > ./console.pem
    
    cat ./console.pem ./harmony.pem > harmony-bundle-ca.pem
  2. Upload the harmony-bundle-ca.pem file to your project as a project file. For more information, see Managing project files.
  3. Create an access key, and save its client ID and client secret. For more information, see Creating access keys in the Anywhere Cloud documentation.

    The connector exchanges the access key for an access token, and gets a new token when the token expires, after one hour by default. Jobs that run for a long time keep their access to the catalog.

  4. In the SQL editor, register the table with a CREATE TABLE statement:
    CREATE TABLE harmony_flink_table (
      id BIGINT,
      name STRING
    ) WITH (
      'catalog-database' = '[***ICEBERG-NAMESPACE***]',
      'catalog-name' = 'harmony',
      'catalog-table' = '[***TABLE-NAME***]',
      'catalog-type' = 'rest',
      'connector' = 'iceberg',
      'header.X-Iceberg-Access-Delegation' = 'vended-credentials',
      'rest.auth.type' = 'oauth2',
      'rest.client.tls.ca-cert-path' = '${ssb.project-file:harmony-bundle-ca.pem}',
      'rest.client.tls.configurer-impl' = 'com.cloudera.ssb.iceberg.rest.SsbTlsConfigurer',
      'credential' = '[***CLIENT-ID***]:[***CLIENT-SECRET***]',
      'uri' = '[***HARMONY-EXTERNAL-API-URI***]/api/catalog',
      'warehouse' = 'harmonycatalog',
      'oauth2-server-uri' = '[***CONSOLE-URI***]/api/v1/auth/access-keys/token'
    );

    Replace the following values:

    • catalog-database: the Iceberg namespace of the table.
    • catalog-table: the name of the table in the catalog.
    • credential: the client ID and the client secret of the access key, separated by a colon.
    • uri: the external API URI of the catalog.
    • warehouse: the name of the catalog in the Cloudera Harmony Catalog. The example uses harmonycatalog, the default catalog.
    • oauth2-server-uri: the URL of the Anywhere Cloud Console, for example https://console.[***DOMAIN***], followed by /api/v1/auth/access-keys/token.

    Flink uses catalog-name only internally, so you can use any value. ${ssb.project-file:harmony-bundle-ca.pem} refers to the certificate file that you uploaded.

  5. Run a SQL job that uses the table, for example:
    INSERT INTO harmony_flink_table SELECT * FROM [***SOURCE-TABLE***];

    Turn on checkpointing for jobs that write to the table. Without checkpointing, the job commits nothing to Iceberg, even while it runs.