[#354] Check container owner if bucket exists

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-02-15 12:06:00 +03:00 committed by Kirillov Denis
parent fdc07b8dc1
commit f04815c32f

View file

@ -643,7 +643,7 @@ func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []*Ver
}
func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) {
_, err := n.GetBucketInfo(ctx, p.Name)
bktInfo, err := n.GetBucketInfo(ctx, p.Name)
if err != nil {
if errors.IsS3Error(err, errors.ErrNoSuchBucket) {
return n.createContainer(ctx, p)
@ -651,6 +651,10 @@ func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.I
return nil, err
}
if p.SessionToken != nil && bktInfo.Owner.Equal(p.SessionToken.OwnerID()) {
return nil, errors.GetAPIError(errors.ErrBucketAlreadyOwnedByYou)
}
return nil, errors.GetAPIError(errors.ErrBucketAlreadyExists)
}