{
  "id": "pod-security-context",
  "title": "Pod Security Context",
  "category": "Security",
  "difficulty": "Medium",
  "type": "task",
  "weight": 6,
  "description": "## Pod Security Context\n\nA security context defines privilege and access control settings for a pod or container.\n\n**Your task:**\n\nCreate a Pod named `secure-pod` using `busybox:1.36` (command: `sleep 3600`) with the following security settings:\n- `runAsUser: 1000`\n- `runAsNonRoot: true`\n- `allowPrivilegeEscalation: false`\n\n```bash\n# Verify after creation:\nkubectl get pod secure-pod -o jsonpath='{.spec.containers[0].securityContext}'\n```",
  "hints": [
    {
      "title": "securityContext structure",
      "body": "Security context can be set at Pod level (`spec.securityContext`) or container level (`spec.containers[].securityContext`). Container-level settings override pod-level.",
      "command": "cat <<EOF | kubectl apply -f -\napiVersion: v1\nkind: Pod\nmetadata:\n  name: secure-pod\nspec:\n  containers:\n  - name: app\n    image: busybox:1.36\n    command: [\"sleep\", \"3600\"]\n    securityContext:\n      runAsUser: 1000\n      runAsNonRoot: true\n      allowPrivilegeEscalation: false\nEOF"
    }
  ],
  "setup_commands": [],
  "validation": {
    "commands": [
      {
        "description": "Pod 'secure-pod' exists",
        "command": "kubectl get pod secure-pod -o jsonpath='{.metadata.name}'",
        "expected_output": "secure-pod",
        "match": "exact"
      },
      {
        "description": "runAsUser is 1000",
        "command": "kubectl get pod secure-pod -o jsonpath='{.spec.containers[0].securityContext.runAsUser}'",
        "expected_output": "1000",
        "match": "exact"
      },
      {
        "description": "runAsNonRoot is true",
        "command": "kubectl get pod secure-pod -o jsonpath='{.spec.containers[0].securityContext.runAsNonRoot}'",
        "expected_output": "true",
        "match": "exact"
      },
      {
        "description": "allowPrivilegeEscalation is false",
        "command": "kubectl get pod secure-pod -o jsonpath='{.spec.containers[0].securityContext.allowPrivilegeEscalation}'",
        "expected_output": "false",
        "match": "exact"
      }
    ]
  },
  "default_namespace": "default",
  "teardown_commands": [
    {
      "command": "kubectl delete pod secure-pod --ignore-not-found --grace-period=0 --force"
    }
  ]
}
