From a2fce5ab5b0536f1ea4853a3283587e9a726ee97 Mon Sep 17 00:00:00 2001 From: Romain Arnaud Date: Thu, 15 Feb 2024 11:41:41 -0500 Subject: [PATCH] Migrate Tekton Chains to an ExternalSecret In order to facilitate backup/restore of a cluster, the signing secret is now stored externally and deployed on the cluster using an ExternalSecret. The original behavior is maintained for local development. rh-pre-commit.version: 2.1.0 rh-pre-commit.check-secrets: ENABLED --- developer/openshift/apps/pipeline-service.sh | 11 ++-- .../openshift/gitops/local/kustomization.yaml | 3 +- .../chains-secrets-config.yaml | 55 +++++++++++++++++++ .../openshift-pipelines/kustomization.yaml | 6 ++ .../local/openshift-pipelines/namespace.yaml | 10 ++++ .../openshift-pipelines/kustomization.yaml | 2 +- ...ets-config.yaml => public-key-secret.yaml} | 31 ++--------- operator/test/test.sh | 21 +------ 8 files changed, 86 insertions(+), 53 deletions(-) create mode 100644 developer/openshift/gitops/local/openshift-pipelines/chains-secrets-config.yaml create mode 100644 developer/openshift/gitops/local/openshift-pipelines/kustomization.yaml create mode 100644 developer/openshift/gitops/local/openshift-pipelines/namespace.yaml rename operator/gitops/argocd/pipeline-service/openshift-pipelines/{chains-secrets-config.yaml => public-key-secret.yaml} (62%) diff --git a/developer/openshift/apps/pipeline-service.sh b/developer/openshift/apps/pipeline-service.sh index c800c13e5..3b1a93cb4 100755 --- a/developer/openshift/apps/pipeline-service.sh +++ b/developer/openshift/apps/pipeline-service.sh @@ -17,10 +17,10 @@ setup_work_dir() { setup_tekton_results | indent } -configure_argocd_apps(){ +configure_argocd_apps() { echo -n "- Updating source repository to '${GIT_URL}/tree/$GIT_REF': " # Patch the url/branch to target the expected repository/branch - yq --inplace ".resources[1] = \"$GIT_URL/developer/openshift/gitops/argocd?ref=$GIT_REF\"" "$manifests_dir/kustomization.yaml" + yq --inplace ".resources[0] = \"$GIT_URL/developer/openshift/gitops/argocd?ref=$GIT_REF\"" "$manifests_dir/kustomization.yaml" yq ".patches[] | .path" "$manifests_dir/kustomization.yaml" | while read -r patch; do yq --inplace ".spec.source.repoURL = \"$GIT_URL\", .spec.source.targetRevision = \"$GIT_REF\"" "$manifests_dir/$patch" done @@ -42,7 +42,7 @@ get_tekton_results_credentials() { TEKTON_RESULTS_DATABASE_PASSWORD="$(yq ".tekton_results_db.password // \"$(openssl rand -base64 20)\"" "$CONFIG")" TEKTON_RESULTS_S3_USER="$(yq '.tekton_results_s3.user // "minio"' "$CONFIG")" TEKTON_RESULTS_S3_PASSWORD="$(yq ".tekton_results_s3.password // \"$(openssl rand -base64 20)\"" "$CONFIG")" - cat << EOF > "$tekton_results_credentials" + cat <"$tekton_results_credentials" --- db_password: $TEKTON_RESULTS_DATABASE_PASSWORD db_user: $TEKTON_RESULTS_DATABASE_USER @@ -56,7 +56,7 @@ EOF TEKTON_RESULTS_S3_PASSWORD="$(yq ".s3_password" "$tekton_results_credentials")" } -patch_tekton_results_manifests(){ +patch_tekton_results_manifests() { yq --inplace " .data.[\"db.password\"]=\"$(echo -n "$TEKTON_RESULTS_DATABASE_PASSWORD" | base64)\", .data.[\"db.user\"]=\"$(echo -n "$TEKTON_RESULTS_DATABASE_USER" | base64)\" @@ -65,7 +65,8 @@ patch_tekton_results_manifests(){ .data.aws_access_key_id=\"$(echo -n "$TEKTON_RESULTS_S3_USER" | base64)\", .data.aws_secret_access_key=\"$(echo -n "$TEKTON_RESULTS_S3_PASSWORD" | base64)\" " "$WORK_DIR/environment/compute/tekton-results/tekton-results-s3-secret.yaml" - string_data="$(cat <"$DEBUG_OUTPUT"; then echo "[ERROR] Pipeline failed to complete successful" >&2 - kubectl get pipelineruns "$1" -n "$2" >"$DEBUG_OUTPUT" + kubectl get "$1" -n "$2" >"$DEBUG_OUTPUT" exit 1 fi } @@ -160,11 +160,6 @@ test_chains() { echo "[ERROR] Secret does not exist" >&2 exit 1 fi - if [ "$(kubectl get secret signing-secrets -n openshift-pipelines -o jsonpath='{.immutable}')" != "true" ]; then - echo "Failed" - echo "[ERROR] Secret is not immutable" >&2 - exit 1 - fi echo "OK" # Trigger the pipeline @@ -231,20 +226,6 @@ test_chains() { exit 1 fi - # TODO: Reactivate on step 2/3 of the migration. - # This test is not critical until we ask EC to use the openshift-pipelines namespace. - # echo -n " - Public key migration: " - # pipeline_name=$(kubectl create -f "$SCRIPT_DIR/manifests/test/tekton-chains/public-key-migration.yaml" -n "$NAMESPACE" | cut -d' ' -f1) - # wait_for_pipeline "$pipeline_name" "$NAMESPACE" - # if [ "$(kubectl get "$pipeline_name" -n "$NAMESPACE" \ - # -o 'jsonpath={.status.conditions[0].reason}')" = "Succeeded" ]; then - # echo "OK" - # else - # echo "Failed" - # echo "[ERROR] Public key is not accessible" >&2 - # exit 1 - # fi - echo -n " - Metrics: " prName="$(kubectl create -n "$NAMESPACE" -f "$SCRIPT_DIR/manifests/test/tekton-chains/tekton-chains-metrics.yaml" | awk '{print $1}')" wait_for_pipeline "$prName" "$NAMESPACE"