Skip to content

Commit

Permalink
CI test cases exist for using deployment name as k8s authn ID
Browse files Browse the repository at this point in the history
Adds CI test cases that use the Kubernetes authentication plugin
in both GKE and OpenShift environments, using Deployment name
(rather than the default service account name) as a Kubernetes
authentication ID.

Addresses Issue #92
  • Loading branch information
diverdane committed Mar 4, 2020
1 parent e428c92 commit d3e408a
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 53 deletions.
4 changes: 4 additions & 0 deletions 4_store_conjur_cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ echo "Retrieving Conjur certificate."

if $cli get pods --selector role=follower --no-headers; then
follower_pod_name=$($cli get pods --selector role=follower --no-headers | awk '{ print $1 }' | head -1)
$cli exec $follower_pod_name -- sed -i "s/:info/:debug/" /opt/conjur/possum/config/environments/appliance.rb
$cli exec $follower_pod_name -- sv restart conjur/possum
echo "****TEMP**** Sleep for 20 seconds to allow for possum restart"
sleep 20
ssl_cert=$($cli exec $follower_pod_name -- cat /opt/conjur/etc/ssl/conjur.pem)
else
echo "Regular follower not found. Trying to assume a decomposed follower..."
Expand Down
37 changes: 33 additions & 4 deletions 7_verify_authentication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,51 @@ set_namespace "$TEST_APP_NAMESPACE_NAME"

echo "Waiting for pods to become available"

retry_count=0
check_pods(){
let "retry_count++"
if [[ $retry_count -eq 140 ]]; then
echo Conjur namespace: $CONJUR_NAMESPACE_NAME
master_pod_name=$($cli get pods -n $CONJUR_NAMESPACE_NAME --selector role=master --no-headers | awk '{ print $1 }' | head -1)
echo Master pod: $master_pod_name
follower_pod_name=$($cli get pods -n $CONJUR_NAMESPACE_NAME --selector role=follower --no-headers | awk '{ print $1 }' | head -1)
echo Follower pod: $follower_pod_name
announce "Dumping master pod logs."
$cli logs -n $CONJUR_NAMESPACE_NAME $master_pod_name
announce "Dumping follower pod logs."
$cli logs -n $CONJUR_NAMESPACE_NAME $follower_pod_name
announce "Getting Kubernetes events."
$cli get events -n $CONJUR_NAMESPACE_NAME
else
echo Retry count: $retry_count
fi
pods_ready "test-app-summon-init" &&
pods_ready "test-app-with-host-outside-apps-branch-summon-init" &&
pods_ready "test-app-summon-sidecar" &&
pods_ready "test-app-secretless"
}
bl_retry_constant "${RETRIES}" "${RETRY_WAIT}" check_pods

echo Conjur namespace: $CONJUR_NAMESPACE_NAME
master_pod_name=$($cli get pods -n $CONJUR_NAMESPACE_NAME --selector role=master --no-headers | awk '{ print $1 }' | head -1)
echo Master pod: $master_pod_name
follower_pod_name=$($cli get pods -n $CONJUR_NAMESPACE_NAME --selector role=follower --no-headers | awk '{ print $1 }' | head -1)
echo Follower pod: $follower_pod_name
announce "Dumping master pod logs."
$cli logs -n $CONJUR_NAMESPACE_NAME $master_pod_name
announce "Dumping follower pod logs."
$cli logs -n $CONJUR_NAMESPACE_NAME $follower_pod_name
announce "Getting Kubernetes events."
$cli get events -n $CONJUR_NAMESPACE_NAME

if [[ "$PLATFORM" == "openshift" ]]; then
echo "Waiting for deployments to become available"

