This repo includes examples of how to create a Kubernetes cluster, deploy the Contrast Agent Operator and some known vulnerable applications. Typical deployment times:
- AKS - 5 mins
- EKS - 20 mins
This deployment will typically take ±5 minutes.
- Install Terraform from here: https://www.terraform.io/downloads.html.
- Install the Azure cli tools using
brew update && brew install azure-cli. - Install kubectl using
brew update && brew install kubectl.
-
Change directory to the AKS folder
-
If your Azure CLI is not authenticated then log into the Azure (
az login) to cache your credentials. -
Create a terraform.tfvars file to add your initials and preferred Azure location, for example:
location="UK South" initials="da" -
Run
terraform initto download the required plugins. -
Run
terraform applyto deploy a new cluster. -
Grab your AKS credentials for kubectl:
az aks get-credentials --resource-group $(terraform output resource_group_name | tr -d '"') --name $(terraform output kubernetes_cluster_name | tr -d '"') -
Deploy the operator and demo apps.
-
View the Kubernetes dashboard (optional):
az aks browse --resource-group $(terraform output resource_group_name | tr -d '"') --name $(terraform output kubernetes_cluster_name | tr -d '"') -
After your demo, run
terraform destroy --auto-approveto remove all resources.
- Install kubectl using
brew update && brew install kubectl. - Install the AWS CLI using
brew update && brew install awscli. - If your AWS CLI is not authenticated then run (
aws configure) to cache your credentials. - Install eksctl using
brew update && brew install eksctl.
- Create a K8S cluster using
eksctl create cluster --name sales-engineering-da --region us-east-2 - Grab your EKS credentials for kubectl:
aws eks update-kubeconfig --region us-east-2 --name sales-engineering-da - After your demo, run
eksctl delete cluster --name sales-engineering-da --region us-east-2to remove all resources.
-
Install the operator:
kubectl apply -f https://github.com/Contrast-Security-OSS/agent-operator/releases/latest/download/install-prod.yaml -
Configure the operator using one of the two options below:
- Rename the config-template.yaml to config.yaml and add your agent credentials on lines 9-11. This file includes agent injectors for all languages.
- Run
kubectl apply -f config.yaml
-
Configure the operator credentials:
kubectl -n contrast-agent-operator create secret generic default-agent-connection-secret --from-literal=apiKey=TODO --from-literal=serviceKey=TODO --from-literal=userName=TODO -
Create a ClusterAgentConnection:
kubectl apply -f - <<EOF apiVersion: agents.contrastsecurity.com/v1beta1 kind: ClusterAgentConnection metadata: name: default-agent-connection namespace: contrast-agent-operator spec: template: spec: url: https://eval.contrastsecurity.com/Contrast apiKey: secretName: default-agent-connection-secret secretKey: apiKey serviceKey: secretName: default-agent-connection-secret secretKey: serviceKey userName: secretName: default-agent-connection-secret secretKey: userName EOF -
Create an AgentInjector (this should be done per target language - example is for Java):
kubectl apply -f - <<EOF apiVersion: agents.contrastsecurity.com/v1beta1 kind: AgentInjector metadata: name: contrast-agent-injector namespace: default spec: type: java selector: labels: - name: contrast value: java EOF
-
Make sure you have the relevant agent injector created and deploy vulnerable applications from the apps folder, e.g.:
kubectl apply -f /apps/webgoat.yaml -
Visit your application in the browser via the external IP. Remember to add
/WebGoat(or equivalent):kubectl get services
-
Check the app has the correct Contrast annotations:
kubectl describe Deployment/webgoat -
Check if Contrast is mentioned in the application logs:
kubectl -n default logs Deployment/webgoat -
Show logging from the init container on the pod:
kubectl logs Deployment/webgoat -c contrast-init
-
Check the operator is running:
kubectl -n contrast-agent-operator get pods -
Check the operator logs:
kubectl logs -f deployment/contrast-agent-operator --namespace contrast-agent-operator -
If you don't have operator logs, check everything is configured:
kubectl get all,secrets,clusteragentconfiguration,clusteragentconnection --namespace contrast-agent-operator -
Elevate the operator logging:
kubectl -n contrast-agent-operator set env deployment/contrast-agent-operator CONTRAST_LOG_LEVEL=Trace