Skip to content

Commit b4bd746

Browse files
committedAug 29, 2019
remove all trailing whitespace
1 parent 8155621 commit b4bd746

File tree

21 files changed

+61
-61
lines changed

21 files changed

+61
-61
lines changed
 

‎001-Lab-Setup/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ Note: You may need to refresh the page a few times before seeing your Kubernetes
2222
In the navigation on the left side of the console, click `Kubernetes Engine`. Here you will find the details about the cluster and a GUI for accessing and administering workloads and services.
2323

2424
## Task 3: Launch Cloud Shell
25-
There is a button titled `Activate Google Cloud Shell` located in the top-bar navigation of the console. When clicked, a terminal will appear in the lower half of the console. This gives you direct command-line access to your Kubernetes cluster.
25+
There is a button titled `Activate Google Cloud Shell` located in the top-bar navigation of the console. When clicked, a terminal will appear in the lower half of the console. This gives you direct command-line access to your Kubernetes cluster.
2626

2727
Cloud shell comes packaged with a beta feature called `code editor` which gives you a minimal IDE for viewing and editing files. This will be used throughout the remainder of the labs. The link is found in the upper-right hand corner of the terminal.
2828

2929
## Task 4: Clone the Git Repository
3030
In your home directory, we are going to pull in the documentation and source code used for the course labs. We can do this by running the following command:
3131
```
32-
git clone https://github.com/ManicodeSecurity/Defending-DevOps/
32+
git clone https://github.com/ManicodeSecurity/Defending-DevOps/
3333
```
3434

3535
## Task 5: Connect to your Kubernetes Cluster
36-
Most of the tools necessary to complete the labs come pre-installed in Google Cloud Shell including `kubectl` which is used extensively to interact with your cluster. Ensure your cluster is operational by running the following commands.
36+
Most of the tools necessary to complete the labs come pre-installed in Google Cloud Shell including `kubectl` which is used extensively to interact with your cluster. Ensure your cluster is operational by running the following commands.
3737

3838
First, we need to use connect to the cluster using Cloud Shell. In the navigation on the left, click `Kubernetes Engine -> Cluster` then click the `Connect` button next to your cluster:
3939

4040
![Cluster Connect](../images/gke-connect.png)
4141

42-
You will then be presented with options to connect to the cluster. Click `Run in Cloud Shell`. This will open Google Cloud Shell in the same browser tab. It will also paste a command into the terminal. All you need to do now is hit enter to run the command.
42+
You will then be presented with options to connect to the cluster. Click `Run in Cloud Shell`. This will open Google Cloud Shell in the same browser tab. It will also paste a command into the terminal. All you need to do now is hit enter to run the command.
4343

4444
The command you are running will look like this:
4545
```

‎002-Containerizing-An-Application/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The source code for the application located in the `src/link-unshorten` director
88
### Task 1: Browse the Application
99
Open up the files in `src/link-unshorten` in your favorite IDE or the Cloud Shell editor and familiarize yourself with the application.
1010

11-
### Task 2: Build the Docker Image
11+
### Task 2: Build the Docker Image
1212
In the `src/link-unshorten` directory run the following command (substituting <yourname> with your own identifier) to build the image on the Cloud Shell VM:
1313
```
1414
docker build -t <yourname>/link-unshorten:0.1 .
@@ -92,7 +92,7 @@ Hint 3: Yes, the answer is commented in the source code
9292
Hint 4: You will need to run `docker stop` on the first running container before running another one with the same port
9393

