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
-
Create a release MR with an update of the version number in
ocp_sso_token/__init__.py
, e.g to '3.1.4' -
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
-
Wait for the pipeline to finish
-
Check the resulting GitLab and PyPI releases
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ocp-sso-token-0.1.1.tar.gz
.
File metadata
- Download URL: ocp-sso-token-0.1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30dac6a0d244ac50ec8c746816219d89eb774efe8b5b4678bca4a961f46a7e70 |
|
MD5 | bf4cf7879da5c59500d257682e517418 |
|
BLAKE2b-256 | 49cf700d7d3ae018edf491bc3513915f4ee89d98bf43aee90a2138afd01e2746 |
File details
Details for the file ocp_sso_token-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: ocp_sso_token-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4ce36c34319d99f8cb72d8dbf8c173d049acf196b9e208d64cdee43d35eeb3 |
|
MD5 | db1fca27ca77cdf390beb600dddc11d6 |
|
BLAKE2b-256 | b10720ce0e3bac6ca9cbbd145564e7032f19e83124fb7e77b2d2efeb537ea8e4 |