|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2022 The Knative 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 | + |
| 18 | +# Set the ROOT_CA and token audiences |
| 19 | + |
| 20 | +echo "Copy the certificate to file" |
| 21 | +ROOTCA="$(mktemp)" |
| 22 | +FILENAME=`basename $ROOTCA` |
| 23 | +kubectl get secret -n knative-serving knative-serving-certs -o json| jq -r '.data."ca-cert.pem"' | base64 -d > $ROOTCA |
| 24 | + |
| 25 | +echo "Create a temporary config-deployment configmap with the certificate" |
| 26 | +CERT=`kubectl create cm config-deployment --from-file $ROOTCA -o json --dry-run=client |jq .data.\"$FILENAME\"` |
| 27 | + |
| 28 | +echo "Get the current config-deployment configmap" |
| 29 | +CURRENT="$(mktemp)" |
| 30 | +kubectl get cm config-deployment -n knative-serving -o json | jq 'del(.data, .binaryData | ."queue-sidecar-token-audiences", ."queue-sidecar-rootca" )' > $CURRENT |
| 31 | + |
| 32 | +echo "Add queue-sidecar-token-audiences" |
| 33 | +AUDIENCES="$(mktemp)" |
| 34 | +jq '.data |= . + { "queue-sidecar-token-audiences": "guard-service"}' $CURRENT > $AUDIENCES |
| 35 | + |
| 36 | +echo "Join the two config-deployment configmaps into one" |
| 37 | +MERGED="$(mktemp)" |
| 38 | +jq --arg cert "${CERT}" '.data |= . + { "queue-sidecar-rootca": $cert}' $AUDIENCES > $MERGED |
| 39 | + |
| 40 | +echo "Apply the joined config-deployment configmap" |
| 41 | +kubectl apply -f $MERGED -n knative-serving |
| 42 | + |
| 43 | +echo "cleanup" |
| 44 | +rm $MERGED $AUDIENCES $ROOTCA $CURRENT |
| 45 | + |
| 46 | +echo "Results:" |
| 47 | +kubectl get cm config-deployment -n knative-serving -o json|jq '.data' |
0 commit comments