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

PutBucketPolicy: specifying '*' as a principal results in 500 #863

Closed
evgeniiz321 opened this issue Oct 19, 2023 · 6 comments · Fixed by #958
Closed

PutBucketPolicy: specifying '*' as a principal results in 500 #863

evgeniiz321 opened this issue Oct 19, 2023 · 6 comments · Fixed by #958
Assignees
Labels
bug Something isn't working I4 No visible changes S4 Routine U2 Seriously planned
Milestone

Comments

@evgeniiz321
Copy link

evgeniiz321 commented Oct 19, 2023

    policy_document = json.dumps(
        {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Principal": "*",
                    "Action": "*",
                    "Resource": [resource1, resource2],
                }
            ],
        }
    )
    client.put_bucket_policy(Bucket=bucket_name, Policy=policy_document)

Results in

2023-10-19T01:49:14.040Z        error   handler/util.go:29      call method     {"status": 500, "request_id": "c8b88b4c-bc35-4fea-a1fc-f69cee176925", "method": "PutBucketPolicy", "bucket": "yournamehere-0ejrug068pe8wi6m-1", "object": "", "description": "could not parse bucket policy", "error": "json: cannot unmarshal string into Go struct field statement.Statement.Principal of type handler.principal"}

According to https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html, https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html and https://gist.github.com/jstewmon/ee5d4b7ec0d8d60cbc303cb515272f8a#file-aws-iam-poilcy-schema-json-L129 "Principal": "*" is a valid principal.

Also take a look at the whole spec I provided above, looks like it is not parsed correctly. E.g. test_bucket_policy_put_obj_request_obj_tag fails with

2023-10-19T23:38:21.897Z        error   handler/util.go:29      call method     {"status": 500, "request_id": "be0dc325-c606-4a34-a33e-1042c4c684c4", "method": "PutBucketPolicy", "bucket": "yournamehere-4xmblafeakl1mnmp-1", "object": "", "description": "could not parse bucket policy", "error": "json: cannot unmarshal string into Go struct field statement.Statement.Action of type []string"}

But the schema provided is valid:

{"Version": "2012-10-17", "Statement": [{"Action": "s3:PutObject", "Principal": {"AWS": "*"}, "Effect": "Allow", "Resource": "arn:aws:s3:::yournamehere-4xmblafeakl1mnmp-1/*", "Condition": {"StringEquals": {"s3:RequestObjectTag/security": "public"}}}]}

For a complete list of failing tests due to an incorrect schema parsing see tests with this mark:

@pytest.mark.skip(reason="https://github.com/nspcc-dev/neofs-s3-gw/issues/863")
@evgeniiz321 evgeniiz321 added bug Something isn't working triage labels Oct 19, 2023
@roman-khimov roman-khimov added this to the v0.30.1 milestone Oct 19, 2023
@smallhive smallhive self-assigned this Oct 31, 2023
@smallhive
Copy link
Contributor

Looks like such principal in not supported

@evgeniiz321
Copy link
Author

I maybe wrong, but it seems to me, that it is said here that we should support Principal: '*', but don't support multiple 'Principal' inside single 'Statement'. Anyways - if we don't want to support the schema above - we should return some message and status code that makes sense, not 500.

@smallhive
Copy link
Contributor

smallhive commented Nov 2, 2023

Correct, but object wildcard:

{
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Principal": {"AWS": "*"},
                    "Action": "*",
                    "Resource": [resource1, resource2],
                }
            ],
        }

not just string wildcard:

{
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Principal": "*",
                    "Action": "*",
                    "Resource": [resource1, resource2],
                }
            ],
        }

@roman-khimov
Copy link
Member

This (and Action) can be fixed with custom MarshalJSON, it's OK to have it here for better compatibility. "Action": "*" and "Principal": "*" notations can be expected to be quite popular (they're just very simple for the purpose).

@roman-khimov roman-khimov added U2 Seriously planned S4 Routine I4 No visible changes labels Dec 20, 2023
@smallhive smallhive linked a pull request Jun 4, 2024 that will close this issue
@smallhive
Copy link
Contributor

PR fixes the wildcard issue, but the test still failed.
I need assistance to handle it. Right now tests failed with the next s3gate error

2024-06-04T14:30:12.450+0400    error   handler/util.go:29      call method     {"status": 403, "request_id": "ef71a550-9ffb-4551-8fde-763f78b04b9d", "method": "PutObject", "bucket": "yournamehere-1469jxiccnya4avo-1", "object": "testobj", "description": "could not get bucket settings", "error": "couldn't get node: access denied: rpc error: code = Unknown desc = access to operation GET is denied by extended ACL check: DENY eACL rule"}

The errors appears here when we are trying to get data from tree service.
On one hand, it is a valid error, because test sets only PutObject action.
On the other hand, we can't put an object because we can't read info about lockConfiguration from treeService

@roman-khimov
Copy link
Member

Likely there are other valid uses for * that will have a broader set of actions, so this can be documented as a known limitation for now. Tree service is to be discontinued, so we won't even try fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working I4 No visible changes S4 Routine U2 Seriously planned
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants