Skip to content

Commit d097d3e

Browse files
authored
Merge pull request #25 from commjoen/nspfun
small steps for the nsps
2 parents 6cedb4c + f7f3c7b commit d097d3e

File tree

25 files changed

+331
-120
lines changed

25 files changed

+331
-120
lines changed

aws/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ The terraform code is loosely based on [this EKS managed Node Group TF example](
4848
5. Do `terraform apply`. Note: the apply will take 10 to 20 minutes depending on the speed of the AWS backplane.
4949
6. When creation is done, do `aws eks update-kubeconfig --region eu-west-1 --name wrongsecrets-exercise-cluster --kubeconfig ~/.kube/wrongsecrets`
5050
7. Do `export KUBECONFIG=~/.kube/wrongsecrets`
51-
8. Run `cd .. && ./build-and-deploy-aws.sh` to install the helm chart for the wrongsecrets-ctf-party.
51+
8. Run `cd ..`
52+
9. Run `./build-an-deploy-aws.sh` to install the helm chart for the wrongsecrets-ctf-party.
5253

5354
Your EKS cluster should be visible in [EU-West-1](https://eu-west-1.console.aws.amazon.com/eks/home?region=eu-west-1#/clusters) by default. Want a different region? You can modify `terraform.tfvars` or input it directly using the `region` variable in plan/apply.
5455

aws/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ module "eks" {
7777

7878
enable_irsa = true
7979

80+
# apply when available: iam_role_permissions_boundary = "arn:aws:iam::${local.account_id}:policy/service-user-creation-permission-boundary"
8081
eks_managed_node_group_defaults = {
8182
disk_size = 50
8283
disk_type = "gp3"

build-an-deploy-aws.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ echo "Usage: ./build-and-deploy-aws.sh"
1010
version="$(uuidgen)"
1111
AWS_REGION="eu-west-1"
1212

13-
helm install -n kube-system csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --set enableSecretRotation=true --set rotationPollInterval=60s
13+
helm upgrade -n kube-system csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver --set enableSecretRotation=true --set rotationPollInterval=60s
1414
echo "Install ACSP"
1515
kubectl apply -f https://raw.githubusercontent.com/aws/secrets-store-csi-driver-provider-aws/main/deployment/aws-provider-installer.yaml
1616

17+
echo "preparing calico via Helm"
18+
helm repo add projectcalico https://docs.projectcalico.org/charts
19+
helm upgrade calico projectcalico/tigera-operator --version v3.21.4
20+
21+
1722
echo "Generate secrets manager challenge secret 2"
1823
aws secretsmanager put-secret-value --secret-id wrongsecret-2 --secret-string "$(openssl rand -base64 24)" --region $AWS_REGION --output json --no-cli-pager
1924

@@ -24,4 +29,4 @@ aws ssm put-parameter --name wrongsecretvalue --overwrite --type SecureString --
2429
wait
2530

2631
#TODO: REWRITE ABOVE, REWRITE THE HARDCODED DEPLOYMENT VALS INTO VALUES AND OVERRIDE THEM HERE!
27-
helm upgrade --install mj ./helm/wrongsecrets-ctf-party --set="imagePullPolicy=Always" --set="balancer.env.K8S_ENV=aws" --set="balancer.repository=jeroenwillemsen/wrongsecrets-balancer" --set="balancer.tag=0.69aws" --set="wrongsecretsCleanup.repository=jeroenwillemsen/wrongsecrets-ctf-cleaner" --set="wrongsecretsCleanup.tag=0.2"
32+
helm upgrade --install mj ./helm/wrongsecrets-ctf-party --set="imagePullPolicy=Always" --set="balancer.env.K8S_ENV=aws" --set="balancer.repository=jeroenwillemsen/wrongsecrets-balancer" --set="balancer.tag=0.76aws" --set="wrongsecretsCleanup.repository=jeroenwillemsen/wrongsecrets-ctf-cleaner" --set="wrongsecretsCleanup.tag=0.2"
File renamed without changes.
File renamed without changes.
File renamed without changes.

helm/wrongsecrets-ctf-party/templates/wrongsecrets-balancer/role.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ rules:
3838
- apiGroups: ['secrets-store.csi.x-k8s.io']
3939
resources: ['secretproviderclasses']
4040
verbs: ['create', 'get', 'list', 'delete']
41+
- apiGroups: ['networking.k8s.io']
42+
resources: ['networkpolicies']
43+
verbs: ['create', 'get', 'list', 'delete']

helm/wrongsecrets-ctf-party/values.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ balancer:
3535
# -- Set this to a fixed random alpa-numeric string (recommended length 24 chars). If not set this get randomly generated with every helm upgrade, each rotation invalidates all active cookies / sessions requirering users to login again.
3636
cookieParserSecret: null
3737
repository: jeroenwillemsen/wrongsecrets-balancer
38-
tag: 0.69aws
38+
tag: 0.76aws
3939
# -- Number of replicas of the wrongsecrets-balancer deployment
40-
replicas: 3
40+
replicas: 1
4141
service:
4242
# -- Kubernetes service type
4343
type: ClusterIP
@@ -54,8 +54,8 @@ balancer:
5454
memory: 256Mi
5555
cpu: 400m
5656
limits:
57-
memory: 512Mi
58-
cpu: 800m
57+
memory: 1024Mi
58+
cpu: 1000m
5959
# -- Optional Configure kubernetes scheduling affinity for the created JuiceShops (see: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity)
6060
affinity: { }
6161
# -- Optional Configure kubernetes toleration for the created JuiceShops (see: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/)
@@ -89,7 +89,7 @@ balancer:
8989

9090
wrongsecrets:
9191
# -- Specifies how many JuiceShop instances MultiJuicer should start at max. Set to -1 to remove the max Juice Shop instance cap
92-
maxInstances: 100
92+
maxInstances: 500
9393
# -- Juice Shop Image to use
9494
image: jeroenwillemsens/wrongsecrets
9595
tag: 1.5.3-no-vault
@@ -191,7 +191,7 @@ wrongsecrets:
191191
#the virtual desktop for the deploymebt
192192
virtualdesktop:
193193
# -- Specifies how many JuiceShop instances MultiJuicer should start at max. Set to -1 to remove the max Juice Shop instance cap
194-
maxInstances: 100
194+
maxInstances: 500
195195
# -- Juice Shop Image to use
196196
image: jeroenwillemsen/wrongsecrets-desktop
197197
tag: latest

readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ We currently only support minikube and AWS EKS (_**But the latter needs you to u
2424
For minikube, run:
2525

2626
```shell
27-
minikube start
27+
28+
minikube start --network-plugin=cni --cni=calico
2829
eval $(minikube docker-env)
29-
./build-an-deploy
30+
./build-an-deploy.sh
3031
kubectl port-forward service/wrongsecrets-balancer 3000:3000
32+
3133
```
3234

35+
For AWS EKS follow the instrucrtions in the `/eks` folder.
36+
3337
Then open a browser and go to [localhost:3000](http:localhost:3000) and have fun :D .
3438

3539

wrongsecrets-balancer/src/__mocks__/kubernetes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
createServiceForTeam: jest.fn(),
99
createDesktopServiceForTeam: jest.fn(),
1010
createServiceAccountForWebTop: jest.fn(),
11+
createNSPsforTeam: jest.fn(),
1112
createRoleForWebTop: jest.fn(),
1213
createRoleBindingForWebtop: jest.fn(),
1314
getJuiceShopInstanceForTeamname: jest.fn(() => ({

wrongsecrets-balancer/src/app.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const promClient = require('prom-client');
66
const basicAuth = require('basic-auth-connect');
77
const onFinished = require('on-finished');
88

9-
const { get } = require('./config');
9+
const { get, extractTeamName } = require('./config');
1010

1111
const app = express();
1212

@@ -61,10 +61,7 @@ app.get('/balancer/dynamics', (req, res) =>
6161
app.use(cookieParser(get('cookieParser.secret')));
6262
app.use('/balancer', express.json());
6363
app.use((req, res, next) => {
64-
const teamname =
65-
process.env['NODE_ENV'] === 'test'
66-
? req.cookies[get('cookieParser.cookieName')]
67-
: req.signedCookies[get('cookieParser.cookieName')];
64+
const teamname = extractTeamName(req);
6865

6966
req.teamname = teamname;
7067
if (teamname) {

wrongsecrets-balancer/src/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ const fetchConfigValue = (name, defaultValue) => {
1313

1414
const get = memoize(fetchConfigValue);
1515
module.exports.get = get;
16+
17+
const extractTeamName = (req) => {
18+
return process.env['NODE_ENV'] === 'test'
19+
? req.cookies[get('cookieParser.cookieName')]
20+
: req.signedCookies[get('cookieParser.cookieName')];
21+
};
22+
module.exports.extractTeamName = extractTeamName;

0 commit comments

Comments
 (0)