Skip to content

Account with NotPrincipal should explicitly provide permission #8782

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vh05
Copy link
Contributor

@vh05 vh05 commented Feb 10, 2025

This is the bucket policy with below combination

    
    Effect : DENY,
    Action: $OPERATION,
    NotPrincipal: $ACCOUNT

The permission on the "Action" for the $ACCOUNT mentioned in the "NotPrincipal" should be explicitly given.

Example: For "Action: get_object", if we want to DENY permission for * (all accounts) and we want to give explicit permission to any one or few accounts, then we can include that account as part of part of "NotPrincipal"

Check DFBUGS-1519 for steps to reproduce the issue

Fixes: https://issues.redhat.com/browse/DFBUGS-1519

@shirady
Copy link
Contributor

shirady commented Feb 10, 2025

@vh05 please add tests in the file "test_s3_bucket_policy.js"

@shirady
Copy link
Contributor

shirady commented Feb 10, 2025

@vh05 I would also start with testing on AWS the steps that are expected to happen before we change it our logs.

Please also add the full testing instructions that you manually did so we can understand what was done (you can add as comment if you prefer).

@nadavMiz
Copy link
Contributor

@vh05 from what I understand this issue is not related to "deny statement using NotPrincipal". can you pleas change the PR name and description to reflect what you are actually doing here

@vh05
Copy link
Contributor Author

vh05 commented Feb 27, 2025

@vh05 from what I understand this issue is not related to "deny statement using NotPrincipal". can you pleas change the PR name and description to reflect what you are actually doing here

Sorry for the delayed response. I have updated the patch. Now the fix and the issue description matches I think

Copy link
Contributor

@shirady shirady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of comments and questions.

Key: KEY,
});

await assert_throws_async(s3_a.putObject({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I thought s3_a is the only user that can put object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The account added in NotPrincipal is allowed on the Action. It is like excluding everyone other than account added as NotPrincipal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use assert_throws_async it is expected to throw an error.
As you mentioned the user_a is allowed on the action, then you probably need to run it without this function on s3_a and can run it on another user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. That expression should be with user_b not user_a. My bad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fixing the test should be able to use notPrincipal it is in the scope of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotPrincipal with Allow is not expected operation as per aws doc

https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_notprincipal.html

from AWS:
NotPrincipal must be used with "Effect":"Deny". Using it with "Effect":"Allow" is not supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it is something that would be fixed in your suggested fix?

@@ -146,18 +146,31 @@ async function _is_object_version_fit(req, predicate, value) {
return res;
}

async function has_bucket_policy_permission(policy, account, method, arn_path, req) {
async function has_bucket_policy_permission(policy, account, method, arn_path, req, account_identifier_type = 'id') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose to have id as default?
the id is currently only in NC.
Please add JSDoc to this function or a comment about the options of account_identifier_type. I think using a enum can help us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the id is considered to solve issues regarding account name and thats the updated one. We are giving exception to name parameter.

I think using a enum can help us
I feel it is for default argument, string is fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see in the Jira ticket, it is not solving it completely.
I didn't understand the quote; was it not clear? I meant to add enum so it will be easier to understand the options that we can use.

Comment on lines 206 to 215
// If the account is categorized as "Not Principal," we need to ALLOW operations
// for that account under the associated principal.
//
// To maintain backward compatibility, we also support name-based comparison for principal matching.
//
// - If `account_identifier_type` is "id" but the `account` parameter contains a name,
// we return `false` to proceed/bypass to the next step, where we check for a name match.
//
// - In the next step, if `account_identifier_type` is "name" and the `account` also contains a name,
// we return the actual value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the allow is by ids and the deny is by names?
You can add it a test case.
What will happen when we support ARN, it will be more complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the allow is by ids and the deny is by names?

Is that test case required. IIUC the name is for backward compatibility and the fix almost like a workaround than a feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is another option, we decided to not remove this to be backward compatible.
Anyway, it is a valid option, and in the containerized it is the only option.

@vh05 vh05 force-pushed the DFBUGS-1519 branch 5 times, most recently from 48d71ef to 25191b9 Compare March 3, 2025 06:50
@vh05 vh05 changed the title [MCG NC] Bucket policy with deny statement using NotPrincipal also denies the principal Account with NotPrincipal should explicitly provide permission Apr 3, 2025
@vh05 vh05 force-pushed the DFBUGS-1519 branch 3 times, most recently from c8a46a9 to e917402 Compare April 8, 2025 11:08
@vh05 vh05 force-pushed the DFBUGS-1519 branch 3 times, most recently from 11caeca to 3d7a476 Compare April 22, 2025 11:45
This is the bucket policy with below combination

```

    Effect : DENY,
    Action: $OPERATION,
    NotPrincipal: $ACCOUNT

```
The permission on the "Action" for the $ACCOUNT mentioned in the
"NotPrincipal" should be explicitly given.

Example: For "Action: get_object", if we want to DENY permission
for * (all accounts) and we want to give explicit permission to
any one or few accounts, then we can include that account as
part of part of "NotPrincipal"

Check DFBUGS-1519 for steps to reproduce the issue

Fixes: https://issues.redhat.com/browse/DFBUGS-1519

Signed-off-by: Vinayakswami Hariharmath <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants