Skip to content

feat: KKP OIDC login via kubelogin#131

Open
krajtar wants to merge 3 commits into
mainfrom
feat/kkp-oidc-login
Open

feat: KKP OIDC login via kubelogin#131
krajtar wants to merge 3 commits into
mainfrom
feat/kkp-oidc-login

Conversation

@krajtar

@krajtar krajtar commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Replaces the OpenStack application-credential login flow with a KKP OIDC flow.

Flow

kubelogin (browser auth, cached ~2h)
    → KKP API /api/v2/projects/{pid}/clusters/{cid}/oidckubeconfig
    → patch auth-provider → exec plugin
    → save kubeconfig to ~/.ewccli/kubeconfigs/<profile>.yaml
    → SSH tunnel + /etc/hosts entry

No OIDC tokens are persisted. The profile stores only the kubeconfig path and SSH keys.

New modules (ewccli/backends/kkp/)

Module Purpose
kubelogin.py Subprocess wrapper, parses ExecCredential JSON
kkp_client.py KKP API client, get_oidc_kubeconfig()
kubeconfig_processor.py auth-providerexec block conversion
network.py SSH tunnel + /etc/hosts + kubelogin binary setup

Changes to existing files

  • login_command.py: Rewritten — removed OpenStack credential prompts, federee/region/tenant_name selection. Single flow: kubelogin → KKP API → patch → save → tunnel+hosts. check_and_generate_ssh_keys kept.
  • configuration.py: Added EWC_CLI_KKP_* config block (API URL, Dex issuer, client ID/secret, project/cluster IDs, SSH jump/tunnel/APIServer IPs, kubeconfig path).
  • ewccli.py: Simplified init() signature — removed tenant_name, federee, region, application_credential_id, application_credential_secret params. Added no_browser.
  • utils.py: Added kubeconfig_path to save_cli_profile(), added profile_exists() + update_cli_profile_credentials().
  • README.md: Updated login section + config env var table.

Tests (120 pass)

  • test_kkp_client.py (5): mock requests, 200/401/404/exception
  • test_kubeconfig_processor.py (7): auth-provider→exec, non-oidc preserved, extract_hostname
  • test_kubelogin.py (4): mock subprocess, parse/invalid/missing token
  • ewccli_login_test.py (+3 new): existing profile refresh, new profile create, missing project ID guard
  • All existing SSH key tests preserved (6)

Breaking changes

  • hub and infra commands (which need OpenStack application credentials) are broken by this change. A separate OpenStack auth path will be added.
  • --tenant-name, --federee, --region, --application-credential-id, --application-credential-secret flags removed from ewc login.

Prerequisites

Closes #42

krajtar added 3 commits July 3, 2026 09:19
Replaces the OpenStack application-credential login flow with a KKP OIDC
flow: kubelogin obtains a browser-authenticated token, the KKP API returns
an OIDC kubeconfig, which is post-processed (auth-provider -> exec plugin)
and saved to the profile.

New backends/kkp/ package:
- kubelogin.py: subprocess wrapper, parses ExecCredential JSON
- kkp_client.py: KKP API client, get_oidc_kubeconfig()
- kubeconfig_processor.py: auth-provider -> exec block conversion
- network.py: SSH tunnel + /etc/hosts + kubelogin binary setup

Login flow: kubelogin -> KKP API -> patch kubeconfig -> save -> tunnel+hosts
No OIDC tokens persisted. Profile stores kubeconfig path + SSH keys only.

hub/infra commands (OpenStack) are broken by this change — separate auth
path to be added.

Closes #42
The SSH tunnel was a user-specific workaround for reaching the user-cluster
apiserver from outside the KKP network. It required a jump host, sudo for
/etc/hosts, and hardcoded IP addresses — not suitable for a general CLI.

Removed:
- ensure_tunnel() and ensure_hosts_entry() from network.py
- extract_hostname() import from login_command.py (unused now)
- EWC_CLI_SSH_JUMP, EWC_CLI_TUNNEL_HOST, EWC_CLI_APISERVER_IP config vars
- Tunnel/hosts patches from integration tests
- SSH/sudo prerequisites and tunnel env vars from README

The apiserver must now be directly reachable from the host running ewccli.
120 tests pass.
extract_hostname was only called by ensure_hosts_entry for the /etc/hosts
tunnel setup. With the tunnel removed, it's dead code. Removes function
+ 2 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] ewc login refactoring

1 participant