Cloud Security

Cloud Security

Cloud Native Security

Overview
  • Followed a layered approach that is based on defense in depth approach.
  • The 4C layers of Cloud Native Security
    • Cloud Datacenter
    • Cluster (Kubernetes)
    • Container
    • Code
  • The 4C model describes where a control lives. The current Kubernetes documentation and the CNCF Cloud Native Security Whitepaper also describe when a control applies across the workload lifecycle:
    • Develop: code review, dependency and secret scanning
    • Distribute: image scanning, SBOMs, image signing
    • Deploy: admission control, policy checks, least-privilege identity
    • Runtime: network policy, audit logs, runtime threat detection
CAREERCloud security failures cross technical layers

Cloud incidents rarely fit into only one category. A vulnerable application, network exposure, workload identity, and excessive storage permissions can combine into one attack path.

The U.S. Department of Justice’s Capital One case summary describes an intrusion through a misconfigured web application firewall that enabled unauthorized access to cloud-hosted data. Public analyses of the incident describe a server-side request forgery (SSRF) that reached the cloud instance metadata service at 169.254.169.254 and obtained temporary credentials for an over-privileged role. The case is a useful reminder to evaluate the complete path from an externally reachable workload to its identity and permitted resources.

In a Kubernetes security review, ask:

  • What can an attacker reach after compromising this container?
  • Can the Pod reach the node’s cloud metadata endpoint?
  • Does the Pod receive a service-account token it does not need?
  • Which API objects and external cloud resources can that identity access?
  • Do network and admission policies limit lateral movement?
  • Would audit logs reveal the access quickly enough to respond?

Security engineers are expected to connect preventive controls with detection, incident response, and evidence.

Cloud Data Center
  • Cloud Provider: Their hardware their policy
    • Shared responsibility: the provider secures the physical facility and hypervisor; the customer secures identities, network rules, data, and workloads.
  • In-house infrastructures
    • Physical security
    • Network access
    • Database access (etcd for Kubernetes)
  • Instance metadata services (169.254.169.254) hand out credentials to anything running on the machine, including containers. Modern clouds offer session-oriented metadata access (for example, AWS IMDSv2), and clusters should block Pod egress to the metadata address unless a workload needs it.
Cluster (Kubernetes)
  • Authentication
  • RBAC Authorization
  • Admission control (Pod Security Admission, policy engines)
  • Encryption (TLS in transit, Secrets at rest)
  • Network Policies
  • Audit logging
  • TLS for Kubernetes Ingress
Container
  • Vulnerability scanning / OS dependency security
  • Image provenance: SBOMs and signed images
  • Privilege control/disabling
  • Container runtime isolation
Code
  • Secure communication over TLS
  • Port range limitation
  • Security of external library dependency
  • Static code analysis
  • Dynamic code security (SQL injection, cross-site scripting, …)
  • No secrets in source code or container images

Cluster Security: Kubernetes

Authentication
  • Kubernetes has no User object. Identities come from the authenticator:
    • Normal users: client certificates, OIDC tokens from an identity provider, or an authenticating proxy (Rancher, for example).
    • Service accounts: the only identity stored inside Kubernetes. Pods receive short-lived, audience-bound ServiceAccount tokens.
  • A client certificate signed by the cluster’s client CA (Certificate Authority) is considered authenticated:
    • the certificate Common Name (CN=) becomes the username;
    • each Organization (O=) becomes a group.
  • Authentication only answers who the caller is. A newly authenticated user is allowed to do almost nothing until RBAC grants permissions.
Authentication hands-on

All commands run on node1 of your FABRIC RKE2 slice. The setup playbook copied /etc/rancher/rke2/rke2.yaml to /home/ubuntu/.kube/config and linked RKE2’s kubectl into /usr/local/bin.

INFOConfirm that the RKE2 cluster is up and ready
1
kubectl get nodes
INFOWho is the ubuntu user, according to Kubernetes?
1
2
kubectl auth whoami
kubectl config view --minify
  • The username is system:admin and the groups include system:masters.
  • system:masters is bound to cluster-admin and bypasses RBAC entirely. This kubeconfig is the cluster’s break-glass credential.
  • Notice that client-certificate-data and client-key-data show as DATA+OMITTED. Anyone who copies the raw file becomes system:admin. We will not hand this file to other users.
