#!/bin/bash # kubectl exec credential plugin for 1Password # Usage: kubectl-credential-1password # # Fetches client certificate and key from 1Password and outputs # ExecCredential JSON for kubectl authentication. set -euo pipefail VAULT_ID="$1" ITEM_ID="$2" CERT_FIELD="$3" KEY_FIELD="$4" # Fetch credentials from 1Password (strips surrounding quotes from text fields) CLIENT_CERT=$(op --vault "$VAULT_ID" item get "$ITEM_ID" --fields "$CERT_FIELD" | sed 's/^"//; s/"$//') CLIENT_KEY=$(op --vault "$VAULT_ID" item get "$ITEM_ID" --fields "$KEY_FIELD" | sed 's/^"//; s/"$//') # Output ExecCredential JSON # Note: jq is used to properly escape the PEM data for JSON jq -n \ --arg cert "$CLIENT_CERT" \ --arg key "$CLIENT_KEY" \ '{ "apiVersion": "client.authentication.k8s.io/v1beta1", "kind": "ExecCredential", "status": { "clientCertificateData": $cert, "clientKeyData": $key } }'