|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The KCP Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +outfile="$PWD/frontproxy.kubeconfig" |
| 20 | + |
| 21 | +cd "$(dirname "$0")" |
| 22 | + |
| 23 | +hostname="$(yq '.externalHostname' < ./kcp-values.yaml)" |
| 24 | + |
| 25 | +kubectl --context kind-kcp -n kcp-certs apply -f- <<EOF |
| 26 | +apiVersion: cert-manager.io/v1 |
| 27 | +kind: Certificate |
| 28 | +metadata: |
| 29 | + name: cluster-admin-client-cert |
| 30 | +spec: |
| 31 | + commonName: cluster-admin |
| 32 | + issuerRef: |
| 33 | + name: certs-front-proxy-client-issuer |
| 34 | + privateKey: |
| 35 | + algorithm: RSA |
| 36 | + size: 2048 |
| 37 | + secretName: cluster-admin-client-cert |
| 38 | + subject: |
| 39 | + organizations: |
| 40 | + - system:kcp:admin |
| 41 | + usages: |
| 42 | + - client auth |
| 43 | +EOF |
| 44 | + |
| 45 | +kubectl --context kind-kcp -n kcp-certs wait certificate/cluster-admin-client-cert --for=condition=Ready |
| 46 | + |
| 47 | +kubectl --context kind-kcp -n kcp-certs get secret proxy-front-proxy-cert -o=jsonpath='{.data.tls\.crt}' | base64 -d > ca.crt |
| 48 | +kubectl --context kind-kcp -n kcp-certs get secret cluster-admin-client-cert -o=jsonpath='{.data.tls\.crt}' | base64 -d > client.crt |
| 49 | +kubectl --context kind-kcp -n kcp-certs get secret cluster-admin-client-cert -o=jsonpath='{.data.tls\.key}' | base64 -d > client.key |
| 50 | +chmod 0600 ca.crt client.crt client.key |
| 51 | + |
| 52 | +kubectl --kubeconfig="$outfile" config set-cluster root --server=https://$hostname:8443/clusters/root --certificate-authority="$(realpath ca.crt)" |
| 53 | +kubectl --kubeconfig="$outfile" config set-credentials kcp-admin --client-certificate="$(realpath client.crt)" --client-key="$(realpath client.key)" |
| 54 | +kubectl --kubeconfig="$outfile" config set-context root --cluster=root --user=kcp-admin |
| 55 | +kubectl --kubeconfig="$outfile" config use-context root |
| 56 | +echo "Kubeconfig file created at '$outfile'" |
0 commit comments