Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .infrastructure/security/rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
kind: ServiceAccount
apiVersion: v1
metadata:
name: secrets-reader
namespace: todoapp

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: secrets-reader-role
namespace: todoapp
rules:
- apiGroups: [""]
resources: ["pods", "secrets"]
verbs: ["list", "get"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: secret-reader-binding
namespace: todoapp
subjects:
- kind: ServiceAccount
name: secrets-reader
roleRef:
kind: Role
name: secrets-reader-role
apiGroup: rbac.authorization.k8s.io
34 changes: 34 additions & 0 deletions INSTRUCTION.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# RBAC for TodoApp

## 1. Create a Kubernetes cluster:
```bash
kubectl create cluster --config cluster.yml
```

## 2. Deploy the application and additional resources:
```bash
./bootstrap.sh
```

## 3. Wait for 1-2 minutes for all pods to initialize. Once ready, verify the pod statuses:
```bash
kubectl get pods -n todoapp
```

## 4. Connect to a pod:
```bash
kubectl exec <pod name> -it -n todoapp -- sh
```

## 5. Set Up and Execute the cURL Command:
```bash
SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount
APISERVER=https://kubernetes.default.svc
TOKEN=$(cat ${SERVICEACCOUNT}/token)
CACERT=${SERVICEACCOUNT}/ca.crt

curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api/v1/namespaces/todoapp/secrets
```

## 6. Verify the Output.
The response should include the details of the secrets in the todoapp namespace.
2 changes: 2 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ kubectl apply -f .infrastructure/app/nodeport.yml
kubectl apply -f .infrastructure/app/hpa.yml
kubectl apply -f .infrastructure/app/deployment.yml

kubectl apply -f .infrastructure/security/rbac.yml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script applies the RBAC configuration, which is crucial for setting up permissions. Ensure that the rbac.yml file is correctly configured to avoid permission issues.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the rbac.yml file in the .infrastructure/security/ directory contains the necessary ServiceAccount, Role, and RoleBinding configurations as previously mentioned. This is crucial for the security setup.


# Install Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script installs the Ingress Controller using a URL. Ensure that the URL is correct and accessible. If there are any network restrictions, this might fail.

# kubectl apply -f .infrastructure/ingress/ingress.yml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ingress configuration is commented out. If ingress is required for your application, make sure to uncomment this line and verify that the ingress.yml file is correctly set up.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ingress configuration is commented out. If your application requires Ingress, make sure to uncomment this line or apply the necessary Ingress configuration to ensure external access to your services.