kc CLI Tool
Overview
kc is the companion CLI tool for Kubauth, providing essential utilities for working with the Kubauth OIDC server and Kubernetes authentication.
GitHub Repository: https://github.com/kubauth/kc
Purpose
The kc CLI tool serves multiple purposes:
- Authentication Testing - Quickly test OIDC authentication flows
- Token Management - Obtain and inspect OIDC tokens
- Kubeconfig Setup - Automate kubectl configuration for OIDC authentication
- User Management - Generate password hashes for users and clients
- Audit Queries - View authentication attempts and user details
- JWT Inspection - Decode and display JWT token contents
Installation
Download the latest release from the GitHub releases page and install it on your system.
macOS and Linux
# Download the appropriate binary for your system
# For example, on macOS:
mv kc_darwin_amd64 kc
chmod +x kc
sudo mv kc /usr/local/bin/
Windows
# Rename and move to a directory in your PATH
mv kc_windows_amd64.exe kc.exe
# Move to a directory in your PATH, e.g., C:\Windows\System32\
Verify Installation
Available Commands
Authentication & Tokens
kc token- Obtain OIDC tokens using the authorization code flow (with browser)kc token-nui- Obtain OIDC tokens using password grant (no browser required)kc jwt- Decode and display JWT token contentskc logout- Clear SSO session and local token cache
Kubernetes Configuration
kc config- Configure kubectl for OIDC authentication with Kubauthkc whoami- Display current authenticated user information
Utilities
kc hash- Generate bcrypt hashes for passwords and secretskc audit- Query authentication audit logskc version- Display version information
Quick Start
1. Test Authentication
2. Generate a Password Hash
3. Configure kubectl
4. Check Who You Are
5. View Audit Logs
Common Options
Many kc commands share common options:
--issuerURL (string)
The Kubauth OIDC issuer URL.
Example: --issuerURL https://kubauth.example.com
--clientId (string)
The OIDC client ID.
Example: --clientId public
--insecureSkipVerify
Skip TLS certificate verification for ìssuerURL (useful for testing with self-signed certificates).
Example: --insecureSkipVerify
--caFile
Provide a CA file for TLS certificate verification of ìssuerURL
-d, --detailed
Decode and display JWT token contents (shortcut for piping to kc jwt).
Example: kc token --issuerURL https://kubauth.example.com --clientId public -d
Kubeconfig configuration File
The kc tool can read OIDC configuration from your kubectl config file when available. This eliminates the need to specify --issuerURL and --clientId for many commands after you've run kc config.
Environment Variables
Some commands support environment variables for configuration:
KC_ISSUER_URL- Default issuer URLKC_CLIENT_ID- Default client IDKC_CLIENT_SECRET- Default client secretKC_USER_LOGIN- Default user login fortoken-nuiKC_USER_PASSWORD- Default user password fortoken-nui
Example:
export KC_ISSUER_URL=https://kubauth.example.com
export KC_CLIENT_ID=public
# Now you can omit these flags
kc token
Getting Help
For help with any command:
Use Cases
Development & Testing
# Quick authentication test
kc token --issuerURL https://kubauth.local --clientId test
# Decode token to inspect claims
kc token --issuerURL https://kubauth.local --clientId test -d
# Test with different users
kc token-nui --issuerURL https://kubauth.local --clientId test \
--login alice --password alice123 -d
User Management
# Generate password hash for a new user
kc hash strongpassword456
# Check user's groups and claims
kc audit detail username
Kubernetes Integration
# Configure kubectl for OIDC
kc config https://kubeconfig.example.com/kubeconfig
# Verify configuration
kc whoami
# Log out to switch users
kc logout
CI/CD & Automation
# Non-interactive authentication for scripts
kc token-nui --issuerURL https://kubauth.example.com \
--clientId automation \
--login serviceaccount \
--password $SERVICE_PASSWORD \
--onlyIdToken
Troubleshooting
Certificate Errors
If you encounter TLS certificate errors:
-
Option 1: Skip verification (not recommended for production)
-
Option 2: Add CA certificate to your system trust store
Extract CA certificate
kubectl -n kubauth get secret kubauth-oidc-server-cert \ -o=jsonpath='{.data.ca\.crt}' | base64 -d > kubauth-ca.crtAdd to system trust store (OS-specific)
Browser Not Opening
If the browser doesn't open automatically with kc token:
- Check the console output for the localhost URL
- Manually open the URL in your browser
- Or use
kc token-nuifor terminal-based authentication