RBAC

Task 8: RBAC, Access Control & Security in AWS EKS (Real-Time Scenarios)

Why is Security Critical in Kubernetes?

  • Prevent unauthorized access to Kubernetes API

  • Secure applications using RBAC, IAM, and Service Accounts

  • Protect data using Network Policies & Secrets Management

  • Detect threats using Audit Logs & Runtime Security


🔹 Step 1: Role-Based Access Control (RBAC) for Users

AWS EKS does not use Kubernetes RBAC for users directly. Instead, IAM users & roles are mapped to Kubernetes RBAC.

1️⃣ Verify the AWS IAM Authenticator

kubectl get configmap -n kube-system aws-auth -o yaml

This maps AWS IAM users/roles to Kubernetes users.


2️⃣ Grant a User Read-Only Access to EKS

1️⃣ Create an IAM Role & Attach Policies

trust-policy.json:

Attach ReadOnly Policy:

2️⃣ Map IAM Role to Kubernetes RBAC Edit aws-auth ConfigMap:

Add:

3️⃣ Apply RBAC in Kubernetes

User now has read-only access to pods & services.


🔹 Step 2: Secure Application Access using Service Accounts

1️⃣ Create a Service Account for an Application

2️⃣ Grant the Service Account Access to Secrets

✅ Now, only this application can access secrets.


🔹 Step 3: AWS IAM Roles for Service Accounts (IRSA)

To allow Kubernetes workloads to use AWS services securely without hardcoding credentials.

1️⃣ Create an IAM Role with an OIDC Trust Policy

trust-policy.json:

2️⃣ Attach S3 Access to the Role

3️⃣ Associate the Role with a Service Account

✅ Now, any Pod using this service account can access S3 securely.


🔹 Step 4: Network Security with Network Policies

Use NetworkPolicies to restrict traffic between namespaces & pods.

This blocks all traffic. To allow specific access:

✅ Now, only backend pods can talk to database pods.


🔹 Step 5: Kubernetes Secrets Encryption

Enable encryption at rest for secrets.

1️⃣ Generate Encryption Key

2️⃣ Edit Encryption Config

3️⃣ Enable Encryption

✅ Now, secrets are encrypted at rest.


🔹 Step 6: Enable Kubernetes Audit Logs

To track security events & API access.

1️⃣ Enable Audit Logging in EKS

2️⃣ Check Audit Logs in CloudWatch

✅ Now, all API calls are logged.


Common Security Issues & Fixes

Issue
Cause
Fix

Unauthorized error when using kubectl

RBAC role missing.

Assign correct role.

Pod has access to AWS resources it shouldn’t

IRSA misconfigured.

Check IAM role & Service Account.

NetworkPolicy blocks all traffic

Policy too strict.

Allow necessary ingress/egress.

Secrets stored in plain text

No encryption enabled.

Use encryption at rest.

Pods can talk to each other freely

No Network Policies.

Implement zero-trust networking.


Final Summary

IAM Users mapped to RBAC rolesApplications use Service Accounts securelyPods use AWS resources via IRSANetwork Policies restrict communicationSecrets are encrypted at restAudit Logs track security events


NEXT: Do you want to proceed with Container Runtime Security (Falco, Kyverno, etc.)? 🚀

Last updated