Authenticating to Cloudera Harmony Catalog REST APIs with Knox

Use Knox SSO from the command line to call Cloudera Harmony Catalog management and catalog REST APIs. Set CONSOLE_KNOX and CATALOG_API, then obtain a hadoop-jwt session cookie for curl and other CLI clients.

The Anywhere Cloud Console authenticates users through Knox SSO. For post-deployment API work (for example creating catalogs), you can exchange your platform username and password for a short-lived hadoop-jwt cookie without opening a browser.

  1. Set Knox and catalog base URLs.
    • CONSOLE_KNOX: Knox SSO base URL for your Anywhere Cloud environment. Take the URL you use to sign in to the Anywhere Cloud Console and replace the console hostname prefix with knox on the same domain (scheme and remainder unchanged; do not append /gateway). For example, if you sign in at https://console.28797-englakedev.awcqe2.sandbox21.cloudera.com/, set CONSOLE_KNOX to https://knox.28797-englakedev.awcqe2.sandbox21.cloudera.com.
    • CATALOG_API: External HTTPS base URL from chcExternalRestApiEndpoint on your deployment (host only, no path). See Accessing Cloudera Harmony Catalog.
    CONSOLE_KNOX=https://knox.<your-environment-domain>
    CATALOG_API=https://<your-harmony-catalog-api-host>  # from chcExternalRestApiEndpoint
  2. Sign in via Knox OBO to get a session token.

    Knox SSO authenticates your CLI session. The websso call returns a reusable hadoop-jwt cookie for API requests.

    read -s -p "Password for <username>: " KPASS; echo
    
    HJWT=$(curl -sk -D - -o /dev/null -u "<username>:${KPASS}" \
      "${CONSOLE_KNOX}/gateway/knox-cdpsso/api/v1/websso?originalUrl=${CATALOG_API}/api/management/v1/catalogs" | \
      awk -F'hadoop-jwt=' 'tolower($0) ~ /set-cookie/ {print $2}' | awk -F';' '{print $1}')

    This exchanges your credentials for a short-lived (about one hour) hadoop-jwt token. Send it as a cookie on each request, for example:

    curl -sk -b "hadoop-jwt=${HJWT}" "${CATALOG_API}/api/management/v1/catalogs"

    For catalog data-plane calls, use the same cookie against paths under /api/catalog.

If you get 401, the token expired or the login failed. Repeat the Knox OBO step.

If you get 403 Principal '<user>' is not authorized ..., Ranger does not grant the operation. Configure policies on the Harmony Catalog Ranger service before you retry. See Creating Ranger policies for additional catalogs.