Day 9: Open Services Without Authentication
Goal: You read a cache without a password – from inside and from outside – and lock it down three ways. · Duration: approx. 70 min · Prerequisite: Day 8
Briefing
“It’s only internal” is not security. A database or cache service
without a password is open to every Pod in the cluster – and if it is
published as a NodePort or LoadBalancer, it is
also open to everyone on the network in front of it. Today you deploy a
Redis without auth as a NodePort (one of the most common
misconfigurations of all), grab its data, and lock it down with three
measures: a password, no NodePort, Default Deny.
Drill 1: The misconfiguration – cache without a password, open to the outside
kubectl create namespace exposed
kubectl -n exposed create deployment cache --image=redis:7-alpine
kubectl -n exposed rollout status deploy/cache --timeout=120s
kubectl -n exposed expose deployment cache --type=NodePort --port=6379
kubectl -n exposed get svc cacheExpected (NodePort number varies):
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cache NodePort 10.43.50.41 <none> 6379:31196/TCP 3s
Save your progress? Sign up for free
Drill 2: Exploit – from inside
The attacker Pod has no redis-cli, but the Redis
protocol is text over TCP – bash and /dev/tcp
are enough:
kubectl -n attacker exec shell -- bash -c '
exec 3<>/dev/tcp/cache.exposed.svc/6379
printf "PING\r\nSET loot pwned\r\nGET loot\r\n" >&3
timeout 2 cat <&3'Expected:
+PONG
+OK
$5
pwned
You have read and written – without any login at all. Every Pod in the cluster can tamper with this data.
Save your progress? Sign up for free
Drill 3: Exploit – from outside
The NodePort makes the cache reachable on a port of
every node, even from the network in front of the cluster. From the host
(with the NodePort number from Drill 1):
NP=31196
exec 3<>/dev/tcp/127.0.0.1/$NP
printf "PING\r\nGET loot\r\n" >&3
timeout 2 cat <&3Expected:
+PONG
$5
pwned
You now read the data written inside the cluster in Drill 2
from outside. A NodePort without auth is a
wide-open barn door.
Save your progress? Sign up for free
Drill 4: Fix – password, ClusterIP, Default Deny
First, enforce a password:
kubectl -n exposed patch deploy cache --type=json \
-p='[{"op":"add","path":"/spec/template/spec/containers/0/args",
"value":["--requirepass","lab-redis-pw"]}]'
kubectl -n exposed rollout status deploy/cache --timeout=90sThen take back the publication – internally, ClusterIP
is enough:
kubectl -n exposed patch svc cache -p '{"spec":{"type":"ClusterIP"}}'And as defense in depth, Default Deny (like Day 8):
kubectl -n exposed apply -f - <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: {name: default-deny-ingress, namespace: exposed}
spec: {podSelector: {}, policyTypes: ["Ingress"]}
EOFSave your progress? Sign up for free
Drill 5: Proof
Without a password, Redis now refuses (network briefly left open for testing):
kubectl -n attacker exec shell -- bash -c '
exec 3<>/dev/tcp/cache.exposed.svc/6379
printf "GET loot\r\n" >&3
timeout 2 cat <&3'Expected:
-NOAUTH Authentication required.
The old NodePort is no longer reachable from the
host:
(exec 3<>/dev/tcp/127.0.0.1/31196) || echo "Port geschlossen"Expected:
bash: connect: Connection refused
Port geschlossen
And with Default Deny, the attacker never even reaches the port:
kubectl -n attacker exec shell -- nc -zv -w4 cache.exposed.svc 6379; echo "rc=$?"Expected:
command terminated with exit code 1
Clean up:
kubectl delete namespace exposedSave your progress? Sign up for free
Checkpoint
Each of the three layers works. You find services exposed as
NodePort cluster-wide like this:
kubectl get svc -A --field-selector spec.type=NodePortExpected: ideally none – every hit needs to be checked (does it really need a NodePort, and is the service behind it authenticated?).
Challenge
NodePorts often appear unnoticed because an expose or a
Helm value sets them. Write a one-liner that lists all
NodePort and LoadBalancer Services in the
cluster with namespace and port – your ongoing inventory.
Hint: kubectl get svc -A -o json plus a
filter on .spec.type.
Solution
kubectl get svc -A -o json | python3 -c '
import sys,json
for s in json.load(sys.stdin)["items"]:
t=s["spec"].get("type")
if t in ("NodePort","LoadBalancer"):
ports=[p.get("nodePort") or p.get("port") for p in s["spec"]["ports"]]
print(t, s["metadata"]["namespace"]+"/"+s["metadata"]["name"], ports)'Expected: In a fresh RKE2, only the intended ones (e.g. the Ingress controller). Everything else is a finding.
Save your progress? Sign up for free
Enterprise Note
- Internal services as
ClusterIP; external access only via an Ingress/Gateway with authentication and TLS, not viaNodePort. - Every data service (DB, cache, message broker) needs authentication – even “internal only” ones. Forbid default passwords and “no password” via admission (Day 12).
- Default Deny as the third layer: even an unauthenticated service is then only reachable by the explicitly allowed sources.
- Never publish admin UIs (Kubernetes Dashboard, database UIs) without auth or via NodePort; use a dedicated, tightly bound token for the Kubernetes Dashboard.