Skip to content

Commit

Permalink
Merge pull request #505 from cyberark/cli8
Browse files Browse the repository at this point in the history
Use Conjur CLI v8.0
  • Loading branch information
szh authored Mar 17, 2023
2 parents 512d42a + 3fc2e63 commit 88e9186
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion deploy/3_load_conjur_policies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if [[ "${DEPLOY_MASTER_CLUSTER}" == "true" ]]; then
$cli_with_timeout "cp ./policy $conjur_cli_pod:/policy"

$cli_with_timeout "exec $conjur_cli_pod -- \
bash -c \"
sh -c \"
CONJUR_ADMIN_PASSWORD=${CONJUR_ADMIN_PASSWORD} \
APP_NAMESPACE_NAME=${APP_NAMESPACE_NAME} \
/policy/load_policies.sh
Expand Down
2 changes: 1 addition & 1 deletion deploy/dev/reload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main() {
cert_location="/opt/conjur/etc/ssl/conjur.pem"
if [ "$CONJUR_DEPLOYMENT" = "oss" ]; then
selector="app=conjur-cli"
cert_location="/root/conjur-${CONJUR_ACCOUNT}.pem"
cert_location="/root/conjur-server.pem"
fi

conjur_pod_name="$(get_pod_name "$CONJUR_NAMESPACE_NAME" "$selector")"
Expand Down
40 changes: 19 additions & 21 deletions deploy/policy/load_policies.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
#!/bin/bash
#!/bin/sh
set -eo pipefail

if [ "$CONJUR_APPLIANCE_URL" != "" ]; then
echo "Running conjur init with $CONJUR_APPLIANCE_URL"
conjur init -u $CONJUR_APPLIANCE_URL -a $CONJUR_ACCOUNT
conjur init -u $CONJUR_APPLIANCE_URL -a $CONJUR_ACCOUNT --self-signed --force
fi

# check for unset vars after checking for appliance url
set -u

echo "Login to Conjur with the conjur-cli"
conjur authn login -u admin -p $CONJUR_ADMIN_PASSWORD
conjur login -i admin -p $CONJUR_ADMIN_PASSWORD

readonly POLICY_DIR="/policy"

# NOTE: generated files are prefixed with the test app namespace to allow for parallel CI
readonly POLICY_FILES=(
"$POLICY_DIR/users.yml"
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.project-authn.yml"
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.cluster-authn-svc.yml"
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.app-identity.yml"
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.conjur-secrets.yml"
set -- "$POLICY_DIR/users.yml" \
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.project-authn.yml" \
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.cluster-authn-svc.yml" \
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.app-identity.yml" \
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.conjur-secrets.yml" \
"$POLICY_DIR/generated/$APP_NAMESPACE_NAME.authn-any-policy-branch.yml"
)

for policy_file in "${POLICY_FILES[@]}"; do
for policy_file in "$@"; do
echo "Loading policy $policy_file..."
conjur policy load root "$policy_file"
conjur policy load -b root -f "$policy_file"
done

# the values of these secrets aren't important as we populate the secret that we
# are testing in each test. We need them to have some value as both are required
# in the pod
conjur variable values add secrets/test_secret "some-secret"
conjur variable values add "secrets/var with spaces" "some-secret"
conjur variable values add "secrets/var+with+pluses" "some-secret"
conjur variable values add "secrets/umlaut" "some-secret"
conjur variable values add secrets/url "postgresql://test-app-backend.app-test.svc.cluster.local:5432"
conjur variable values add secrets/username "some-user"
conjur variable values add secrets/password "7H1SiSmYp@5Sw0rd"

conjur authn logout
conjur variable set -i secrets/test_secret -v "some-secret"
conjur variable set -i "secrets/var with spaces" -v "some-secret"
conjur variable set -i "secrets/var+with+pluses" -v "some-secret"
conjur variable set -i "secrets/umlaut" -v "some-secret"
conjur variable set -i secrets/url -v "postgresql://test-app-backend.app-test.svc.cluster.local:5432"
conjur variable set -i secrets/username -v "some-user"
conjur variable set -i secrets/password -v "7H1SiSmYp@5Sw0rd"

conjur logout
4 changes: 3 additions & 1 deletion deploy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ main() {

deployConjur() {
pushd ..
git clone [email protected]:cyberark/kubernetes-conjur-deploy kubernetes-conjur-deploy-$UNIQUE_TEST_ID
git clone --single-branch --branch master \
[email protected]:cyberark/kubernetes-conjur-deploy \
kubernetes-conjur-deploy-$UNIQUE_TEST_ID

cmd="./start"
if [ $CONJUR_DEPLOYMENT = "oss" ]; then
Expand Down
2 changes: 1 addition & 1 deletion deploy/run_with_summon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ selector="role=follower"
cert_location="/opt/conjur/etc/ssl/conjur.pem"
if [ "$CONJUR_DEPLOYMENT" = "oss" ]; then
selector="app=conjur-cli"
cert_location="/root/conjur-${CONJUR_ACCOUNT}.pem"
cert_location="/root/conjur-server.pem"
fi
conjur_pod_name="$(get_pod_name "$CONJUR_NAMESPACE_NAME" "$selector")"
ssl_cert=$($cli_with_timeout "exec ${conjur_pod_name} --namespace $CONJUR_NAMESPACE_NAME -- cat $cert_location")
Expand Down
2 changes: 1 addition & 1 deletion deploy/teardown_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fi

set_namespace $CONJUR_NAMESPACE_NAME

$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable values add secrets/test_secret \"supersecret\""
$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable set -i secrets/test_secret -v \"supersecret\""

set_namespace $APP_NAMESPACE_NAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

# Deploy app to test against
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

helm_chart_name="secrets-provider"
Expand All @@ -33,7 +33,7 @@ pushd ../../
fill_helm_chart "another-"
helm install -f "../helm/secrets-provider/ci/another-test-values-$UNIQUE_TEST_ID.yaml" \
another-secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

# Wait for Job completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

# Check for Job completion
Expand All @@ -24,7 +24,7 @@ pushd ../../
fill_helm_chart "another-"
helm install -f "../helm/secrets-provider/ci/another-test-values-$UNIQUE_TEST_ID.yaml" \
another-secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

helm_chart_name="another-secrets-provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

# Check for Job completion
Expand All @@ -26,7 +26,7 @@ pushd ../../
fill_helm_chart "another-"
helm install -f "../helm/secrets-provider/ci/another-test-values-$UNIQUE_TEST_ID.yaml" \
another-secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

helm_chart_name="another-secrets-provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pushd ../../
fill_helm_chart_no_override_defaults
helm install -f "../helm/secrets-provider/ci/take-default-test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

# Validate that known defaults were taken if not supplied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

## Validate that resources were not created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

echo "Expecting Secrets Provider to fail with debug message 'CSPFK004D Failed to retrieve k8s secret. Reason: secrets K8S_SECRET-non-existent-secret not found'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pushd ../../
helm install -f "../helm/secrets-provider/ci/take-default-test-values-$UNIQUE_TEST_ID.yaml" \
-f "../helm/secrets-provider/ci/take-image-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

pod_name="$(get_pod_name "$APP_NAMESPACE_NAME" 'app=test-helm')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pushd ../../
fill_helm_chart
helm install -f "../helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ../helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="test/test_cases/conjur-server.pem"
popd

pod_name="$(get_pod_name "$APP_NAMESPACE_NAME" 'app=test-helm')"
Expand Down
3 changes: 2 additions & 1 deletion deploy/test/test_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ deployConjur() {
# from inside the container
docker pull $CONJUR_APPLIANCE_IMAGE

git clone [email protected]:cyberark/kubernetes-conjur-deploy \
git clone --single-branch --branch master \
[email protected]:cyberark/kubernetes-conjur-deploy \
kubernetes-conjur-deploy-$UNIQUE_TEST_ID

cmd="./start"
Expand Down
18 changes: 9 additions & 9 deletions deploy/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ configure_cli_pod() {

conjur_cli_pod=$(get_conjur_cli_pod_name)

$cli_with_timeout "exec $conjur_cli_pod -- bash -c \"yes yes | conjur init -a $CONJUR_ACCOUNT -u $conjur_url\""
$cli_with_timeout "exec $conjur_cli_pod -- sh -c \"echo y | conjur init -a $CONJUR_ACCOUNT -u $conjur_url --self-signed --force\""

$cli_with_timeout exec $conjur_cli_pod -- conjur authn login -u admin -p $CONJUR_ADMIN_PASSWORD
$cli_with_timeout exec $conjur_cli_pod -- conjur login -i admin -p $CONJUR_ADMIN_PASSWORD
}

configure_conjur_url() {
Expand All @@ -216,7 +216,7 @@ fetch_ssl_from_conjur() {
cert_location="/opt/conjur/etc/ssl/conjur.pem"
if [ "$CONJUR_DEPLOYMENT" = "oss" ]; then
selector="app=conjur-cli"
export cert_location="/root/conjur-${CONJUR_ACCOUNT}.pem"
export cert_location="/root/conjur-server.pem"
fi

export conjur_pod_name="$(get_pod_name "$CONJUR_NAMESPACE_NAME" "$selector")"
Expand All @@ -227,9 +227,9 @@ setup_helm_environment() {

configure_conjur_url

ssl_location="conjur-$UNIQUE_TEST_ID.pem"
ssl_location="conjur-server.pem"
if [ "${DEV}" = "true" ]; then
ssl_location="../conjur-$UNIQUE_TEST_ID.pem"
ssl_location="../conjur-server.pem"
fi

fetch_ssl_from_conjur
Expand Down Expand Up @@ -327,7 +327,7 @@ deploy_chart() {
fill_helm_chart
helm install -f "helm/secrets-provider/ci/test-values-$UNIQUE_TEST_ID.yaml" \
secrets-provider ./helm/secrets-provider \
--set-file environment.conjur.sslCertificate.value="conjur-$UNIQUE_TEST_ID.pem"
--set-file environment.conjur.sslCertificate.value="conjur-server.pem"
popd
}

Expand Down Expand Up @@ -444,7 +444,7 @@ set_conjur_secret() {
echo "Set secret '$SECRET_NAME' to '$SECRET_VALUE'"
set_namespace "$CONJUR_NAMESPACE_NAME"
configure_cli_pod
$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable values add $SECRET_NAME $SECRET_VALUE"
$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- conjur variable set -i $SECRET_NAME -v $SECRET_VALUE"
set_namespace $APP_NAMESPACE_NAME
}

Expand All @@ -471,7 +471,7 @@ load_policy() {
$cli_with_timeout "cp ../../policy $conjur_cli_pod:/policy"

$cli_with_timeout "exec $(get_conjur_cli_pod_name) -- \
conjur policy load --delete root \"/policy/generated/$APP_NAMESPACE_NAME.$filename.yml\""
conjur policy update -b root -f \"/policy/generated/$APP_NAMESPACE_NAME.$filename.yml\""

$cli_with_timeout "exec $conjur_cli_pod -- rm -rf ./policy"

Expand Down Expand Up @@ -504,7 +504,7 @@ test_secret_is_provided() {

set_namespace "$CONJUR_NAMESPACE_NAME"
conjur_cli_pod=$(get_conjur_cli_pod_name)
$cli_with_timeout "exec $conjur_cli_pod -- conjur variable values add \"$variable_name\" $secret_value"
$cli_with_timeout "exec $conjur_cli_pod -- conjur variable set -i \"$variable_name\" -v $secret_value"

set_namespace "$APP_NAMESPACE_NAME"
deploy_init_env
Expand Down

0 comments on commit 88e9186

Please sign in to comment.