I'm trying to remove access to temporarily generated session tokens using STS.
But received following error:
Exception in thread "main" com.amazonaws.services.securitytoken.model.MalformedPolicyDocumentException: Policy document should not specify a principal. (Service: AWSSecurityTokenService; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: c563c2c1-62a8-478e-98a3-f6153ee8df03; Proxy: null)
AssumeRoleRequest roleRequest =
new AssumeRoleRequest()
.withRoleArn(ROLE_ARN)
.withTags(tags)
.withRoleSessionName(ROLE_SESSION_NAME);
roleRequest.setDurationSeconds(60 * 15);
roleRequest.withPolicy(**INVALIDATE_POLICY**);
AssumeRoleResult roleResponse = stsClient.assumeRole(roleRequest);
Generated policy based on the documentation:
{
"Version": "2012-10-17",
"Statement": {
"Principal": {
"AWS": "arn:aws:sts::ACCOUNT-ID-WITHOUT-HYPHENS:assumed-Role/Mary"
},
"Effect": "Deny",
"Action": "s3:*",
"Resource": "arn:aws:s3:::EXAMPLE-BUCKET"
}
}