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 #32

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions .infrastructure/app/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
labels:
app: todoapp
spec:
serviceAccountName: secrets-reader
serviceAccountName: secret-lister
containers:
- name: todoapp
image: ikulyk404/todoapp:4.0.1
Expand Down Expand Up @@ -91,4 +91,4 @@ spec:
secretName: app-secret
- name: app-config-volume
configMap:
name: app-config
name: app-config
33 changes: 33 additions & 0 deletions .infrastructure/security/rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: secret-lister
namespace: todoapp

---

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

---

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

## 1. Create a kubernetes cluster using kind:

```bash
kind create cluster --config cluster.yml
```

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

## 3. Wait for 2 minutes for all pods to initialize. Once ready, verify pods status:
```bash
kubectl get pods -n todoapp
```
If this command does not show you information about your pods, try verifing cluster name using command:
```bash
kubectl config current-context
kubectl get pods -n todoapp --context <current context>
```
and replace 'kind-kind' with your context

## 4. Connect to a pod:
Replace <pod name> with your pod name
```bash
kubectl exec -n todoapp <pod name> -it -- 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
```

## 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

# Install Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# 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 resource application is commented out. If you intend to use Ingress for routing, consider uncommenting this line to apply the Ingress configuration.