Object permission control
Permission control
Set access permissions for objects
Currently, BOS supports two methods for setting ACLs. For details, refer to Permission Control
The first method is to use Canned ACL. During bos_put_object_acl, the object access permission is set via the header "x-bce-acl", "x-bce-grant-read" or "x-bce-grant-permission". Currently configurable permissions include private and public-read. The three types of headers cannot appear in the same request simultaneously.
The second method is to set the accessControlList in the custom Acl style, specifically by uploading its json string, or directly upload an ACL file. For details, refer to Permission Control Overview
Set Canned ACL
Canned ACL is a predefined access permission, allowing users to set it for specific objects, supporting three interfaces:
1 bos_acl_e bos_acl;
2 bos_acl = BOS_ACL_PRIVATE;
3 bos_status_t *s = NULL;
4 bos_table_t *resp_headers = NULL;
5 bos_string_t object;
6 s = bos_put_object_acl(options, &bucket, &object, bos_acl, NULL, NULL, NULL, NULL, &resp_headers);
7 print_headers(resp_headers);
8 if (bos_status_is_ok(s)) {
9 printf("put bucket acl succeeded\n");
10 } else {
11 printf("put bucket acl failed\n");
12 }
Set custom ACL
Users can refer to the following code to set bucket's custom access permissions, supporting three different parameters:
1 bos_acl_e bos_acl;
2 bos_acl = 6;
3 bos_status_t *s = NULL;
4 bos_table_t *resp_headers = NULL;
5 bos_string_t object;
6 char * acl_json = "{ \"accessControlList\": [ { \"grantee\":[{ \"id\":\"168bf6fd8fa74d9789f35a283a1f15e2\
7" }], \"permission\":[\"WRITE\"] } ] }";
8 s = bos_put_object_acl(options, &bucket, &object, NULL, acl_json, NULL, NULL, NULL, &resp_headers);
9 print_headers(resp_headers);
10 if (bos_status_is_ok(s)) {
11 printf("put object acl succeeded\n");
12 } else {
13 printf("put object acl failed\n");
14 }
Obtain access permissions for objects
The following code retrieves an object's access permission:
1 s = bos_get_object_acl(options, &bucket, &object, &root, &resp_headers);
2 *jsonString = json_dumps(root, JSON_INDENT(2));
3 printf("\n%s\n", jsonString);
Note:
The specific structure Grant involved in ACL is shared between bucket ACL and object ACL systems
Currently, only the grantee and permission fields are utilized in the object acl system.
. The remaining annotated fields are unique to the bucket acl system.
