When defining permissions for AWS resources like S3, KMS, etc, how do I determine whether to define the permission in an identity-based policy attached to the IAM user/group/role or a resource-based policy attached to the resource?
One possible case is if it’s a public or private resource. For example you might have an s3 bucket that is used for your internal stack somehow but should not be public. So leave it private, but setup iam roles for the various services and apply those roles as part of your provisioning automation on those resources.
Where as with a public bucket, you might do something with headers, IP filtering, etc.
Short answer: Resource based policies should be used for things identity based policies cannot provide.
S3 bucket policies should typically be used to manage types of access, such as blocking writing unencrypted data or allowing cross account access. You can use it to grant users/roles access but then you’re making it very difficult to audit access.
KMS is totally different, the key policies are used to defined how the AWS Account accesses the CMK, identity based polices are still required to grant principals access to the CMK. You can grant the account full access but that’s an insanely terrible practice (you want to allow any principal the ability to manage the CMK and key policy?) as you’re dealing with encryption mechanisms.