| name | OC Authentication Helper |
| description | Helper skill to retrieve OAuth tokens from the correct OpenShift cluster context when multiple clusters are configured |
OC Authentication Helper
This skill provides a centralized way to retrieve OAuth tokens from specific OpenShift clusters when multiple cluster contexts are configured in the user's kubeconfig.
When to Use This Skill
Use this skill whenever you need to:
- Get an OAuth token for API authentication from a specific OpenShift cluster
- Verify authentication to a specific cluster
- Work with multiple OpenShift cluster contexts simultaneously
This skill is used by all commands that need to authenticate with OpenShift clusters:
ask-sippycommand (DPCR cluster)trigger-periodic,trigger-postsubmit,trigger-presubmitcommands (app.ci cluster)query-job-statuscommand (app.ci cluster)
The skill provides a single curl_with_token.sh script that wraps curl and automatically handles OAuth token retrieval and injection, preventing accidental token exposure.
Due to a known Claude Code bug with git-installed marketplace plugins:
When referencing files from this skill (scripts, configuration files, etc.), you MUST:
- Always use the "Base directory" path provided at the top of this skill prompt
- Never assume skills are located in
~/.claude/plugins/ - Construct full absolute paths by combining the base directory with the relative file path
Example:
- ❌ WRONG:
~/.claude/plugins/ci/skills/oc-auth/curl_with_token.sh - ✅ CORRECT: Use the base directory shown above +
/curl_with_token.sh
If you see "no such file or directory" errors, verify you're using the base directory path, not the assumed marketplace cache location.
Prerequisites
oc CLI Installation
- Check if installed:
which oc - If not installed, provide instructions for the user's platform
- Installation guide: https://docs.openshift.com/container-platform/latest/cli_reference/openshift_cli/getting-started-cli.html
- Check if installed:
User Authentication
- User must be logged in to the target cluster via browser-based authentication
- Each
oc logincreates a new context in the kubeconfig
How It Works
The oc CLI maintains multiple cluster contexts in ~/.kube/config. When a user runs oc login to different clusters, each login creates a separate context. This skill:
- Lists all available contexts
- Searches for the context matching the target cluster by API server URL
- Retrieves the OAuth token from that specific context
- Returns the token for use in API calls
Common Clusters
Here are commonly used OpenShift clusters:
1. app.ci - OpenShift CI Cluster
- Console URL: https://console-openshift-console.apps.ci.l2s4.p1.openshiftapps.com/
- API Server: https://api.ci.l2s4.p1.openshiftapps.com:6443
- Used by: trigger-periodic, trigger-postsubmit, trigger-presubmit, query-job-status
2. dpcr - DPCR Cluster
- Console URL: https://console-openshift-console.apps.cr.j7t7.p1.openshiftapps.com/
- API Server: https://api.cr.j7t7.p1.openshiftapps.com:6443
- Used by: ask-sippy
Note: The skill supports any OpenShift cluster - simply provide the cluster's API server URL.
Usage
Script: curl_with_token.sh
A curl wrapper that automatically retrieves the OAuth token and adds it to the request, preventing token exposure.
curl_with_token.sh <cluster_api_url> [curl arguments...]
Parameters:
<cluster_api_url>: Full cluster API server URL (e.g.,https://api.ci.l2s4.p1.openshiftapps.com:6443)[curl arguments...]: All standard curl arguments (URL, headers, data, etc.)
How it works:
- Finds the oc context matching the specified cluster API URL
- Retrieves OAuth token from that cluster context
- Adds
Authorization: Bearer <token>header automatically - Executes curl with all provided arguments
- Token never appears in output or command history
Exit Codes:
0: Success1: Invalid cluster_id or missing arguments2: No context found for the specified cluster3: Failed to retrieve token from context- Other: curl exit codes
Example Usage in Commands
Use the curl wrapper instead of regular curl for authenticated requests:
# Query app.ci API
curl_with_token.sh https://api.ci.l2s4.p1.openshiftapps.com:6443 -X POST \
-d '{"job_name": "my-job", "job_execution_type": "1"}' \
https://gangway-ci.apps.ci.l2s4.p1.openshiftapps.com/v1/executions
# Query Sippy API (DPCR cluster)
curl_with_token.sh https://api.cr.j7t7.p1.openshiftapps.com:6443 -s -X POST \
-H "Content-Type: application/json" \
-d '{"message": "question", "chat_history": []}' \
https://sippy-auth.dptools.openshift.org/api/chat
# Query any other OpenShift cluster API
curl_with_token.sh https://api.your-cluster.example.com:6443 -X GET \
https://your-api.example.com/endpoint
Benefits:
- Token never exposed in logs or output
- Automatic authentication error handling
- Same curl arguments you're already familiar with
- Works with any curl flags (-v, -s, -X, -H, -d, etc.)
Error Handling
The script provides clear error messages for common scenarios:
Missing or invalid arguments
- Error: "Usage: curl_with_token.sh
[curl arguments...]" - Shows example usage
- Error: "Usage: curl_with_token.sh
No context found
- Error: "No oc context found for cluster with API server: {url}"
- Provides authentication instructions
Token retrieval failed
- Error: "Failed to retrieve token from context {context}"
- Suggests re-authenticating to the cluster
Authentication Instructions
General Authentication Process:
Please authenticate first:
1. Visit the cluster's console URL in your browser
2. Log in through the browser with your credentials
3. Click on username → 'Copy login command'
4. Paste and execute the 'oc login' command in terminal
Verify authentication with:
oc config get-contexts
oc cluster-info
Examples:
For app.ci cluster:
- Visit https://console-openshift-console.apps.ci.l2s4.p1.openshiftapps.com/
- Follow the authentication process above
- Verify with
oc cluster-info- should show API server: https://api.ci.l2s4.p1.openshiftapps.com:6443
For DPCR cluster:
- Visit https://console-openshift-console.apps.cr.j7t7.p1.openshiftapps.com/
- Follow the authentication process above
- Verify with
oc cluster-info- should show API server: https://api.cr.j7t7.p1.openshiftapps.com:6443
Benefits
- Single Source of Truth: All context discovery logic is in one place
- Consistency: All commands use the same authentication method
- Maintainability: Changes to cluster names or patterns only need to be updated in one place
- Error Handling: Centralized error messages and authentication instructions
- Multi-Cluster Support: Users can be authenticated to multiple clusters simultaneously
Implementation Details
The script uses the following approach:
Get all context names
oc config get-contexts -o nameFind matching context by API server URL
for ctx in $contexts; do cluster_name=$(oc config view -o jsonpath="{.contexts[?(@.name=='$ctx')].context.cluster}") server=$(oc config view -o jsonpath="{.clusters[?(@.name=='$cluster_name')].cluster.server}") if [ "$server" = "$target_url" ]; then echo "$ctx" break fi doneRetrieve token from context
oc whoami -t --context=$context_name
This ensures we get the token from the correct cluster by matching the exact API server URL, even when multiple cluster contexts exist.