Interview Prep/Kubernetes/Storage and volumes

Volume attach fails with `AttachVolume.Attach failed for volume "pvc-..." : rpc error: code = Internal desc = Could not attach volume ... UnauthorizedOperation: You are not authorized to perform this operation`.

IntermediateTroubleshootingStorage and volumes
Answer

Likely causes → The CSI controller's IAM role lacks ec2:AttachVolume, the volume is encrypted with a KMS key the role cannot use (kms:CreateGrant), or an SCP denies the call.

Diagnose →

kubectl get sa ebs-csi-controller-sa -n kube-system -o jsonpath='{.metadata.annotations}'
aws sts decode-authorization-message --encoded-message <msg-from-error> | jq -r .DecodedMessage | jq

Fix → Attach AmazonEBSCSIDriverPolicy, plus a KMS policy statement allowing kms:CreateGrant, kms:Decrypt, kms:GenerateDataKeyWithoutPlaintext on the CMK for the role.

Prevent → Keep the CSI role policy in IaC next to the KMS key definition.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Storage and volumes