Skip to content

Commit ab34216

Browse files
macaroon,grant: added new permissions for get/set bucket object lock config
Updates storj/edge#500 Change-Id: I96054ce31eadeae406e1a32e6686b8aacd1bcd4c
1 parent 259b391 commit ab34216

10 files changed

+89
-43
lines changed

grant/internal/pb/encryption.pico.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grant/internal/pb/encryption_access.pico.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grant/internal/pb/scope.pico.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grant/restrict.go

+21-13
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ type Permission struct {
6464
// AllowBypassGovernanceRetention gives permission for governance retention
6565
// to be bypassed on objects.
6666
AllowBypassGovernanceRetention bool
67+
// AllowPutBucketObjectLockConfiguration gives permission for object lock configuration to be
68+
// placed on buckets.
69+
AllowPutBucketObjectLockConfiguration bool
70+
// AllowGetBucketObjectLockConfiguration gives permission for object lock configuration to be
71+
// retrieved from buckets.
72+
AllowGetBucketObjectLockConfiguration bool
6773
// NotBefore restricts when the resulting access grant is valid for.
6874
// If set, the resulting access grant will not work if the Satellite
6975
// believes the time is before NotBefore.
@@ -112,19 +118,21 @@ func (access *Access) Restrict(permission Permission, prefixes ...SharePrefix) (
112118
}
113119

114120
caveat := macaroon.WithNonce(macaroon.Caveat{
115-
DisallowReads: !permission.AllowDownload,
116-
DisallowWrites: !permission.AllowUpload,
117-
DisallowLists: !permission.AllowList,
118-
DisallowDeletes: !permission.AllowDelete,
119-
DisallowLocks: !permission.AllowLock,
120-
DisallowPutRetention: !permission.AllowPutObjectRetention,
121-
DisallowGetRetention: !permission.AllowGetObjectRetention,
122-
DisallowPutLegalHold: !permission.AllowPutObjectLegalHold,
123-
DisallowGetLegalHold: !permission.AllowGetObjectLegalHold,
124-
DisallowBypassGovernanceRetention: !permission.AllowBypassGovernanceRetention,
125-
NotBefore: notBefore,
126-
NotAfter: notAfter,
127-
MaxObjectTtl: permission.MaxObjectTTL,
121+
DisallowReads: !permission.AllowDownload,
122+
DisallowWrites: !permission.AllowUpload,
123+
DisallowLists: !permission.AllowList,
124+
DisallowDeletes: !permission.AllowDelete,
125+
DisallowLocks: !permission.AllowLock,
126+
DisallowPutRetention: !permission.AllowPutObjectRetention,
127+
DisallowGetRetention: !permission.AllowGetObjectRetention,
128+
DisallowPutLegalHold: !permission.AllowPutObjectLegalHold,
129+
DisallowGetLegalHold: !permission.AllowGetObjectLegalHold,
130+
DisallowBypassGovernanceRetention: !permission.AllowBypassGovernanceRetention,
131+
DisallowPutBucketObjectLockConfiguration: !permission.AllowPutBucketObjectLockConfiguration,
132+
DisallowGetBucketObjectLockConfiguration: !permission.AllowGetBucketObjectLockConfiguration,
133+
NotBefore: notBefore,
134+
NotAfter: notAfter,
135+
MaxObjectTtl: permission.MaxObjectTTL,
128136
})
129137

130138
for _, prefix := range prefixes {

grant/restrict_test.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ func TestRestrict(t *testing.T) {
3737
}
3838

3939
fullPermission := Permission{
40-
AllowDownload: true,
41-
AllowUpload: true,
42-
AllowList: true,
43-
AllowDelete: true,
44-
AllowPutObjectRetention: true,
45-
AllowGetObjectRetention: true,
46-
AllowPutObjectLegalHold: true,
47-
AllowGetObjectLegalHold: true,
48-
AllowBypassGovernanceRetention: true,
40+
AllowDownload: true,
41+
AllowUpload: true,
42+
AllowList: true,
43+
AllowDelete: true,
44+
AllowPutObjectRetention: true,
45+
AllowGetObjectRetention: true,
46+
AllowPutObjectLegalHold: true,
47+
AllowGetObjectLegalHold: true,
48+
AllowBypassGovernanceRetention: true,
49+
AllowPutBucketObjectLockConfiguration: true,
50+
AllowGetBucketObjectLockConfiguration: true,
4951
}
5052

5153
action1 := macaroon.Action{

macaroon/apikey.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ const (
7171
// ActionPutObjectLegalHold specifies an action related to updating
7272
// Object Legal Hold configuration.
7373
ActionPutObjectLegalHold ActionType = 9
74-
// ActionGetObjectLegalHold specifies an action related to updating
74+
// ActionGetObjectLegalHold specifies an action related to retrieving
7575
// Object Legal Hold configuration.
7676
ActionGetObjectLegalHold ActionType = 10
7777
// ActionBypassGovernanceRetention specifies an action related to bypassing
7878
// Object Governance Retention.
7979
ActionBypassGovernanceRetention ActionType = 11
80+
// ActionPutBucketObjectLockConfiguration specifies an action related to updating
81+
// Bucket Object Lock configuration.
82+
ActionPutBucketObjectLockConfiguration ActionType = 12
83+
// ActionGetBucketObjectLockConfiguration specifies an action related to retrieving
84+
// Bucket Object Lock configuration.
85+
ActionGetBucketObjectLockConfiguration ActionType = 13
8086
)
8187

8288
// APIKeyVersion specifies the version of an API key.
@@ -182,6 +188,8 @@ func (a *APIKey) Check(ctx context.Context, secret []byte, version APIKeyVersion
182188
ActionPutObjectLegalHold,
183189
ActionGetObjectLegalHold,
184190
ActionBypassGovernanceRetention,
191+
ActionPutBucketObjectLockConfiguration,
192+
ActionGetBucketObjectLockConfiguration,
185193
ActionLock:
186194
return ErrUnauthorized.New("action disallowed")
187195
}
@@ -394,6 +402,14 @@ func (c *Caveat) Allows(action Action) bool {
394402
if c.DisallowBypassGovernanceRetention {
395403
return false
396404
}
405+
case ActionPutBucketObjectLockConfiguration:
406+
if c.DisallowPutBucketObjectLockConfiguration {
407+
return false
408+
}
409+
case ActionGetBucketObjectLockConfiguration:
410+
if c.DisallowGetBucketObjectLockConfiguration {
411+
return false
412+
}
397413
default:
398414
return false
399415
}

macaroon/apikey_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func TestSerializeParseRestrictAndCheck(t *testing.T) {
7070
ActionPutObjectLegalHold,
7171
ActionGetObjectLegalHold,
7272
ActionBypassGovernanceRetention,
73+
ActionPutBucketObjectLockConfiguration,
74+
ActionGetBucketObjectLockConfiguration,
7375
ActionLock,
7476
} {
7577
action1.Op = actionType

macaroon/types.pico.go

+23-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

macaroon/types.proto

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ message Caveat {
2222
bool disallow_put_legal_hold = 8;
2323
bool disallow_get_legal_hold = 9;
2424
bool disallow_bypass_governance_retention = 11;
25+
bool disallow_put_bucket_object_lock_configuration = 12;
26+
bool disallow_get_bucket_object_lock_configuration = 13;
2527

2628
// If any entries exist, require all access to happen in at least
2729
// one of them.

proto.lock

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
"name": "disallow_bypass_governance_retention",
5858
"type": "bool"
5959
},
60+
{
61+
"id": 12,
62+
"name": "disallow_put_bucket_object_lock_configuration",
63+
"type": "bool"
64+
},
65+
{
66+
"id": 13,
67+
"name": "disallow_get_bucket_object_lock_configuration",
68+
"type": "bool"
69+
},
6070
{
6171
"id": 10,
6272
"name": "allowed_paths",

0 commit comments

Comments
 (0)