The Kubernetes networking environment by default is an open network without restrictions or limitations.
This means that any pod can access any other pod or service. This introduces potential risks.
Our arcadia-users
exposes an internal API /v1/user_i/
which is used by the arcadia-login
service only. This means that no other service should have access to it.
Lets see what security implications this has:
arcadia-stocks
pod. This pod is used only to get current crypto prices and nothing else. It should not be able to contact any other pod.export arcadia_stocks_pod=$(kubectl get pods --selector=app=arcadia-stocks | grep arcadia-stocks -m 1 | cut -d' ' -f1)
kubectl exec -it $arcadia_stocks_pod -- bash
Output
arcadia-stocks
container, the bellow command will access the arcadia-users
internal API and get specific user information.arcadia-login
pods.curl http://arcadia-users/v1/user_i/c29yaW5AbmdpbnguY29t
Output
exit
the container bash.
arcadia-login
podscat << EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: arcadia-users-sa
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: arcadia-login-sa
---
apiVersion: specs.smi-spec.io/v1alpha3
kind: HTTPRouteGroup
metadata:
name: route-group
spec:
matches:
- name: destination-traffic
methods:
- GET
---
apiVersion: access.smi-spec.io/v1alpha2
kind: TrafficTarget
metadata:
name: traffic-target
spec:
destination:
kind: ServiceAccount
name: arcadia-users-sa
rules:
- kind: HTTPRouteGroup
name: route-group
matches:
- destination-traffic
sources:
- kind: ServiceAccount
name: arcadia-login-sa
EOF
kubectl set serviceaccount deployments/arcadia-users arcadia-users-sa
kubectl set serviceaccount deployments/arcadia-login arcadia-login-sa
arcadia-stocks
pod and retry getting user information from the arcadia-users
service, this time it will be blocked.export arcadia_stocks_pod=$(kubectl get pods --selector=app=arcadia-stocks | grep arcadia-stocks -m 1 | cut -d' ' -f1)
kubectl exec -it $arcadia_stocks_pod -- bash
curl http://arcadia-users/v1/user_i/c29yaW5AbmdpbnguY29t
Output
exit
the container bash.
arcadia-login
pod and try getting user information from the arcadia-users
service, only this service should be allowed.export arcadia_login_pod=$(kubectl get pods --selector=app=arcadia-login | grep arcadia-login -m 1 | cut -d' ' -f1)
kubectl exec -it $arcadia_login_pod -- bash
curl http://arcadia-users/v1/user_i/c29yaW5AbmdpbnguY29t
Output
exit
the container bash.