Skip to content

s3 bucket table resource based policy not accepted what is wrong ?

0

hello while trying to use resource based policies for s3 table buckets here is the policy i used for aa role i created

{
    "Version": "2012-10-17",
    "Statement": [ 
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::123:role/roletest1"
            },
            "Action": [
                "s3tables:GetTableData", 
                "s3tables:GetTableMetadataLocation"
            ],
            "Resource": "arn:aws:s3tables:us-west-2:123:table-bucket/tabletest/table/*",
            "Condition": { 
                "StringLike": { "s3tables:TableNamespace": "namesptest" }
            }
        }
    ]
}


but when i try to assign it to a table using following command aws s3tables put-table-policy --namespace namesptest --name table1 --resource-policy ".\j.json" --table-bucket-arn arn:aws:s3tables:us-west-2:123:bucket/tabletest --profile admin

i get this error:

An error occurred (BadRequestException) when calling the PutTablePolicy operation: The specified policy is malformed i used the same policy mentionned in the doc

2 Answers
0

There are a few issues with your approach:

  1. Policy Type Mismatch: The policy you've created is a table bucket policy, but you're trying to apply it as a table policy. These are two different types of policies in S3 Tables.

  2. Command Mismatch: You're using the put-table-policy command, which is for setting policies on individual tables. However, your policy is structured for a table bucket.

  3. Resource ARN: The resource ARN in your policy is for a table bucket, not an individual table.

To resolve this, you have two options:

Option 1: If you want to apply this policy to the entire table bucket: Use the put-table-bucket-policy command instead. Modify your command to:

aws s3tables put-table-bucket-policy --table-bucket-arn arn:aws:s3tables:us-west-2:123:bucket/tabletest --resource-policy file://j.json --profile admin

Option 2: If you want to apply a policy to a specific table: Modify your policy to target a specific table instead of the entire bucket. Change the Resource line to:

"Resource": "arn:aws:s3tables:us-west-2:123:table/tabletest/namesptest/table1"

Then use your original put-table-policy command.

Also, ensure that:

  • Your JSON file is properly formatted and doesn't contain any syntax errors.
  • You have the necessary permissions to perform these operations.
  • The role ARN, account ID, and other details in your policy are correct.

Remember, table bucket policies are for managing permissions at the bucket or namespace level, while table policies are for individual tables. Choose the appropriate policy type based on your access control needs.

Sources
Resource-based policies for S3 Tables - Amazon Simple Storage Service
Managing table bucket policies - Amazon Simple Storage Service
Managing table policies - Amazon Simple Storage Service

answered 2 years ago

EXPERT

reviewed 2 years ago

  • I got the same error when i set this aws s3tables put-table-bucket-policy --resource-policy ".\j.json" --table-bucket-arn arn:aws:s3tables:us-west-2:123:bucket/tabletest --profile admin

    An error occurred (BadRequestException) when calling the PutTableBucketPolicy operation: The specified policy is malformed

0

Hello.

I have a problem with the AWS CLI command I'm running.
If the policy is saved in a JSON file, please read it using "file://" as shown below.

aws s3tables put-table-policy --namespace my_namespace --name my_table --resource-policy file://Untitled-4.json --table-bucket-arn arn:aws:s3tables:ap-northeast-1:123456789012:bucket/kobayashi-test-table

By the way, there is no key called "s3tables:TableNamespace" in the "Condition" section of the policy you created, so I think it is invalid as a policy.
So please change it to "s3tables:namespace" as shown below.
In the "Condition" section of "s3tables", you can use "s3tables:namespace" and "s3tables:tableName".
https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3tables.html#amazons3tables-policy-keys

{
    "Version": "2012-10-17",
    "Statement": [ 
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::123456789012:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_AdministratorAccess_yyyyy"
            },
            "Action": [
                "s3tables:GetTableData", 
                "s3tables:GetTableMetadataLocation"
            ],
            "Resource": "arn:aws:s3tables:ap-northeast-1:123456789012:bucket/kobayashi-test-table/table/12345678-1234-1234-1234-1233456578909",
            "Condition": { 
                "StringLike": { "s3tables:namespace": "my_namespace" }
            }
        }
    ]
}
EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.