Skip to main content

Obtain an OCP OAuth token for an SSO IdP with Kerberos support

Project description

Automation to create OpenShift CLI tokens for OpenID-connected IdP with Kerberos support

This package can be found on PyPI as ocp-sso-token.

Problem: several manual steps to log into an OpenShift cluster via OIDC without ROPC

To log into an OpenShift cluster on the command line, oc login supports user/password authentication for various identity providers like LDAP or OIDC with ROPC grant flow.

If no provider with password support is configured, the user is referred to the OAuth login page to obtain a temporary token interactively. After selecting the right provider, the user is forwarded to authenticate with the SSO provider, and redirected back to the cluster afterwards. Another click reveals the temporary token that can now be used for the CLI tools.

For an OpenID provider that supports Kerberos tickets, the authentication with the SSO provider happens transparently. For such setups, logging into a cluster via the CLI roughly requires the following steps:

  • run oc login and click on the link, or visit a bookmark for the cluster login page
  • click on the button for the OpenID provider
  • watch the webpages forwarding to each other
  • click on the link to reveal the temporary token
  • use the shown temporary token/oc login command to log into the cluster

These steps must be performed daily and per cluster.

Approach: automate all the steps above

The Python script in this repository automates all the steps to obtain the temporary token so that the following is possible:

kinit $user@$domain
oc login --server $server --token $(ocp-sso-token $server)

Installing the script

# from PyPI
pip install ocp-sso-token

# from source
pip install --user git+https://gitlab.com/cki-project/ocp-sso-token

Using the script to log into an OpenShift cluster via OIDC

usage: ocp-sso-token [-h] [--identity-providers IDENTITY_PROVIDERS] api_url

Log into an OCP cluster via Kerberos tickets

positional arguments:
  api_url               Cluster API URL like https://api.cluster:6443

optional arguments:
  -h, --help            show this help message and exit
  --identity-providers IDENTITY_PROVIDERS
                        Identity provider names (default: SSO,OpenID)

Running a smoke test:

kinit user@DOMAIN.COM
server=https://api.cluster:6443
oc --server $server --token $(ocp-sso-token $server) get project

If your identity provider name is not included in the defaults shown above, add it via --identity-providers. The first matching identity provider will be used.

Creating a development setup and running the tests

Installing development dependencies:

pip install -e .[dev]

Running linting/tests:

tox

Creating a release

  1. Create a release MR with an update of the version number in ocp_sso_token/__init__.py, e.g to '3.1.4'

  2. After merging, push a new tag with the same version prefixed with v, e.g.

    git tag v3.1.4
    git push origin v3.1.4
    
  3. Wait for the pipeline to finish

  4. Check the resulting GitLab and PyPI releases

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ocp-sso-token-0.1.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

ocp_sso_token-0.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file ocp-sso-token-0.1.0.tar.gz.

File metadata

  • Download URL: ocp-sso-token-0.1.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for ocp-sso-token-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b801c63ceb865dc4ae846e75241833ff047bd8c620cbd3fcd26bd9332fcc5448
MD5 65f1efee9a4bcea25a7cce4ade6b6417
BLAKE2b-256 654eed5e8c4e7d3c86b44dbbfa9d745aba7fc5aa563d811c1afec2e9b11f46cd

See more details on using hashes here.

File details

Details for the file ocp_sso_token-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ocp_sso_token-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44b486d57148979ab3b087b06490b3959b33f89516cc08e0ae908a478c897057
MD5 3a513c76cd6f69e26ef43db132549f76
BLAKE2b-256 6699f51f6a4237482c90dbc699d0a9f1ebbfa83fba28c3a93591ea54daa8e25e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page