check_deployment_status(){
[[ "$(deployment_status "test-app-summon-init")" == "Complete" ]] &&
[[ "$(deployment_status "test-app-with-host-outside-apps-branch-summon-init")" == "Complete" ]] &&
[[ "$(deployment_status "test-app-summon-sidecar")" == "Complete" ]] &&
[[ "$(deployment_status "test-app-secretless")" == "Complete" ]]
[[ "$(deployment_status "oc-test-app-summon-init")" == "Complete" ]] &&
[[ "$(deployment_status "oc-test-app-with-host-outside-apps-branch-summon-init")" == "Complete" ]] &&
[[ "$(deployment_status "oc-test-app-summon-sidecar")" == "Complete" ]] &&
[[ "$(deployment_status "oc-test-app-secretless")" == "Complete" ]]
}
bl_retry_constant "${RETRIES}" "${RETRY_WAIT}" check_deployment_status

Expand Down
92 changes: 52 additions & 40 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,72 @@ pipeline {
// Postgres Tests
stage('Deploy Demos Postgres') {
parallel {
stage('GKE, v5 Conjur, Postgres') {
steps {
sh 'cd ci && summon --environment gke ./test gke postgres'
}
}
//stage('GKE, v5 Conjur, Postgres') {
// steps {
// sh 'cd ci && summon --environment gke ./test gke postgres'
// }
//}

stage('OpenShift v3.9, v5 Conjur, Postgres') {
steps {
sh 'cd ci && summon --environment oc ./test oc postgres'
}
}
//stage('GKE, v5 Conjur, Postgres, Deployment Authn ID') {
// steps {
// sh 'cd ci && CONJUR_AUTHN_LOGIN_RESOURCE=deployment summon --environment gke ./test gke postgres'
// }
//}

stage('OpenShift v3.10, v5 Conjur, Postgres') {
steps {
sh 'cd ci && summon --environment oc310 ./test oc postgres'
}
}
//stage('OpenShift v3.9, v5 Conjur, Postgres') {
// steps {
// sh 'cd ci && summon --environment oc ./test oc postgres'
// }
//}

//stage('OpenShift v3.10, v5 Conjur, Postgres') {
// steps {
// sh 'cd ci && summon --environment oc310 ./test oc postgres'
// }
//}

stage('OpenShift v3.11, v5 Conjur, Postgres') {
steps {
sh 'cd ci && summon --environment oc311 ./test oc postgres'
}
}
}
}

// MySQL Tests
stage('Deploy Demos MySQL') {
parallel {
stage('GKE, v5 Conjur, MySQL') {
steps {
sh 'cd ci && summon --environment gke ./test gke mysql'
}
}

stage('OpenShift v3.9, v5 Conjur, MySQL') {
steps {
sh 'cd ci && summon --environment oc ./test oc mysql'
}
}

stage('OpenShift v3.10, v5 Conjur, MySQL') {
stage('OpenShift v3.11, v5 Conjur, Postgres, Deployment Authn ID') {
steps {
sh 'cd ci && summon --environment oc310 ./test oc mysql'
}
}

stage('OpenShift v3.11, v5 Conjur, MySQL') {
steps {
sh 'cd ci && summon --environment oc311 ./test oc mysql'
sh 'cd ci && CONJUR_AUTHN_LOGIN_RESOURCE=deployment_config summon --environment oc311 ./test oc postgres'
}
}
}
}

// MySQL Tests
// stage('Deploy Demos MySQL') {
// parallel {
// stage('GKE, v5 Conjur, MySQL') {
// steps {
// sh 'cd ci && summon --environment gke ./test gke mysql'
// }
// }
//
// stage('OpenShift v3.9, v5 Conjur, MySQL') {
// steps {
// sh 'cd ci && summon --environment oc ./test oc mysql'
// }
// }
//
// stage('OpenShift v3.10, v5 Conjur, MySQL') {
// steps {
// sh 'cd ci && summon --environment oc310 ./test oc mysql'
// }
// }
//
// stage('OpenShift v3.11, v5 Conjur, MySQL') {
// steps {
// sh 'cd ci && summon --environment oc311 ./test oc mysql'
// }
// }
// }
// }
}

post {
Expand Down
8 changes: 6 additions & 2 deletions ci/test
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ function main() {

function deployConjur() {
pushd ..
git clone --single-branch --branch master [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
git clone --single-branch --branch openshift_deploy_configs [email protected]:cyberark/kubernetes-conjur-deploy kubernetes-conjur-deploy-$UNIQUE_TEST_ID
popd

runDockerCommand "cd kubernetes-conjur-deploy-$UNIQUE_TEST_ID && ./start"
runDockerCommand "cd kubernetes-conjur-deploy-$UNIQUE_TEST_ID && CONJUR_LOG_LEVEL=debug ./start"
}

function deployDemo() {
Expand Down Expand Up @@ -100,6 +101,8 @@ function prepareTestEnvironment() {

export CONJUR_APPLIANCE_IMAGE=$registry:5.0-stable

export CONJUR_AUTHN_LOGIN_RESOURCE="${CONJUR_AUTHN_LOGIN_RESOURCE:-service_account}"

# Prepare Docker images
docker pull $CONJUR_APPLIANCE_IMAGE
docker build --tag $CONJUR_DEMO_TEST_IMAGE:$CONJUR_NAMESPACE_NAME \
Expand Down Expand Up @@ -136,6 +139,7 @@ function runDockerCommand() {
-e CONJUR_NAMESPACE_NAME \
-e CONJUR_ACCOUNT \
-e CONJUR_ADMIN_PASSWORD \
-e CONJUR_AUTHN_LOGIN_RESOURCE \
-e AUTHENTICATOR_ID \
-e TEST_APP_NAMESPACE_NAME \
-e TEST_APP_DATABASE \
Expand Down
2 changes: 1 addition & 1 deletion openshift/test-app-secretless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kind: DeploymentConfig
metadata:
labels:
app: test-app-secretless
name: test-app-secretless
name: oc-test-app-secretless
spec:
replicas: 1
selector:
Expand Down
2 changes: 1 addition & 1 deletion openshift/test-app-summon-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kind: DeploymentConfig
metadata:
labels:
app: test-app-summon-init
name: test-app-summon-init
name: oc-test-app-summon-init
spec:
replicas: 1
selector:
Expand Down
2 changes: 1 addition & 1 deletion openshift/test-app-summon-sidecar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kind: DeploymentConfig
metadata:
labels:
app: test-app-summon-sidecar
name: test-app-summon-sidecar
name: oc-test-app-summon-sidecar
spec:
replicas: 1
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kind: DeploymentConfig
metadata:
labels:
app: test-app-with-host-outside-apps-branch-summon-init
name: test-app-with-host-outside-apps-branch-summon-init
name: oc-test-app-with-host-outside-apps-branch-summon-init
spec:
replicas: 1
selector:
Expand Down
6 changes: 3 additions & 3 deletions policy/templates/project-authn-def.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
kubernetes/authentication-container-name: authenticator
openshift: "{{ IS_OPENSHIFT }}"
- !host
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment/oc-test-app-summon-sidecar
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment_config/oc-test-app-summon-sidecar
annotations:
kubernetes/authentication-container-name: authenticator
openshift: "{{ IS_OPENSHIFT }}"
Expand All @@ -63,7 +63,7 @@
kubernetes/authentication-container-name: authenticator
openshift: "{{ IS_OPENSHIFT }}"
- !host
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment/oc-test-app-summon-init
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment_config/oc-test-app-summon-init
annotations:
kubernetes/authentication-container-name: authenticator
openshift: "{{ IS_OPENSHIFT }}"
Expand All @@ -73,7 +73,7 @@
kubernetes/authentication-container-name: secretless
openshift: "{{ IS_OPENSHIFT }}"
- !host
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment/oc-test-app-secretless
id: {{ TEST_APP_NAMESPACE_NAME }}/deployment_config/oc-test-app-secretless
annotations:
kubernetes/authentication-container-name: secretless
openshift: "{{ IS_OPENSHIFT }}"
Expand Down

0 comments on commit d3e408a

Please sign in to comment.