9494
### Bonus 3: Inspect the Docker image
95-
[dive](https://github.com/wagoodman/dive) is an OSS project that helps with visualization and optimization of images.
95+
[dive](https://github.com/wagoodman/dive) is an OSS project that helps with visualization and optimization of images.
9696

9797
Install `dive` in Cloud Shell and inspect the unshorten image that was created.
9898

‎003-Cluster-Setup/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ echo "Default Namespace Switched:" $(kubectl get sa default -o jsonpath='{.metad
1616
1. `kubectl` is the command line utility that we will use to interact with our Kubernetes cluster. The first task is to view the Pods that are running on our cluster with an out-of-the-box installation. Run the following command in you terminal:
1717
```
1818
kubectl get pods
19-
```
19+
```
2020

2121
2. As you can see no pods are running. This is because we are dropped into the `default` namespace and the `default` namespace has nothing deployed to it. Try running the same command with the following argument. This will list the pods used by the Kubernetes system itself:
2222
```
@@ -86,7 +86,7 @@ exit
8686
### Task 3: Exposing your Pod to the World
8787
There are a variety of ways to make our Pod accessible to the outside world. A Service with the type `LoadBalancer` will be used to give our Pod a stable existence and an IP we can reach from our web browser.
8888

89-
The `LoadBalancer` type spins up a load balancer in GCP automatically.
89+
The `LoadBalancer` type spins up a load balancer in GCP automatically.
9090

9191
1. To expose the application we create a Service with the type of LoadBalancer:
9292
```
@@ -106,7 +106,7 @@ http://<EXTERNAL-IP>:8080/api/check?url=bit.ly/test
106106
4. This is no way to manage a real Kubernetes cluster. Tear down your app using the following commands:
107107
```
108108
kubectl delete pod link-unshorten && kubectl delete svc link-unshorten
109-
```
109+
```
110110

111111
### Task 4: "Codifying" Your Deployment
112112
Running ad hoc commands in a terminal are no way to maintain a proper DevOps infrastructure. Kubernetes is built with "Infrastructure as Code" in mind by using manifests. Manifests can be written in JSON and YAML. We will be using YAML for all labs.
@@ -124,7 +124,7 @@ kubectl create -f link-unshorten-service.yaml
124124
kubectl get pods
125125
```
126126

127-
4. Under the hood we can see the new ReplicaSet that was created. Remember, a Deployment actually creates a ReplicaSet. Deployments provide the same replication functions via ReplicaSets and also the ability to rollout changes and roll them back if necessary.
127+
4. Under the hood we can see the new ReplicaSet that was created. Remember, a Deployment actually creates a ReplicaSet. Deployments provide the same replication functions via ReplicaSets and also the ability to rollout changes and roll them back if necessary.
128128
```
129129
kubectl get replicaset
130130
```
@@ -137,14 +137,14 @@ kubectl describe svc link-unshorten-service
137137
6. Similar to how we interacted with our application earlier, we use the IP from the above output and paste it into our browser.
138138
```
139139
http://<EXTERNAL-IP>/api/check?url=bit.ly/test
140-
```
140+
```
141141

142142
### Task 5: Scale
143143

144144
1. We will first increase the number of pods in our Deployment using `kubectl scale`. Note - This will not reflect what is defined in the manifest. These values will be out of sync.
145145

146146
```
147-
kubectl scale deployment/link-unshorten --replicas=4
147+
kubectl scale deployment/link-unshorten --replicas=4
148148
kubectl get pods
149149
# 4 pods should be running
150150
```
@@ -169,7 +169,7 @@ kubectl delete hpa <HPA_NAME>
169169
5. Relaunch our Deployment from the manifest file:
170170
```
171171
kubectl create -f link-unshorten-deployment.yaml
172-
kubectl get pods
172+
kubectl get pods
173173
# two pods should be running
174174
```
175175

@@ -181,7 +181,7 @@ kubectl replace -f link-unshorten-deployment.yaml
181181

182182
7. Inspect the Pods scaling. Note that others will be terminating at the same time:
183183
```
184-
kubectl get pods
184+
kubectl get pods
185185
```
186186

187187
### Multi-Container Pods
@@ -207,7 +207,7 @@ exit
207207
```
208208

209209
### Bonus
210-
A critical RCE vulnerability was just reported through a bug bounty and was fixed late into the night. Roll out a new version of the app (0.2) in your cluster to patch the vulnerability on each of your three running pods. No downtime allowed! Show the deployment history using `kubectl rollout history`
210+
A critical RCE vulnerability was just reported through a bug bounty and was fixed late into the night. Roll out a new version of the app (0.2) in your cluster to patch the vulnerability on each of your three running pods. No downtime allowed! Show the deployment history using `kubectl rollout history`
211211

212212
### Bonus 2
213213
The new version you just rolled out contains a critical bug! Quickly rollback the deployment to 0.1 (Yes, 0.1 is the vulnerable version, but this is just for practice!)
@@ -221,6 +221,6 @@ echo "Default Namespace Switched:" $(kubectl get sa default -o jsonpath='{.metad
221221
```
222222

223223
### Discussion Questions
224-
1. What would be a good piece of your application or infrastructure to start breaking up into Pods within Kubernetes?
224+
1. What would be a good piece of your application or infrastructure to start breaking up into Pods within Kubernetes?
225225

226-
2. What security challenges does administering a Kubernetes cluster using a tool like kubectl present?
226+
2. What security challenges does administering a Kubernetes cluster using a tool like kubectl present?

‎003-Cluster-Setup/manifests/link-unshorten-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Deployment
33
metadata:
44
# A Deployment named link-unshorten is created using the metadata: name field
55
name: link-unshorten
6-
# We give the deployment a label
6+
# We give the deployment a label
77
labels:
88
app: unshorten-api
99
spec:
@@ -13,7 +13,7 @@ spec:
1313
selector:
1414
matchLabels:
1515
app: unshorten-api
16-
template:
16+
template:
1717
metadata:
1818
labels:
1919
# We label all Pods in this deployment as app: unshorten-api

‎004-Cluster-Authentication/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Kubernetes Engine Admin
1313
Editor
1414
1515
User 2: <your-intern-email>@manicode.us
16-
Roles:
16+
Roles:
1717
Minimal GKE Role
1818
Browser
1919
```
@@ -26,11 +26,11 @@ container.clusters.getCredentials
2626
```
2727

2828
### Task 1: Launch Your Infrastructure
29-
First, we will spin up our application in both a `development` and `production` namespace.
29+
First, we will spin up our application in both a `development` and `production` namespace.
3030

3131
Note: You should be logged in to Cloud Shell using the admin account provided at the beginning of class to run the following commands, NOT `<your-intern-email>@manicode.us`.
3232

33-
We need to retrieve the credentials of our running cluster using the following `gcloud` command. This command updates our kubeconfig in Cloud Shell file with appropriate credentials and endpoint information to point kubectl at a specific cluster in Google Kubernetes Engine.
33+
We need to retrieve the credentials of our running cluster using the following `gcloud` command. This command updates our kubeconfig in Cloud Shell file with appropriate credentials and endpoint information to point kubectl at a specific cluster in Google Kubernetes Engine.
3434

3535
```
3636
# Use gcloud get-credentials to retrieve the cert
@@ -65,11 +65,11 @@ kubectl get pods --all-namespaces
6565
Take note of this process. Our user has full administrative access to our cluster due to being provisioned with the `Kubernetes Engine Admin` role. We will now see how RBAC helps give us granular access control at the object-level within our cluster.
6666

6767
### Task 2: Authenticate as a Restricted User
68-
We will now log in using a separate user who has very locked down access to the entire project. In an incognito window browse to `cloud.google.com` and authenticate with the user `<your-intern-email>@manicode.us` and the same password that was provided to you for the admin user.
68+
We will now log in using a separate user who has very locked down access to the entire project. In an incognito window browse to `cloud.google.com` and authenticate with the user `<your-intern-email>@manicode.us` and the same password that was provided to you for the admin user.
6969

70-
Note: *Using the same password for multiple accounts is bad. Don't do this at home.*
70+
Note: *Using the same password for multiple accounts is bad. Don't do this at home.*
7171

72-
Now open up Cloud Shell and use the following `gcloud get-credentials` command to retrieve the credentials for your user so we can start interacting with the cluster. This is the same cluster you just launched the `production` and `development` infrastructure in.
72+
Now open up Cloud Shell and use the following `gcloud get-credentials` command to retrieve the credentials for your user so we can start interacting with the cluster. This is the same cluster you just launched the `production` and `development` infrastructure in.
7373

7474
```
7575
# Authenticate to the cluster
@@ -80,7 +80,7 @@ Now, attempt to run some `kubectl` queries on the cluster.
8080
```
8181
kubectl get pods --namespace=production
8282
kubectl get pods --namespace=development
83-
kubectl get secrets
83+
kubectl get secrets
8484
kubectl run link-unshorten --image=jmbmxer/link-unshorten:0.1 --port=8080
8585
```
8686
These should all fail with a `Forbidden` error. While <your-intern-email>@manicode.us does technically have an account on the cluster, RBAC is stopping it from accessing any of the objects.
@@ -93,7 +93,7 @@ kubectl auth can-i list secrets --namespace default
9393
```
9494

9595
### Task 3: Add Yourself as `cluster-admin`
96-
By default, User 1 will not be able to create the `roles` or `rolebindings` needed to begin building our RBAC policies. We need to ensure User 1 (our Administrator) has the appropriate access to the cluster by granting the user `cluster-admin` rights.
96+
By default, User 1 will not be able to create the `roles` or `rolebindings` needed to begin building our RBAC policies. We need to ensure User 1 (our Administrator) has the appropriate access to the cluster by granting the user `cluster-admin` rights.
9797

9898
`cluster-admin` is one of several Default User-facing roles included with every Kubernetes installation. They should be used with caution as many of these roles grant excessive privileges and are often abused for a quick fix.
9999

@@ -124,10 +124,10 @@ kubectl auth can-i create roles --as=root --as-group=system:authenticated --as-g
124124
yes
125125
```
126126

127-
### Task 4: Create RBAC Rules
127+
### Task 4: Create RBAC Rules
128128
Our user `<your-intern-email>@manicode.us` is a restricted user so we only want to grant access to read pods in the `development` namespace and nothing more. We will use RBAC to enforce a policy
129129

130-
Now, open the file `user-role-binding.yaml` in the `manifests/role` directory and replace <your-intern-email> with the one provided to you. It will be the same as your admin account but with the word `intern` at the end (eg. `manicode0003intern@manicode.us`).
130+
Now, open the file `user-role-binding.yaml` in the `manifests/role` directory and replace <your-intern-email> with the one provided to you. It will be the same as your admin account but with the word `intern` at the end (eg. `manicode0003intern@manicode.us`).
131131
```
132132
# In the manifests/role directory
133133
kubectl create -f .

‎004-Cluster-Authentication/manifests/development/link-unshorten-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
# A Deployment named link-unshorten is created using the metadata: name field
55
name: link-unshorten
66
namespace: development
7-
# We give the deployment a label
7+
# We give the deployment a label
88
labels:
99
app: unshorten-api
1010
spec:
@@ -14,7 +14,7 @@ spec:
1414
selector:
1515
matchLabels:
1616
app: unshorten-api
17-
template:
17+
template:
1818
metadata:
1919
labels:
2020
# We label all Pods in this deployment as app: unshorten-api

‎004-Cluster-Authentication/manifests/production/link-unshorten-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
# A Deployment named link-unshorten is created using the metadata: name field
55
name: link-unshorten
66
namespace: production
7-
# We give the deployment a label
7+
# We give the deployment a label
88
labels:
99
app: unshorten-api
1010
spec:
@@ -14,7 +14,7 @@ spec:
1414
selector:
1515
matchLabels:
1616
app: unshorten-api
17-
template:
17+
template:
1818
metadata:
1919
labels:
2020
# We label all Pods in this deployment as app: unshorten-api

‎007-Network-Policies/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ echo "Default Namespace Switched:" $(kubectl get sa default -o jsonpath='{.metad
1414
```
1515

1616
### Task 2: Create our Network Policy
17-
Go to the `manifests/network-policies` directory and inspect the Network policy named `hello-unshorten.yaml`. This policy simply selects Pods with label `app=unshorten-api` and specifies an ingress policy to allow traffic only from Pods with the label `app=unshorten-fe`. We only want to allow traffic from pods that are acting as frontends to our API.
17+
Go to the `manifests/network-policies` directory and inspect the Network policy named `hello-unshorten.yaml`. This policy simply selects Pods with label `app=unshorten-api` and specifies an ingress policy to allow traffic only from Pods with the label `app=unshorten-fe`. We only want to allow traffic from pods that are acting as frontends to our API.
1818

1919
In the `manifests/network-policies` directory run:
2020
```

‎007-Network-Policies/manifests/api/link-unshorten-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
selector:
1010
matchLabels:
1111
app: unshorten-api
12-
template:
12+
template:
1313
metadata:
1414
labels:
1515
app: unshorten-api

‎008-Istio/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gcloud beta container clusters update $(gcloud container clusters list --format
2424

2525
(!)Ensure all cluster operations are labeled `DONE` before continuing(!)
2626
```
27-
gcloud beta container operations list
27+
gcloud beta container operations list
2828
```
2929

3030
### Task 2: Verify our Istio Installation
@@ -80,7 +80,7 @@ Lets build some rules to explicit allow outbound egress traffic to only bit.ly a
8080
kubectl create -f .
8181
```
8282

83-
Once the rules are created, try to visit the API again and you should be able to successfully unshorten links to `bit.ly` domains only.
83+
Once the rules are created, try to visit the API again and you should be able to successfully unshorten links to `bit.ly` domains only.
8484

8585
```
8686
http://35.197.37.188/api/check?url=https://bit.ly/hi

‎008-Istio/manifests/api/link-unshorten-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Deployment
33
metadata:
44
# A Deployment named link-unshorten is created using the metadata: name field
55
name: link-unshorten
6-
# We give the deployment a label
6+
# We give the deployment a label
77
labels:
88
app: unshorten-api
99
spec:
@@ -13,7 +13,7 @@ spec:
1313
selector:
1414
matchLabels:
1515
app: unshorten-api
16-
template:
16+
template:
1717
metadata:
1818
labels:
1919
# We label all Pods in this deployment as app: unshorten-api

‎009-Secrets/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ curl \
148148
http://127.0.0.1:8200/v1/secret/mysql
149149
```
150150

151-
### Task 4: Using Vault to Store and inject our MySQL Password
151+
### Task 4: Using Vault to Store and inject our MySQL Password
152152

153153
We can now call the Vault API to inject our secret into our `kubectl create` command on the fly as follows.
154154

155155
First, delete `mysql-secrets` from our cluster:
156156
```
157-
kubectl delete secret mysql-secrets
157+
kubectl delete secret mysql-secrets
158158
```
159159

160160
navigate to `manifests/secrets` and run:

‎009-Secrets/manifests/api/link-unshorten-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
selector:
1010
matchLabels:
1111
app: unshorten-api
12-
template:
12+
template:
1313
metadata:
1414
labels:
1515
app: unshorten-api

‎009-Secrets/manifests/vault/vault-statefulset.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: apps/v1beta1
2-
# StatefulSets are intended to be used with stateful applications and distributed systems.
2+
# StatefulSets are intended to be used with stateful applications and distributed systems.
33
kind: StatefulSet
44
metadata:
55
name: vault

‎010-Security-Pipeline/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Security Pipeline and Automation
2-
This lab will spin up Jenkins in our cluster along with a private Docker image repository. Jenkins will also handle zero-downtime deploys of the unshorten API upon a successful build. The humble beginnings of a self-contained DevSecOps pipeline.
2+
This lab will spin up Jenkins in our cluster along with a private Docker image repository. Jenkins will also handle zero-downtime deploys of the unshorten API upon a successful build. The humble beginnings of a self-contained DevSecOps pipeline.
33

44
### Create the `lab010` Namespace and Use as Default
55

@@ -39,7 +39,7 @@ We need a location to store our versioned Docker images within our Kubernetes cl
3939
kubectl create -f .
4040
```
4141

42-
2. Once all of the Pods and Services are up and healthy, grab the URL for our freshly created registry and visit it in your browser.
42+
2. Once all of the Pods and Services are up and healthy, grab the URL for our freshly created registry and visit it in your browser.
4343

4444
Note: The registry runs on port `8080`.
4545
```
@@ -83,7 +83,7 @@ kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
8383
https://github.com/ManicodeSecurity/unshorten-jenkins-demo
8484
```
8585

86-
5. Inspect the `Jenkinsfile` in the repo. It has the humble beginnings of an AppSec and DevSecOps pipeline. Each stage is meant to apply automation to the process where issues result in failed builds.
86+
5. Inspect the `Jenkinsfile` in the repo. It has the humble beginnings of an AppSec and DevSecOps pipeline. Each stage is meant to apply automation to the process where issues result in failed builds.
8787

8888
### Task 4: Trigger a Build
8989
Most pipeline setups will trigger builds on a git commit or through some other automated manner. To simulate this, we will tell Jenkins to trigger a build manually:

0 commit comments

Comments
 (0)
Please sign in to comment.