🎓 LEVEL 38 DEBRIEF: Volume Permissions & fsGroup¶
Congratulations! You've mastered volume permissions - critical for secure container file access!
📊 What You Fixed¶
The Problem:
spec:
containers:
- securityContext:
runAsUser: 1000 # Runs as user 1000
# ❌ No fsGroup! Volume owned by root
The Solution:
spec:
securityContext: # ✅ Pod-level
fsGroup: 1000
containers:
- securityContext:
runAsUser: 1000
runAsGroup: 1000
🔍 Understanding Volume Permissions¶
The Permission Problem¶
Default Behavior: - Volume created with root ownership (0:0) - Container runs as non-root user (e.g., 1000) - User 1000 cannot write to root-owned directory
Without fsGroup:
With fsGroup: 1000:
Security Context Levels¶
Container-level (per-container):
containers:
- securityContext:
runAsUser: 1000 # Run as this user
runAsGroup: 1000 # Run as this group
readOnlyRootFilesystem: true
Pod-level (affects all containers + volumes):
spec:
securityContext:
fsGroup: 1000 # Change volume group ownership
runAsNonRoot: true # Enforce non-root
fsGroupChangePolicy: "OnRootMismatch"
💥 Common Mistakes¶
Mistake 1: fsGroup in Wrong Place¶
Fix:
Mistake 2: Mismatched User and Group¶
spec:
securityContext:
fsGroup: 2000
containers:
- securityContext:
runAsUser: 1000
runAsGroup: 1000 # ❌ Doesn't match fsGroup!
Mistake 3: Root User with fsGroup¶
spec:
securityContext:
fsGroup: 1000 # Ignored! Root has full access anyway
containers:
- securityContext:
runAsUser: 0 # Running as root
🛡️ Best Practices¶
-
Always set fsGroup for non-root containers:
-
Match fsGroup with runAsGroup:
-
Use fsGroupChangePolicy:
-
Document required permissions:
🎯 Key Takeaways¶
- fsGroup changes volume group ownership - Enables write access
- Set at pod level - Not container level
- Match with runAsGroup - For consistency
- Required for non-root containers - That need to write to volumes
- Check with ls -la - Verify permissions in pod
Well done! You understand volume permissions! 🎉