Skip to content

Commit ad819a9

Browse files
authored
Merge pull request #94 from cyberark/72-add-example-applications
Adds example for deploying applications on KinD cluster
2 parents 5608102 + 14e3e1a commit ad819a9

11 files changed

+762
-4
lines changed

conjur-oss/README.md

+39-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Conjur Open Source is part of the CyberArk Privileged Access Security Solution w
3131
* [Deploying Without LoadBalancer Support (e.g. for KinD, MiniKube, KataCoda)](#deploying-without-loadbalancer-support-eg-for-kind-minikube-katacoda)
3232
* [Debugging](#debugging)
3333
* [PostgreSQL Database Password Restrictions](#postgresql-database-password-restrictions)
34+
- [What's Next? Deploy an Example Application That Uses Conjur Secrets](#whats-next-deploy-an-example-application-that-uses-conjur-secrets)
3435
- [Deleting the Conjur Deployment](#deleting-the-conjur-deployment)
3536
* [Uninstalling the Chart via Helm Delete](#uninstalling-the-chart-via-helm-delete)
3637
* [Cleaning Up Kubernetes Secrets Not Managed by Helm](#cleaning-up-kubernetes-secrets-not-managed-by-helm)
@@ -200,7 +201,7 @@ container to create an account during startup. To retrieve the credentials
200201
for this account, perform the following commands:
201202

202203
```sh-session
203-
ACCOUNT_NAME=<conjur-account-name>
204+
CONJUR_ACCOUNT=<conjur-account-name>
204205
CONJUR_NAMESPACE=<conjur-namespace>
205206
HELM_RELEASE=<helm-release>
206207
POD_NAME=$(kubectl get pods --namespace "$CONJUR_NAMESPACE" \
@@ -209,7 +210,7 @@ POD_NAME=$(kubectl get pods --namespace "$CONJUR_NAMESPACE" \
209210
kubectl exec --namespace "$CONJUR_NAMESPACE" \
210211
"$POD_NAME" \
211212
--container=conjur-oss \
212-
-- conjurctl role retrieve-key "$ACCOUNT_NAME":user:admin | tail -1
213+
-- conjurctl role retrieve-key "$CONJUR_ACCOUNT":user:admin | tail -1
213214
```
214215

215216
> Note: If you have `logLevel` set to `debug`, the `tail -1` command will truncate the output.
@@ -219,14 +220,14 @@ If you set `account.create` to `false`, or did not provide a value, an admin acc
219220
need to be created. To create an account, use the following commands:
220221

221222
```sh-session
222-
ACCOUNT_NAME=<Name for Conjur account to be created>
223+
CONJUR_ACCOUNT=<Name for Conjur account to be created>
223224
POD_NAME=$(kubectl get pods --namespace "$CONJUR_NAMESPACE" \
224225
-l "app=conjur-oss,release=$HELM_RELEASE" \
225226
-o jsonpath="{.items[0].metadata.name}")
226227
kubectl exec --namespace $CONJUR_NAMESPACE \
227228
$POD_NAME \
228229
--container=conjur-oss \
229-
-- conjurctl account create $ACCOUNT_NAME | tail -1
230+
-- conjurctl account create $CONJUR_ACCOUNT | tail -1
230231
```
231232
The credentials for this account will be provided after the account has been created.
232233
Store these in a safe location.
@@ -452,6 +453,40 @@ The following restrictions apply to the PostgreSQL database password:
452453
["-", ".", "_", or "~"]
453454
- Password length must be less than or equal to 64 characters.
454455

456+
## What's Next? Deploy an Example Application That Uses Conjur Secrets
457+
458+
If you are new to Conjur, you may be interested in learning more about how
459+
Conjur security policy can be configured and an application can
460+
be deployed that uses Conjur OSS to safely manage secrets data.
461+
462+
This repository contains a set of scripts that can:
463+
464+
- Create a [Kubernetes-in-Docker](https://github.com/kubernetes-sigs/kind)
465+
(KinD) cluster on your local machine
466+
- Helm install a Conjur OSS cluster on that KinD cluster
467+
- Enable the
468+
[Conjur Kubernetes Authenticator](https://docs.conjur.org/Latest/en/Content/Operations/Services/k8s_auth.htm)
469+
(authn-k8s) (as a security admin)
470+
- Load Conjur security policies for some example applications
471+
(as a security admin)
472+
- Deploy instances of a simple "Pet Store" application each using
473+
one of the following Conjur authentication broker/clients:
474+
- [Secretless Broker](https://github.com/cyberark/secretless-broker) sidecar container
475+
- [Conjur Kubernetes Authenticator Client](https://github.com/cyberark/conjur-authn-k8s-client)
476+
sidecar container
477+
- [Conjur Kubernetes Authenticator Client](https://github.com/cyberark/conjur-authn-k8s-client)
478+
init container
479+
(as an application developer/deployer)
480+
481+
Please refer to the [README.md](../examples/kubernetes-in-docker/README.md)
482+
file in the `../examples/kubernetes-in-docker` directory for more details
483+
on how to run these demo scripts.
484+
485+
These scripts will also generate some application-specific Conjur policy
486+
YAML files and Kubernetes application manifests as concrete examples of
487+
how applications can be deployed that use Conjur Kubernetes authentication
488+
to safely retrieve secrets.
489+
455490
## Deleting the Conjur Deployment
456491

457492
Uninstalling or deleting a Conjur deployment involves two steps:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# KinD and Helm install options
2+
export CREATE_KIND_CLUSTER="${CREATE_KIND_CLUSTER:-true}"
3+
export KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}"
4+
export HELM_INSTALL_CONJUR="${HELM_INSTALL_CONJUR:-true}"
5+
export HELM_RELEASE="${HELM_RELEASE:-conjur-oss}"
6+
export CONJUR_NAMESPACE="${CONJUR_NAMESPACE:-conjur-oss}"
7+
export CONJUR_ACCOUNT="${CONJUR_ACCOUNT:-myConjurAccount}"
8+
export CONJUR_LOG_LEVEL="${CONJUR_LOG_LEVEL:-info}"
9+
10+
# Basic demo config
11+
export TEST_APP_DATABASE="${TEST_APP_DATABASE:-postgres}"
12+
export TEST_APP_NAMESPACE_NAME="${TEST_APP_NAMESPACE_NAME:-app-test}"
13+
14+
# Configuration for Conjur authn-k8s
15+
export ANNOTATION_BASED_AUTHN="${ANNOTATION_BASED_AUTHN:-true}"
16+
export AUTHENTICATOR_ID="${AUTHENTICATOR_ID:-my-authenticator-id}"
17+
18+
# Conjur OSS Helm chart specific setting for demo scripts
19+
export CONJUR_OSS_HELM_INSTALLED="${CONJUR_OSS_HELM_INSTALLED:-true}"
20+
21+
# KinD specific specific setting for demo scripts
22+
export TEST_APP_LOADBALANCER_SVCS="${TEST_APP_LOADBALANCER_SVCS:-false}"
23+
24+
# DockerHub account credentials are required since the demo scripts need to
25+
# build and push demo images to a registry so that the images can then be
26+
# pulled by KinD.
27+
#
28+
# These should be configured/customized in bootstrap.env
29+
check_env_var "DOCKER_REGISTRY_URL"
30+
check_env_var "DOCKER_REGISTRY_PATH"
31+
check_env_var "DOCKER_USERNAME"
32+
check_env_var "DOCKER_PASSWORD"
33+
check_env_var "DOCKER_EMAIL"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
. utils.sh
6+
7+
check_env_var "KIND_CLUSTER_NAME"
8+
min_kind_version="0.7.0"
9+
10+
# Confirm that 'kind' binary is installed.
11+
if ! command -v kind &> /dev/null; then
12+
echo "kind binary not found. See https://kind.sigs.k8s.io/docs/user/quick-start/"
13+
echo "for installation instructions."
14+
exit 1
15+
fi
16+
17+
# Check version of 'kind' binary.
18+
kind_version="$(kind version -q)"
19+
if ! meets_min_version $kind_version $min_kind_version; then
20+
echo "kind version $kind_version is invalid. Version must be $min_kind_version or newer"
21+
exit 1
22+
fi
23+
24+
# Check if KinD cluster has already been created
25+
if [ "$(kind get clusters | grep "^$KIND_CLUSTER_NAME$")" = "$KIND_CLUSTER_NAME" ]; then
26+
echo "KinD cluster '$KIND_CLUSTER_NAME' already exists. Skipping cluster creation."
27+
else
28+
kind create cluster --name "$KIND_CLUSTER_NAME"
29+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
. utils.sh
4+
5+
min_helm_version="3.1"
6+
7+
# Confirm that 'helm' binary is installed.
8+
if ! command -v helm &> /dev/null; then
9+
echo "helm binary not found. See https://helm.sh/docs/intro/install/"
10+
echo "for installation instructions."
11+
exit 1
12+
fi
13+
14+
# Check version of 'helm' binary.
15+
helm_version="$(helm version --template {{.Version}} | sed 's/^v//')"
16+
if ! meets_min_version $helm_version $min_helm_version; then
17+
echo "helm version $helm_version is invalid. Version must be $min_helm_version or newer"
18+
exit 1
19+
fi
20+
21+
# Create the namespace for the Conjur cluster if necessary
22+
if has_namespace "$CONJUR_NAMESPACE"; then
23+
echo "Namespace '$CONJUR_NAMESPACE' exists, not going to create it."
24+
else
25+
kubectl create ns "$CONJUR_NAMESPACE"
26+
fi
27+
28+
# Check if the Conjur cluster release has already been installed. If so, run
29+
# Helm upgrade. Otherwise, do a Helm install of the Conjur cluster.
30+
if [ "$(helm list -q -n $CONJUR_NAMESPACE | grep "^$HELM_RELEASE$")" = "$HELM_RELEASE" ]; then
31+
helm upgrade \
32+
-n "$CONJUR_NAMESPACE" \
33+
--set account.name="$CONJUR_ACCOUNT" \
34+
--set account.create="true" \
35+
--set authenticators="authn\,authn-k8s/$AUTHENTICATOR_ID" \
36+
--set logLevel="$CONJUR_LOG_LEVEL" \
37+
--reuse-values \
38+
--recreate-pods \
39+
"$HELM_RELEASE" \
40+
"../../conjur-oss"
41+
else
42+
# Helm install a Conjur cluster and create a Conjur account
43+
data_key="$(docker run --rm cyberark/conjur data-key generate)"
44+
echo "data_key: $data_key"
45+
helm install \
46+
-n "$CONJUR_NAMESPACE" \
47+
--set dataKey="$data_key" \
48+
--set account.name="$CONJUR_ACCOUNT" \
49+
--set account.create="true" \
50+
--set authenticators="authn\,authn-k8s/$AUTHENTICATOR_ID" \
51+
--set logLevel="$CONJUR_LOG_LEVEL" \
52+
"$HELM_RELEASE" \
53+
"../../conjur-oss"
54+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
. utils.sh
6+
7+
master_pod="$(get_master_pod_name)"
8+
echo "$(kubectl exec \
9+
-n "$CONJUR_NAMESPACE" \
10+
"$master_pod" \
11+
--container=conjur-oss \
12+
-- conjurctl role retrieve-key "$CONJUR_ACCOUNT":user:admin | tail -1)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
. utils.sh
6+
7+
# Ensure that $AUTHENTICATOR_ID is enabled for authn-k8s
8+
authenticators="$(kubectl get secret \
9+
-n $CONJUR_NAMESPACE \
10+
$HELM_RELEASE-conjur-authenticators \
11+
--template={{.data.key}} | base64 -d)"
12+
if grep -q "$authenticators" <<< "$AUTHENTICATOR_ID"; then
13+
echo "Enabling authenticator ID $AUTHENTICATOR_ID for authn-k8s"
14+
helm upgrade \
15+
-n "$CONJUR_NAMESPACE" \
16+
--reuse-values \
17+
--recreate-pods \
18+
--set authenticators="authn\,authn-k8s/$AUTHENTICATOR_ID" \
19+
--set logLevel="$CONJUR_LOG_LEVEL" \
20+
"$HELM_RELEASE" \
21+
../../conjur-oss
22+
23+
# Pause to let Helm begin to terminate existing pods as a result
24+
# of Helm upgrade
25+
sleep 5
26+
27+
# Wait for Conjur master pod to have both containers ready
28+
wait_for_conjur_ready
29+
30+
else
31+
echo "Authenticator ID $AUTHENTICATOR_ID is already enabled for authn-k8s"
32+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
. utils.sh
6+
7+
conjur_demo_scripts_path="temp/kubernetes-conjur-demo"
8+
9+
# Clone the conjurdemos/kubernetes-conjur-demo repo
10+
rm -rf "$conjur_demo_scripts_path"
11+
announce "Cloning Kubernetes Conjur Demo scripts to $conjur_demo_scripts_path"
12+
mkdir -p temp
13+
git clone https://github.com/conjurdemos/kubernetes-conjur-demo "$conjur_demo_scripts_path"
14+
15+
# Because the kubernetes-conjur-demo scripts use a different naming convention
16+
# for the Conjur namespace env variable, some translation is required.
17+
export CONJUR_NAMESPACE_NAME="$CONJUR_NAMESPACE"
18+
19+
announce "Running the Kubernetes Conjur Demo scripts"
20+
cd "$conjur_demo_scripts_path"
21+
./start

0 commit comments

Comments
 (0)