radosgw-admin role-policy put --role-name=S3Access1 --policy-name=Policy1 --policy-doc=\{\"Version\":\"2012-10-17\",\"Statement\":\[\{\"Effect\":\"Allow\",\"Action\":\[\"s3:*\"\],\"Resource\":\"arn:aws:s3:::example_bucket\"\}\]\}
+For passing ``policy-doc`` as a file::
+
+ radosgw-admin role-policy put --role-name=S3Access1 --policy-name=Policy1 --infile policy-document.json
+
In the above example, we are attaching a policy 'Policy1' to role 'S3Access1', which allows all s3 actions on 'example_bucket'.
List Permission Policy Names attached to a Role
return -EINVAL;
}
- if (perm_policy_doc.empty()) {
+ if (perm_policy_doc.empty() && infile.empty()) {
cerr << "permission policy document is empty" << std::endl;
return -EINVAL;
}
- bufferlist bl = bufferlist::static_from_string(perm_policy_doc);
+ bufferlist bl;
+ if (!infile.empty()) {
+ int ret = read_input(infile, bl);
+ if (ret < 0) {
+ cerr << "ERROR: failed to read input policy document: " << cpp_strerror(-ret) << std::endl;
+ return -ret;
+ }
+ perm_policy_doc = bl.to_str();
+ } else {
+ bl = bufferlist::static_from_string(perm_policy_doc);
+ }
try {
const rgw::IAM::Policy p(g_ceph_context, tenant, bl);
} catch (rgw::IAM::PolicyParseException& e) {