Is there a way to hide the file listing index page of a MinIO bucket?

Viewed 1612

I have set a MinIO bucket's access permission to "download" so that files can be read (but not written) by anyone, but this has enabled an "index page" that shows the contents of the entire bucket. For example, consider the bucket store/test that contains the file example.png. I would like example.png to be readable by the world wide web, so I set the access permission for store/test to "download", which means that https://store.example.com/test/example.png is now readable by anyone, but it also means that https://store.example.com/test now shows a listing of all files in the bucket:

<!-- Pretty printed result of $ curl https://store.example.com/test -->
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Name>test</Name>
  <Prefix/>
  <Marker/>
  <MaxKeys>4500</MaxKeys>
  <Delimiter/>
  <IsTruncated>false</IsTruncated>
  <Contents>
    <Key>example.png</Key>
    <LastModified>2021-02-05T08:13:06.683Z</LastModified>
    <ETag>"7c8b827ef97e929258e9728cb96059cf-33"</ETag>
    <Size>4295413012</Size>
    <Owner>
      <ID>02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4</ID>
      <DisplayName/>
    </Owner>
    <StorageClass>STANDARD</StorageClass>
  </Contents>
</ListBucketResult>

I don't want to show this listing page, but I do want all files in the bucket to be world-readable, including files that are added to the bucket later. How can this be achieved?

3 Answers

If my bucket name is file

mc policy set none myminio/file
mc policy set download myminio/file/*

Setting a bucket policy is the correct answer here, using the public or download policy allows full access to the bucket, whereas the policy will limit to just the actions you want to allow.

Adding on to @tapos-ghosh policy above, you would apply this as a bucket level policy:

  • Create a file with that policy definition, e.g., bucket_pol.json
  • Apply the bucket policy:

mc policy set-json bucket_pol.json site1/public/ Access permission for site1/public/ is set from `bucket_pol.json

Now, I can access a specific object:

curl http://minio1:9000/public/public.object
Ubuntu 20.04.2 LTS \n \l

But I cannot get a list of objects for the bucket:

curl http://minio1:9000/public/
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied.</Message><BucketName>public</BucketName><Resource>/public/</Resource><RequestId>1668F2D9FA3B99E9</RequestId><HostId>c37065ef-0eb8-4cf3-847a-ffedd29f9e30</HostId></Error>

you need to setup policy . I provide you a policy configuration , help of this file setup your policy

{
   "Statement":[
      {
         "Action":[
            "s3:GetBucketLocation"
         ],
         "Effect":"Allow",
         "Principal":{
            "AWS":[
               "*"
            ]
         },
         "Resource":[
            "arn:aws:s3:::psb-new"
         ]
      },
      {
         "Action":[
            "s3:GetObject"
         ],
         "Effect":"Allow",
         "Principal":{
            "AWS":[
               "*"
            ]
         },
         "Resource":[
            "arn:aws:s3:::psb-new/*"
         ]
      }
   ],
   "Version":"2012-10-17"
}
Related