Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdk bootstrap fails with Access Denied due to conditional explicit deny in IAM policy #27622

Closed
AliceLeyou opened this issue Oct 20, 2023 · 3 comments
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@AliceLeyou
Copy link

Describe the bug

Bootstrapping fails with a user that has all required IAM permissions, when the user is also assigned a policy statement with a conditional explicit deny. In this case we have a policy that restricts access if the account isn't protected with MFA device. Even though the condition isn't in effect.

Expected Behavior

I expected the CDK to successfully bootstrap as the statement that contains the explicit deny isn't in effect.

Current Behavior

❌  Environment aws://123/eu-central-1 failed bootstrapping: AccessDenied: User: arn:aws:iam::123:user/AliceLeyou is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:eu-central-1:123:stack/CDKToolkit/* with an explicit deny in an identity-based policy
    at Request.<anonymous> (C:\Users\AliceLeyou\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:362:190133)
    at Request.<anonymous> (C:\Users\AliceLeyou\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:362:196364)
    at Request.callListeners (C:\Users\AliceLeyou\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:362:90251) {
  code: 'AccessDenied',
  time: 2023-10-18T07:59:55.636Z,
  requestId: 'e96bb3fc-cfcb-4f3e-a6a6-9df2cce0ee9c',
  statusCode: 403,
  retryable: false,
  retryDelay: 668.2722539643373
}

User: arn:aws:iam::123:user/AliceLeyou is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:eu-central-1:150060545140:stack/CDKToolkit/*

Reproduction Steps

Create an IAM user that has permissions for a cdk bootstrap (in my case not full access but a least privilege list I've found here #21937) and assign a policy with the following statement. As soon as the policy containing this statement was removed, the bootstrap was successful.

MFA policy statement:

        {
            "Sid": "DenyAllExceptListedIfNoMFA",
            "Effect": "Deny",
            "NotAction": [
                "iam:CreateVirtualMFADevice",
                "iam:EnableMFADevice",
                "iam:GetUser",
                "iam:ListMFADevices",
                "iam:ListVirtualMFADevices",
                "iam:ResyncMFADevice",
                "iam:ChangePassword",
                "sts:GetSessionToken",
                "iam:GetAccountPasswordPolicy"
            ],
            "Resource": "*",
            "Condition": {
                "BoolIfExists": {
                    "aws:MultiFactorAuthPresent": "false"
                }
            }
        }

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.101.1 (build 16ddad1)

Framework Version

No response

Node.js Version

v18.12.1

OS

Microsoft Windows 10 Pro

Language

TypeScript

Language Version

No response

Other information

No response

@AliceLeyou AliceLeyou added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 20, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Oct 20, 2023
@peterwoodworth
Copy link
Contributor

The only explanation would be that the condition is in effect. I can't tell from here whether your condition should be taking effect or not, either way I don't think that would be a CDK issue as this error is being thrown due to lack of permissions.

Either way, I don't see where this policy block came from in the first place or why it would be a bug if it didn't work since this is undocumented to begin with

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. bug This issue is a bug. labels Oct 20, 2023
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 23, 2023
@kazazor
Copy link

kazazor commented Dec 7, 2023

@AliceLeyou did you end up solving this issue?
I'm having the same issue with the conditional MultiFactorAuthPresent.

We added a policy to force everyone to setup MFA. Even after setting it up (and by doing so, gaining access to all of the permissions we have in another policy), cdk still fails here.
Removing this policy with the condition seems to solve it.

@peterwoodworth can this be reopened?
Here is more input from our side.

The ForceMFS policy (taken from AWS docs) :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowViewAccountInfo",
            "Effect": "Allow",
            "Action": [
                "iam:GetAccountPasswordPolicy",
                "iam:ListVirtualMFADevices"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowManageOwnPasswords",
            "Effect": "Allow",
            "Action": [
                "iam:ChangePassword",
                "iam:GetUser"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnVirtualMFADevice",
            "Effect": "Allow",
            "Action": [
                "iam:CreateVirtualMFADevice"
            ],
            "Resource": "arn:aws:iam::*:mfa/*"
        },
        {
            "Sid": "AllowManageOwnUserMFA",
            "Effect": "Allow",
            "Action": [
                "iam:DeactivateMFADevice",
                "iam:EnableMFADevice",
                "iam:ListMFADevices",
                "iam:ResyncMFADevice"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "DenyAllExceptListedIfNoMFA",
            "Effect": "Deny",
            "NotAction": [
                "iam:CreateVirtualMFADevice",
                "iam:EnableMFADevice",
                "iam:GetUser",
                "iam:GetMFADevice",
                "iam:ListMFADevices",
                "iam:ListVirtualMFADevices",
                "iam:ResyncMFADevice",
                "sts:GetSessionToken"
            ],
            "Resource": "*",
            "Condition": {
                "BoolIfExists": {
                    "aws:MultiFactorAuthPresent": "false"
                }
            }
        }
    ]
}

And after setting up MFA:
Screenshot 2023-12-07 at 14 02 16

The cdk fails with this error:

User: arn:aws:iam::XXXXX:user/YYYY is not authorized to perform: cloudformation:DescribeStacks on resource: arn:aws:cloudformation:us-west-2:XXXXX:stack/vpc-stack-staging/08b3a5c0-8f54-11ee-91d0-06c4e3f2a485 with an explicit deny in an identity-based policy

And as you can see from the user's access advisor the user has access to it and even tried to access it today:
Screenshot 2023-12-07 at 14 04 44

So the condition is met when using the console, but not using CDK.
Does it maybe have anything to do with role-assuming or anything like that? Although as I mentioned without the ForceMFA policy everything works again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. package/tools Related to AWS CDK Tools or CLI response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants