Helper skill to retrieve OAuth tokens from the correct OpenShift cluster context when multiple clusters are configured
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdcurl_with_token.shThis skill provides a centralized way to retrieve OAuth tokens from specific OpenShift clusters when multiple cluster contexts are configured in the user's kubeconfig.
Use this skill whenever you need to:
This skill is used by all commands that need to authenticate with OpenShift clusters:
ask-sippy command (DPCR cluster)trigger-periodic, trigger-postsubmit, trigger-presubmit commands (app.ci cluster)query-job-status command (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:
~/.claude/plugins/Example:
~/.claude/plugins/ci/skills/oc-auth/curl_with_token.sh/curl_with_token.shIf you see "no such file or directory" errors, verify you're using the base directory path, not the assumed marketplace cache location.
oc CLI Installation
which ocUser Authentication
oc login creates a new context in the kubeconfigThe 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:
Here are commonly used OpenShift clusters:
app.ci - OpenShift CI Clusterdpcr - DPCR ClusterNote: The skill supports any OpenShift cluster - simply provide the cluster's API server URL.
curl_with_token.shA 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:
Authorization: Bearer <token> header automaticallyExit Codes:
0: Success1: Invalid cluster_id or missing arguments2: No context found for the specified cluster3: Failed to retrieve token from contextUse 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:
The script provides clear error messages for common scenarios:
Missing or invalid arguments
No context found
Token retrieval failed
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
For app.ci cluster:
oc cluster-info - should show API server: https://api.ci.l2s4.p1.openshiftapps.com:6443For DPCR cluster:
oc cluster-info - should show API server: https://api.cr.j7t7.p1.openshiftapps.com:6443The script uses the following approach:
Get all context names
oc config get-contexts -o name
Find 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
done
Retrieve 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.