Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Support restricted PSA enforcement part 2 into release/1.0.x #2740

Conversation

hc-github-team-consul-core

Backport

This PR is auto-generated from #2702 to be assessed for backporting due to the inclusion of the label backport/1.0.x.

🚨

Warning automatic cherry-pick of commits failed. If the first commit failed,
you will see a blank no-op commit below. If at least one commit succeeded, you
will see the cherry-picked commits up to, not including, the commit where
the merge conflict occurred.

The person who merged in the original PR is:
@pglass
This person should manually cherry-pick the original PR into a new backport PR,
and close this one when the manual backport PR is merged in.

merge conflict error: POST https://api.github.com/repos/hashicorp/consul-k8s/merges: 409 Merge conflict []

The below text is copied from the body of the original PR.


Changes proposed in this PR:

Part 2 of #2572.

Update the following to set a "restricted" security context:

  • create-federation-secret-job.yaml
  • ingress-gateways-deployment.yaml
  • mesh-gateway-deployment.yaml
    • This is not included because adding the "restricted" security context settings to MGW makes it impossible to use hostNetwork=true
  • partition-init-job.yaml
  • terminating-gateways-deployment.yaml
  • sync-catalog-deployment.yaml

Also, fix a WAN federation test to run on kind

How I've tested this PR:

Run acceptance tests on kind with restricted PSA enforcement enabled on the consul namespace (see script)

  • Run the WAN fed test that is fixed in this PR, in order to validate the create federation secret job and mesh gateway deployment
  • Run TestTerminatingGateway and TestIngressGateway and manually validate the gateways start and run successfully in the restricted consul namespace
    • (note: these tests fail when test applications are deployed to a restricted namespace, because the test applications do not support running in a restricted namespace)
  • Run TestPartitions_Gateway and manually validate the partitions-init job succeeds

Test script:

  • Run make kind and then ./test-psa-kind.sh (no tproxy) or ./test-psa-kind.sh -tproxy (tproxy enabled). Toggle comments at the bottom to try to run other tests.
  • Run make kind-cni and ./test-psa-kind.sh -cni to test with tproxy+cni
Test script
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

export CONSUL_LICENSE=$(cat ~/.consul-ent-license)
export CONSUL_ENT_LICENSE=$CONSUL_LICENSE

# Cleanup old namespaces
# for context in $(kubectl config get-contexts -o name | grep '^kind-') ; do
for context in kind-dc1 kind-dc2 ; do
    kubectl --context $context get ns \
		| grep ^acceptance | awk '{print $1}' \
		| xargs -n 1 -I '{}' kubectl --context $context delete ns '{}' || true
done

EXTRA_FLAGS=""

while [[ $# -gt 0 ]]; do
    case $1 in
        -tproxy)
            EXTRA_FLAGS+=" -enable-transparent-proxy"
            shift;
            ;;
        -cni)
            EXTRA_FLAGS+=" -enable-cni -enable-transparent-proxy"
            shift;
            ;;
        *)
            echo "Unrecognized argument: '$1'"
            exit 1
    esac
done

function runtest() {
    local testdir=$1
    local runtest=$2

    if [ -n "$runtest" ]; then
        runtest="-run $runtest"
    fi

    # Create consul namespaces with restricted PSA enformcement.
    set -xeuo pipefail

    local ns_base="acceptance-$1-$RANDOM"
    local contexts=""
    local namespaces=""
    #for context in $(kubectl config get-contexts -o name | grep '^kind-') ; do
    for context in kind-dc1 kind-dc2 ; do
        local consul_namespace="${ns_base}-$context"
        kubectl --context $context create ns $consul_namespace
        kubectl --context $context label --overwrite ns $consul_namespace \
            pod-security.kubernetes.io/enforce=restricted \
            pod-security.kubernetes.io/enforce-version=v1.24

        if [ -n "$contexts" ]; then
            contexts+=","
            namespaces+=","
        fi
        contexts+="$context"
        namespaces+="$consul_namespace"
    done

    # Grab the default image versions from the helm values.
    imageK8S=$(cat ../charts/consul/values.yaml | yq -r '.global.imageK8S' \
        | sed 's/-dev/-dev-ubi/')
    imageConsul=$(cat ../charts/consul/values.yaml | yq -r '.global.image' \
        | sed 's/consul:/consul-enterprise:/' | sed 's/-dev/-dev-ubi/')
    imageDataplane=$(cat ../charts/consul/values.yaml | yq -r '.global.imageConsulDataplane' \
        | sed 's/-dev/-dev-ubi/')

    cd "${SCRIPT_DIR}/tests/$testdir"
    rm -rf ./_debug
    mkdir ./_debug
    go test  -v -p 1 -timeout 15m -failfast \
        -consul-k8s-image "$imageK8S" \
        -consul-image "$imageConsul" \
        -consul-dataplane-image "$imageDataplane" \
        -debug-directory ./_debug \
        -enable-enterprise \
        -kube-contexts "$contexts" \
        -kube-namespaces "$namespaces" \
        -enable-multi-cluster -use-kind \
        -enable-restricted-psa-enforcement \
        $EXTRA_FLAGS $runtest \
        ./...
}

runtest "connect" 'TestConnectInject$'
runtest wan-federation 'TestWANFederation/secure'
#runtest terminating-gateway 'TestTerminatingGateway$/secure:_true'
#runtest terminating-gateway 'TestTerminatingGatewaySingleNamespace'
#runtest ingress-gateway 'TestIngressGatewaySingleNamespace'
#runtest ingress-gateway 'TestIngressGateway$/secure:_true'
#runtest cloud 'TestBasicCloud'
#runtest partitions 'TestPartitions_Connect/default_destination_namespace'

How I expect reviewers to test this PR:

Checklist:


Overview of commits

@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/pglass/NET-185/psa-enforcement-openshift-2/globally-settled-kingfish branch from c1c4ff8 to 18a8b43 Compare August 8, 2023 14:48
@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/pglass/NET-185/psa-enforcement-openshift-2/globally-settled-kingfish branch from 18a8b43 to c1c4ff8 Compare August 8, 2023 14:48
@hashicorp-cla
Copy link

hashicorp-cla commented Aug 8, 2023

CLA assistant check
All committers have signed the CLA.

@pglass pglass force-pushed the backport/pglass/NET-185/psa-enforcement-openshift-2/globally-settled-kingfish branch from db63a40 to 91151d3 Compare August 8, 2023 14:59
@pglass pglass force-pushed the backport/pglass/NET-185/psa-enforcement-openshift-2/globally-settled-kingfish branch from 91151d3 to cea1a2e Compare August 8, 2023 15:05
@pglass pglass marked this pull request as ready for review August 8, 2023 15:06
@pglass pglass enabled auto-merge (squash) August 8, 2023 15:09
@pglass pglass merged commit 326e87f into release/1.0.x Aug 8, 2023
3 checks passed
@pglass pglass deleted the backport/pglass/NET-185/psa-enforcement-openshift-2/globally-settled-kingfish branch August 8, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants