}
}
-static vector<Policy> get_iam_user_policy_from_attr(CephContext* cct,
+vector<Policy> get_iam_user_policy_from_attr(CephContext* cct,
RGWRados* store,
map<string, bufferlist>& attrs,
const string& tenant) {
int RGWListBuckets::verify_permission()
{
- if (!verify_user_permission(this, s, ARN(), rgw::IAM::s3ListAllMyBuckets)) {
+ rgw::IAM::Partition partition = rgw::IAM::Partition::aws;
+ rgw::IAM::Service service = rgw::IAM::Service::s3;
+
+ if (!verify_user_permission(this, s, ARN(partition, service, "", s->user->user_id.tenant, "*"), rgw::IAM::s3ListAllMyBuckets)) {
return -EACCES;
}
return -EACCES;
}
- if (!verify_user_permission(this, s, ARN(s->bucket), rgw::IAM::s3CreateBucket)) {
+ rgw_bucket bucket;
+ bucket.name = s->bucket_name;
+ bucket.tenant = s->bucket_tenant;
+ ARN arn = ARN(bucket);
+ if (!verify_user_permission(this, s, arn, rgw::IAM::s3CreateBucket)) {
return -EACCES;
}
bool prefetch_data);
extern rgw::IAM::Environment rgw_build_iam_environment(RGWRados* store,
struct req_state* s);
-
+extern vector<rgw::IAM::Policy> get_iam_user_policy_from_attr(CephContext* cct,
+ RGWRados* store,
+ map<string, bufferlist>& attrs,
+ const string& tenant);
static inline int get_system_versioning_params(req_state *s,
uint64_t *olh_epoch,
int RGWHandler_REST::init_permissions(RGWOp* op)
{
- if (op->get_type() == RGW_OP_CREATE_BUCKET)
+ if (op->get_type() == RGW_OP_CREATE_BUCKET) {
+ // We don't need user policies in case of STS token returned by AssumeRole, hence the check for user type
+ if (! s->user->user_id.empty() && s->user->type != TYPE_NONE) {
+ try {
+ map<string, bufferlist> uattrs;
+ if (auto ret = rgw_get_user_attrs_by_uid(store, s->user->user_id, uattrs); ! ret) {
+ if (s->iam_user_policies.empty()) {
+ s->iam_user_policies = get_iam_user_policy_from_attr(s->cct, store, uattrs, s->user->user_id.tenant);
+ } else {
+ // This scenario can happen when a STS token has a policy, then we need to append other user policies
+ // to the existing ones. (e.g. token returned by GetSessionToken)
+ auto user_policies = get_iam_user_policy_from_attr(s->cct, store, uattrs, s->user->user_id.tenant);
+ s->iam_user_policies.insert(s->iam_user_policies.end(), user_policies.begin(), user_policies.end());
+ }
+ }
+ } catch (const std::exception& e) {
+ lderr(s->cct) << "Error reading IAM User Policy: " << e.what() << dendl;
+ }
+ }
+ s->env = rgw_build_iam_environment(store, s);
return 0;
+ }
return do_init_permissions();
}