From d018bd2372ea14d8178dd4249b79d236bf3c9e16 Mon Sep 17 00:00:00 2001 From: John ODonnell Date: Fri, 10 Dec 2021 17:30:52 -0500 Subject: [PATCH 1/2] Small bug fixes - Redirect stdout to /dev/null during client gen - Update command for colorful announce messages - Address deprecation warning in docker-compose network declaration --- bin/generate_client | 2 +- bin/util | 4 ++-- docker-compose.yml | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/generate_client b/bin/generate_client index fa6cf79b..381befe9 100755 --- a/bin/generate_client +++ b/bin/generate_client @@ -140,6 +140,6 @@ docker run --rm \ -g "$client_lang" \ -o "/out/" \ $client_config \ - $template_arg + $template_arg 1> /dev/null echo "Done! Client is in $output_volume folder!" diff --git a/bin/util b/bin/util index 7ffbeef9..0d1b9eb3 100755 --- a/bin/util +++ b/bin/util @@ -14,9 +14,9 @@ function get_banner(){ function announce() { banner=$(get_banner $@) - echo -e "\e[0;32m$banner" + echo -e "\033[0;32m$banner" echo -e "$@" - echo -e "$banner\e[m" + echo -e "$banner\033[m" } function ensure_client_is_generated(){ diff --git a/docker-compose.yml b/docker-compose.yml index f13a40ae..4b349d4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -148,5 +148,4 @@ services: networks: default: - external: - name: openapi-spec + name: openapi-spec From bf41c9f55f38db802709a44ec8f6e600496d49f3 Mon Sep 17 00:00:00 2001 From: John ODonnell Date: Fri, 18 Mar 2022 13:12:44 -0400 Subject: [PATCH 2/2] Allow deployment of stable Conjur version --- bin/generate_postman_collection | 2 +- bin/start_conjur | 36 +++++++++++++++++++++++++++++++++ bin/test_api_contract | 7 +++++++ bin/test_integration | 12 ++++++++--- bin/util | 12 ++++++++++- docker-compose.yml | 2 +- examples/kong/start | 15 ++++++++------ examples/python/start | 6 ++---- examples/ruby/start | 6 ++---- 9 files changed, 78 insertions(+), 20 deletions(-) diff --git a/bin/generate_postman_collection b/bin/generate_postman_collection index bb7dc048..f1c398a0 100755 --- a/bin/generate_postman_collection +++ b/bin/generate_postman_collection @@ -56,7 +56,7 @@ cmd="python3 examples/postman/postman_env_setup.py" arg="" if [[ local_env -eq 1 ]]; then - ensure_conjur_up + ensure_conjur_up latest export CONJUR_AUTHN_API_KEY="$(docker-compose exec conjur conjurctl role retrieve-key dev:user:admin | tr -d '\r')" diff --git a/bin/start_conjur b/bin/start_conjur index 7c1afcc3..acea41b7 100755 --- a/bin/start_conjur +++ b/bin/start_conjur @@ -1,6 +1,41 @@ #!/usr/bin/env bash source bin/util +print_help() { + cat << EOF +This script starts Conjur Open Source in a docker-compose environment. + +USAGE +./bin/start_conjur [options] + +OPTIONS +-h|--help Print help message. +-s|--stable Start the latest stable version of Conjur Open Source. + By default, the 'edge' version is used, which includes as yet + unreleased content. +EOF +} + +conjur_tag="" + +while test $# -gt 0 +do + param=$1 + shift + case "$param" in + -h|--help) + print_help + exit 0 + ;; + -s|--stable) + conjur_tag="latest" + ;; + *) + break + ;; + esac +done + cleanup() { echo "Cleaning up..." docker-compose rm --stop --force -v @@ -23,6 +58,7 @@ echo "Building services..." docker-compose build pg conjur conjur-https # Start Conjur server +export CONJUR_OPEN_SOURCE_IMAGE_TAG="${conjur_tag:-$CONJUR_OPEN_SOURCE_IMAGE_TAG}" echo "Starting Conjur..." docker-compose up -d conjur conjur-https docker-compose exec -T conjur conjurctl wait diff --git a/bin/test_api_contract b/bin/test_api_contract index f32f952b..be7bd4aa 100755 --- a/bin/test_api_contract +++ b/bin/test_api_contract @@ -2,6 +2,7 @@ source bin/util endpoint_flag="" +conjur_tag="latest" while test $# -gt 0; do case "$1" in @@ -16,6 +17,7 @@ while test $# -gt 0; do echo echo "-h, --help show help" echo "-e, --endpoint test endpoints starting with the given path" + echo "-s, --stable test against the latest stable version of Conjur Open Source" exit 0 ;; -e|--endpoint) @@ -27,6 +29,10 @@ while test $# -gt 0; do fi shift ;; + -s|--stable) + conjur_tag="edge" + shift + ;; *) break ;; @@ -35,6 +41,7 @@ done if [[ -z "$(docker-compose ps -q)" ]]; then announce "Environment not found. Spinning up..." + export CONJUR_OPEN_SOURCE_IMAGE_TAG="$conjur_tag" ./bin/start_conjur 1> /dev/null echo fi diff --git a/bin/test_integration b/bin/test_integration index 2d7c70a0..f3c2be88 100755 --- a/bin/test_integration +++ b/bin/test_integration @@ -27,6 +27,7 @@ OPTIONS This option does not maintaing Conjur Enterprise. WARNING: may cause failing test cases. --no-regen-client Prevent the script from re-generating the client library. +-s|--stable Runs tests against the latest stable version of Conjur Open Source. -t|--test Runs a given test in a client test suite. EOF } @@ -42,6 +43,7 @@ enterprise=0 appliance="oss" enterprise_params="" docker_network="openapi-spec" +conjur_open_source_tag="edge" no_regen_client=0 no_rebuid_conjur=0 @@ -87,6 +89,9 @@ do --no-regen-client) no_regen_client=1 ;; + -s|--stable) + conjur_open_source_tag="latest" + ;; -t|--test) test="$1" shift @@ -197,11 +202,12 @@ if [[ $no_rebuild_conjur -eq 0 || ( $(conjur_alive) -eq 1 && $enterprise -eq 0 ) || ( $(enterprise_alive) -eq 1 && $enterprise -eq 1 ) ]]; then if [[ $enterprise -eq 0 ]]; then - announce "Starting Conjur OSS" - bin/start_conjur + announce "Starting Conjur OSS" + export CONJUR_OPEN_SOURCE_IMAGE_TAG="$conjur_open_source_tag" + bin/start_conjur else announce "Starting Conjur Enterprise" - bin/start_enterprise + bin/start_enterprise pushd ./test/dap-intro # Create the parameter to import volumes from the Enterprise container so we have its certificates diff --git a/bin/util b/bin/util index 0d1b9eb3..36dd10b0 100755 --- a/bin/util +++ b/bin/util @@ -41,11 +41,21 @@ function ensure_client_is_generated(){ } function ensure_conjur_up(){ + desired_tag="$1" + export CONJUR_OPEN_SOURCE_IMAGE_TAG="$desired_tag" if [ -z $(docker-compose ps -q conjur) ]; then announce "Starting Conjur container" ./bin/start_conjur else - announce "Conjur already up!" + docker ps | grep openapi | grep cyberark/conjur | grep $desired_tag > /dev/null + desired_tag_deployed="$?" + if [[ "$desired_tag_deployed" == "0" ]]; then + announce "Conjur already up!" + else + announce "Conjur not deployed with tag $desired_tag. Re-deploying..." + ./bin/stop + ./bin/start_conjur + fi fi } diff --git a/docker-compose.yml b/docker-compose.yml index 4b349d4e..9dbd56ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: POSTGRES_HOST_AUTH_METHOD: trust conjur: - image: cyberark/conjur:edge + image: cyberark/conjur:${CONJUR_OPEN_SOURCE_IMAGE_TAG:-edge} command: server -a dev -f /policy/policy.yaml environment: CONJUR_DATA_KEY: 'OyXV68Mip14xj33huGaQKewmmS+gKtDlp6ECZ2iATpU=' diff --git a/examples/kong/start b/examples/kong/start index 80f09ca1..a7e9de41 100755 --- a/examples/kong/start +++ b/examples/kong/start @@ -39,27 +39,30 @@ announce "Ensure Kong Gateway is active" if [[ -z $(curl -s http://localhost:8001/services/Conjur | grep '"name":"Conjur"') ]]; then echo "Kong setup failed" exit 1 -else - echo "Kong setup successful" fi announce "Making requests to Conjur through Kong Gateway" -ensure_conjur_up +set +e +ensure_conjur_up latest sleep 10 +set -e admin_api_key="$(docker-compose exec -T conjur conjurctl role retrieve-key dev:user:admin | tr -d '\r')" token="$(curl -s http://localhost:8000/authn/dev/admin/authenticate \ --header "Accept-Encoding: base64" \ --data $admin_api_key)" -secret_data="Hello World!" +curl -X POST http://localhost:8000/policies/dev/policy/root \ + -H "Authorization: Token token=\"$token\"" \ + --data "$(< examples/config/policy.yml)" 1> /dev/null -curl -is http://localhost:8000/secrets/dev/variable/testSecret \ +secret_data="Hello World!" +curl -is http://localhost:8000/secrets/dev/variable/sampleSecret \ -H "Authorization: Token token=\"$token\"" \ --data "$secret_data" -retrieved_secret="$(curl http://localhost:8000/secrets/dev/variable/testSecret \ +retrieved_secret="$(curl http://localhost:8000/secrets/dev/variable/sampleSecret \ -H "Authorization: Token token=\"$token\"")" if [ "$secret_data" == "$retrieved_secret" ]; then diff --git a/examples/python/start b/examples/python/start index 07ed0670..b6448404 100755 --- a/examples/python/start +++ b/examples/python/start @@ -1,10 +1,8 @@ #!/bin/bash -set -e - source ./bin/util -ensure_client_is_generated python conjur -ensure_conjur_up +ensure_client_is_generated python oss +ensure_conjur_up latest export CONJUR_ADMIN_API_KEY=$(get_conjur_admin_api_key) diff --git a/examples/ruby/start b/examples/ruby/start index bf29333c..141cc026 100755 --- a/examples/ruby/start +++ b/examples/ruby/start @@ -1,10 +1,8 @@ #!/bin/bash -set -e - source ./bin/util -ensure_client_is_generated ruby conjur -ensure_conjur_up +ensure_client_is_generated ruby oss +ensure_conjur_up latest # Remove the gem if it is already built so we dont create a gemfile # which contains itself when we build