~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/socialweb-computer-console

console.socialweb.computer: kcp, kubectl and ssh compiled to wasm in a browser tab with a terminal; a kcp fork

0
0
main
75 lines · 2.9 KB Raw History
#!/usr/bin/env bash

# Copyright 2026 The kcp Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Static variant of kind.sh: brings up a kind cluster and runs Tilt against
# Tiltfile.static, which installs the upstream kcp-operator and deploys the
# upstream kcp images instead of building them from local sources.
#
# Extract the attacker's raw client cert/key from pentest-attacker.kubeconfig so
# you can probe the kcp front proxy with curl (or any HTTP tool) directly —
# useful for anything kubectl won't let you express (custom headers, malformed
# paths, verb tunnelling, raw watch streams, etc.).
#
# Usage:
#   ./contrib/tilt/pentest/attacker-creds.sh            # write PEMs + print examples
#   eval "$(./contrib/tilt/pentest/attacker-creds.sh -e)"  # export env vars into your shell
#
# Run after contrib/tilt/pentest/setup.sh.

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
ATTACKER_KCFG="$REPO_ROOT/pentest-attacker.kubeconfig"
OUT_DIR="$REPO_ROOT/pentest-attacker-creds"
PROXY="https://kcp.localhost:8443"

[[ -f "$ATTACKER_KCFG" ]] || { echo "run contrib/tilt/pentest/setup.sh first" >&2; exit 1; }

mkdir -p "$OUT_DIR"
kubectl --kubeconfig "$ATTACKER_KCFG" config view --raw \
  -o jsonpath='{.users[0].user.client-certificate-data}' | base64 -d > "$OUT_DIR/tls.crt"
kubectl --kubeconfig "$ATTACKER_KCFG" config view --raw \
  -o jsonpath='{.users[0].user.client-key-data}' | base64 -d > "$OUT_DIR/tls.key"
chmod 600 "$OUT_DIR/tls.key"

# -e: emit shell exports and nothing else.
if [[ "${1:-}" == "-e" ]]; then
  echo "export KCP_PROXY='$PROXY'"
  echo "export ATTACKER_CERT='$OUT_DIR/tls.crt'"
  echo "export ATTACKER_KEY='$OUT_DIR/tls.key'"
  exit 0
fi

cat <<EOF
Wrote attacker client credentials:
  cert : $OUT_DIR/tls.crt
  key  : $OUT_DIR/tls.key
  proxy: $PROXY

Raw API examples (the attacker authenticates by client cert):

  # Who does the shard think you are?
  curl -sk --cert "$OUT_DIR/tls.crt" --key "$OUT_DIR/tls.key" \\
    -X POST "$PROXY/clusters/root:alpha/apis/authentication.k8s.io/v1/selfsubjectreviews" \\
    -H 'Content-Type: application/json' \\
    -d '{"apiVersion":"authentication.k8s.io/v1","kind":"SelfSubjectReview"}'

  # Try to read the flag in a workspace you have no RBAC for (expect 403):
  curl -sk --cert "$OUT_DIR/tls.crt" --key "$OUT_DIR/tls.key" \\
    "$PROXY/clusters/root:bravo/api/v1/namespaces/default/secrets/crown-jewels"

Add -H 'Header: value' to experiment with request shaping.
EOF