NC | NSFS | Fix Issue DFBUGS-1307 | Bucket Policy With Principal as ID #8680
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explain the changes
rest_s3
andbucketspace_fs
to check the permission by the principal on account name when the previous check was only not DENY, so in case someone puts several statements using both account ID and account name, we won't skip it after the checks on the account ID.Issues: Fixed Jira-1307
Currently, we had an issue when someone put a bucket policy with two statements:
We used the first one only as it was not "IMPLICIT_DENY" and didn't check the second option.
GAPs:
Deny
.Allow
) - opened Improve Bucket Policy Code Ideas (Use Enum) #8697.bucketspace_fs
Methods #8699, for example:noobaa-core/src/sdk/bucketspace_fs.js
Lines 672 to 674 in a5b95e7
Testing Instructions:
Automatic test:
sudo NC_CORETEST=true node ./node_modules/mocha/bin/mocha ./src/test/unit_tests/test_s3_bucket_policy.js
make run-single-test testname=test_s3_bucket_policy.js CONTAINER_PLATFORM=linux/arm64
(I have MacOS so I use the flagCONTAINER_PLATFORM=linux/arm64
).Manual Test:
sudo node src/cmd/manage_nsfs account add --name <account-name> --new_buckets_path /Users/buckets/ --access_key <access-key> --secret_key <secret-key> --uid <uid> --gid <gid>
Note: before creating the account need to give permission to the
new_buckets_path
:chmod 777 /Users/buckets/
.sudo node src/cmd/nsfs --debug 5
alias nc-user-1-s3=‘AWS_ACCESS_KEY_ID=<access-key> AWS_SECRET_ACCESS_KEY=<secret-key> aws --no-verify-ssl --endpoint-url https://localhost:6443’
.nc-user-1-s3 s3 ls; echo $?
nc-user-1-s3 s3 mb s3://bucket-1307
(bucket-1307
is the bucket name in this example)echo 'test_data' | nc-user-1-s3 s3 cp - s3://bucket-1307/test_object.txt
sudo node src/cmd/manage_nsfs account add --name <account-name> --new_buckets_path /Users/buckets/ --access_key <access-key> --secret_key <secret-key> --uid <uid> --gid <gid>
(use the sameuid
andgid
as the first created account).nc-user-2-s3 s3 ls; echo $?
Statement with * allow, statement with account name deny
13. Put bucket policy (statement with account name):
nc-user-1-s3 s3api put-bucket-policy --bucket bucket-1307 --policy file://policy1.json
policy1.json (replace the principal with the account name in the Deny statement):
nc-user-2-s3 s3api get-object --bucket bucket-1307 --key test_object.txt /dev/stdout
(should getAccessDenied
error)Statement with * allow, statement with account ID deny
15. Put bucket policy (statement with account ID):
nc-user-1-s3 s3api put-bucket-policy --bucket bucket-1307 --policy file://policy2.json
policy2.json (replace the principal with the account ID in the Deny statement)::
nc-user-2-s3 s3api get-object --bucket bucket-1307 --key test_object.txt /dev/stdout
(should getAccessDenied
error)