INFOCreate a new Linux user account
  • New user account is called student:
1
2
sudo useradd -s /bin/bash -m student
sudo su - student
  • Try running kubectl commands now:
1
2
kubectl get nodes
kubectl get svc
  • With no kubeconfig, kubectl falls back to localhost:8080 and fails. A Linux account means nothing to the Kubernetes API server.
  • If you instead see permission denied when running kubectl itself, replace the symlink with a copy of the binary (as ubuntu): sudo cp --remove-destination "$(readlink -f /usr/local/bin/kubectl)" /usr/local/bin/kubectl
  • Type exit to return to the ubuntu account.
INFOIssue a client certificate for student

As ubuntu, generate a private key and a certificate signing request. The subject sets the username (CN=student) and a group (O=csc478-students):

1
2
3
4
5
mkdir -p ~/student-cert && cd ~/student-cert
openssl genrsa -out student.key 2048
openssl req -new -key student.key \
  -subj "/CN=student/O=csc478-students" \
  -out student.csr

Submit the request to the cluster’s CA through the Kubernetes CertificateSigningRequest API. The certificate expires after 24 hours:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: student
spec:
  request: $(base64 -w0 < student.csr)
  signerName: kubernetes.io/kube-apiserver-client
  expirationSeconds: 86400
  usages:
    - client auth
EOF

kubectl get csr student
kubectl certificate approve student
kubectl get csr student

Download the signed certificate and the cluster CA certificate:

1
2
3
4
kubectl get csr student -o jsonpath='{.status.certificate}' | base64 -d > student.crt
kubectl config view --raw --minify \
  -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d > ca.crt
openssl x509 -in student.crt -noout -subject -issuer -enddate

Hand the files to student. The private key never left this machine and was never seen by the API server:

1
2
sudo install -o student -g student -m 0600 student.key /home/student/
sudo install -o student -g student -m 0644 student.crt ca.crt /home/student/
INFOBuild a kubeconfig for student
1
sudo su - student

Use kubectl config instead of hand-editing YAML:

1
2
3
4
5
6
7
8
9
kubectl config set-cluster rke2 \
  --server=https://127.0.0.1:6443 \
  --certificate-authority=ca.crt --embed-certs=true
kubectl config set-credentials student \
  --client-certificate=student.crt --client-key=student.key --embed-certs=true
kubectl config set-context student@rke2 \
  --cluster=rke2 --user=student --namespace=csc478-lab
kubectl config use-context student@rke2
cat ~/.kube/config
  • Try running kubectl commands now:
1
2
3
kubectl auth whoami
kubectl get nodes
kubectl get pods
  • kubectl auth whoami succeeds: the username is student and the groups are csc478-students and system:authenticated.
  • kubectl get nodes and kubectl get pods fail with Forbidden. The API server knows who student is (authenticated) but no binding says what student may do (not authorized). Compare this to the earlier connection refused error.
INFOAuthorize student in one namespace

Exit back to ubuntu, create the lab namespace, and bind the built-in edit ClusterRole to the group, limited to that namespace:

1
2
3
4
exit
kubectl create namespace csc478-lab
kubectl create rolebinding csc478-students-edit \
  --clusterrole=edit --group=csc478-students -n csc478-lab

Check as student:

1
2
3
4
5
6
7
sudo su - student
kubectl get pods
kubectl create deployment web --image=nginx
kubectl get deployments,pods
kubectl get pods -n kube-system
kubectl get nodes
kubectl auth can-i --list
  • Work inside csc478-lab succeeds.
  • kube-system and nodes remain Forbidden.
  • Binding a group rather than a user means future certificates with O=csc478-students receive the same access without new bindings.
INFOClean up

As ubuntu:

1
2
kubectl delete namespace csc478-lab
kubectl delete csr student
  • Deleting the CSR does not revoke the certificate. Kubernetes has no client-certificate revocation list; a leaked certificate stays valid until it expires. That is why expirationSeconds matters, and why production clusters prefer OIDC tokens for people.
CHALLENGE

Create a second identity, auditor, in the group csc478-auditors, bound to the built-in view ClusterRole in csc478-lab. Put both identities in the student account’s kubeconfig as two contexts, and switch between them with kubectl config use-context.

Use kubectl auth can-i to show evidence that:

  • auditor can list Pods but cannot read Secrets or create Deployments;
  • student can do all three;
  • neither identity can list Nodes.

A kubeconfig can also hold several clusters. On FABRIC this is not practical across slices: every slice uses 192.168.1.0/24, and each API server certificate only lists its own addresses in tls-san.

RBAC Authorization
  • Kubernetes uses the rbac.authorization.k8s.io API group to drive RBAC-based authorization decisions,
  • RKE2 starts the API server with the Node and RBAC authorizers:
1
kubectl describe pods kube-apiserver -n kube-system | grep -i authorization
  • RBAC API: Role, ClusterRole, RoleBinding, ClusterRoleBinding.
  • Role: sets permissions within a particular namespace
1
2
kubectl get role --all-namespaces
kubectl describe role system::leader-locking-kube-controller-manager -n kube-system
  • ClusterRole: set permission for non-namespaced resources, or a reusable set of namespaced permissions
1
2
kubectl get clusterrole
kubectl describe clusterrole cluster-admin
  • RoleBinding binding grants the permissions defined in a role to a user or set of users.
  • ClusterRoleBinding grants that access cluster-wide.
1
2
3
kubectl get rolebinding --all-namespaces
kubectl get clusterrolebinding
kubectl describe clusterrolebinding cluster-admin
  • What resources are available and what verbs are applicable?
1
kubectl api-resources --sort-by name -o wide
Encryption of Secrets at rest
  • Secrets are only base64-encoded in the API. Anyone with etcd access or an etcd backup can read them unless the API server encrypts them.
  • RKE2 enables Secrets encryption at rest by default. On node1:
1
sudo rke2 secrets-encrypt status
  • Encryption at rest does not protect against an identity that is allowed to get secrets through the API. That is still an RBAC question.
  • Many production teams keep secrets in an external manager (cloud KMS, HashiCorp Vault) and sync or mount them into Pods.
Network Policies
  • By default, every Pod can reach every other Pod and every address the node can reach.
  • A NetworkPolicy selects Pods and restricts their ingress or egress. RKE2’s default CNI, Canal, enforces policies through Calico.
  • Example: let Pods in a namespace reach anything except the cloud metadata endpoint, the Capital One attack path:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-metadata-egress
  namespace: csc478-lab
spec:
  podSelector: {}
  policyTypes:
    - Egress
  egress:
    - to:
        - ipBlock:
            cidr: 0.0.0.0/0
            except:
              - 169.254.169.254/32
  • A stricter baseline starts from default-deny and explicitly allows DNS and required services.
Kubernetes Ingress
  • Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.
  • Traffic routing is controlled by rules defined on the Ingress resource.
  • Ingress is managed by Ingress Controllers.
  • There are many different Ingress Controllers
    • RKE2 packages its own controller. Releases have shipped rke2-ingress-nginx by default, and RKE2 also supports Traefik (ingress-controller: traefik in /etc/rancher/rke2/config.yaml).
    • The upstream community ingress-nginx project was retired in March 2026. Treat the controller as a component with its own CVEs and support lifecycle.
  • Check which controller your cluster runs:
1
2
kubectl get pods -n kube-system | grep -i -E 'ingress|traefik'
kubectl get ingressclass
  • The Gateway API is the successor to Ingress. It separates infrastructure ownership (Gateway) from application routing (HTTPRoute), which maps well onto RBAC roles.
TLS for Kubernetes Ingress
  • TLS terminates at the Ingress controller. The certificate and key live in a kubernetes.io/tls Secret in the same namespace as the Ingress:
1
kubectl create secret tls web-tls --cert=web.crt --key=web.key -n csc478-lab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  namespace: csc478-lab
spec:
  tls:
    - hosts:
        - web.example.com
      secretName: web-tls
  rules:
    - host: web.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80
  • In production, cert-manager requests and renews certificates automatically (for example, from Let’s Encrypt).
  • Traffic from the controller to the backend Pod is plain HTTP unless the backend or a service mesh (mutual TLS) encrypts it.

Container Security

Pod Security Standards
  • Pod security will influence container security.
  • Three policies:
    • Privileged
    • Baseline
    • Restricted
  • Cumulative and range from highly permissive to highly restrictive
  • Enforced by the built-in Pod Security Admission controller through namespace labels (enforce, audit, warn).
  • RKE2 applies privileged cluster-wide by default. With profile: cis in the RKE2 config, the default becomes restricted with exemptions for system namespaces.
Privileged
  • Purposely open, entirely unrestricted
  • Enable system- and infrastructure-level workloads
    • Implied understanding that these workloads are run as privileged/trusted users.
  • Absence of restrictions and allow-by-default mechanism
Baseline
  • Streamline adoption for common containerized workloads
  • Prevent known privilege escalations
    • No privileged containers, host namespaces, or hostPath volumes
  • Linux capabilities a container may add under baseline (anything else is rejected):
    • AUDIT_WRITE
    • CHOWN
    • DAC_OVERRIDE
    • FOWNER
    • FSETID
    • KILL
    • MKNOD
    • NET_BIND_SERVICE
    • SETFCAP
    • SETGID
    • SETPCAP
    • SETUID
    • SYS_CHROOT
  • Linux full capability list
Restricted
  • Enforce Pod hardening best practices at the expense of compatibility
  • Target security-critical applications and lower-trust users
  • Example policy:
    • Disable privilege escalation
    • Containers must run as non-root
    • Drop ALL capabilities and only allow NET_BIND_SERVICE.
    • Seccomp profile must be RuntimeDefault or Localhost
    • Only a limited set of volume types (no hostPath)
Pod Security Admission hands-on
INFOEnforce restricted on a namespace
1
2
3
4
kubectl create namespace psa-demo
kubectl label namespace psa-demo \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/warn=restricted
INFOTry an ordinary nginx Pod
1
kubectl run plain-nginx --image=nginx -n psa-demo
  • The request is rejected with violates PodSecurity "restricted:latest", followed by every missing setting: allowPrivilegeEscalation, capabilities, runAsNonRoot, and seccompProfile.
  • The Pod was authenticated and authorized. Admission stopped it.
INFODeploy a compliant Pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
cat <<'EOF' | kubectl apply -n psa-demo -f -
apiVersion: v1
kind: Pod
metadata:
  name: hardened-nginx
spec:
  automountServiceAccountToken: false
  securityContext:
    runAsNonRoot: true
    runAsUser: 101
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: nginx
      image: nginxinc/nginx-unprivileged:stable
      ports:
        - containerPort: 8080
      securityContext:
        allowPrivilegeEscalation: false
        capabilities:
          drop: ["ALL"]
EOF

kubectl get pods -n psa-demo
kubectl exec -n psa-demo hardened-nginx -- id
  • The unprivileged nginx image listens on port 8080, so it does not need NET_BIND_SERVICE.
  • automountServiceAccountToken: false removes the API token from a workload that never talks to the Kubernetes API.
INFOClean up
1
kubectl delete namespace psa-demo
Supply chain security
  • Most container risk arrives through the image: base OS packages, language dependencies, and whoever built and pushed it.
  • Common controls:
    • Scanning: tools such as Trivy or Grype report known CVEs in images.
    • SBOM: a software bill of materials lists what is inside an image, so you can answer “are we affected?” when the next CVE lands.
    • Signing and provenance: Sigstore cosign signs images; SLSA describes how trustworthy the build process is.
    • Admission policy: Kyverno, OPA Gatekeeper, or the built-in ValidatingAdmissionPolicy can reject unsigned images, latest tags, or images from unapproved registries.
  • Pin images by digest (image: nginx@sha256:...) so the image you scanned is the image you run.
Runtime security
  • Prevention eventually fails, so clusters also need detection:
    • Kubernetes audit logs record who called which API, and when.
    • Runtime detectors such as Falco watch system calls for suspicious behavior: a shell spawned in a container, a read of /etc/shadow, an unexpected outbound connection.
  • Cloud-native application protection platforms (CNAPP) combine posture checks, image scanning, identity analysis, and runtime detection into one product.