@@ -929,7 +929,7 @@ func TestAuthorizeScope(t *testing.T) {
929
929
Org :map [string ][]Permission {},
930
930
User : []Permission {},
931
931
},
932
- AllowIDList : []string { workspaceID .String ()},
932
+ AllowIDList : []AllowListElement {{ Type : ResourceWorkspace . Type , ID : workspaceID .String ()} },
933
933
},
934
934
}
935
935
@@ -1019,7 +1019,9 @@ func TestAuthorizeScope(t *testing.T) {
1019
1019
User : []Permission {},
1020
1020
},
1021
1021
// Empty string allow_list is allowed for actions like 'create'
1022
- AllowIDList : []string {"" },
1022
+ AllowIDList : []AllowListElement {{
1023
+ Type :ResourceWorkspace .Type ,ID :"" ,
1024
+ }},
1023
1025
},
1024
1026
}
1025
1027
@@ -1145,7 +1147,7 @@ func TestAuthorizeScope(t *testing.T) {
1145
1147
ResourceUser .Type : {policy .ActionRead },
1146
1148
}),
1147
1149
},
1148
- AllowIDList : []string { policy . WildcardSymbol },
1150
+ AllowIDList : []AllowListElement { AllowListAll () },
1149
1151
},
1150
1152
}
1151
1153
@@ -1163,6 +1165,131 @@ func TestAuthorizeScope(t *testing.T) {
1163
1165
)
1164
1166
}
1165
1167
1168
+ func TestScopeAllowList (t * testing.T ) {
1169
+ t .Parallel ()
1170
+
1171
+ defOrg := uuid .New ()
1172
+
1173
+ // Some IDs to use
1174
+ wid := uuid .New ()
1175
+ gid := uuid .New ()
1176
+
1177
+ user := Subject {
1178
+ ID :"me" ,
1179
+ Roles :Roles {
1180
+ must (RoleByName (RoleOwner ())),
1181
+ },
1182
+ Scope :Scope {
1183
+ Role :Role {
1184
+ Identifier :RoleIdentifier {
1185
+ Name :"AllowList" ,
1186
+ OrganizationID :defOrg ,
1187
+ },
1188
+ DisplayName :"AllowList" ,
1189
+ // Allow almost everything
1190
+ Site :allPermsExcept (ResourceUser ),
1191
+ },
1192
+ AllowIDList : []AllowListElement {
1193
+ {Type :ResourceWorkspace .Type ,ID :wid .String ()},
1194
+ {Type :ResourceWorkspace .Type ,ID :"" },// Allow to create
1195
+ {Type :ResourceTemplate .Type ,ID :policy .WildcardSymbol },
1196
+ {Type :ResourceGroup .Type ,ID :gid .String ()},
1197
+
1198
+ // This scope allows all users, but the permissions do not.
1199
+ {Type :ResourceUser .Type ,ID :policy .WildcardSymbol },
1200
+ },
1201
+ },
1202
+ }
1203
+
1204
+ testAuthorize (t ,"AllowList" ,user ,
1205
+ // Allowed:
1206
+ cases (func (c authTestCase )authTestCase {
1207
+ c .allow = true
1208
+ return c
1209
+ },
1210
+ []authTestCase {
1211
+ {resource :ResourceWorkspace .InOrg (defOrg ).WithOwner (user .ID ).WithID (wid ),actions : []policy.Action {policy .ActionRead }},
1212
+ // matching on empty id
1213
+ {resource :ResourceWorkspace .InOrg (defOrg ).WithOwner (user .ID ),actions : []policy.Action {policy .ActionCreate }},
1214
+
1215
+ // Template has wildcard ID, so any uuid is allowed, including the empty
1216
+ {resource :ResourceTemplate .InOrg (defOrg ).WithID (uuid .New ()),actions :AllActions ()},
1217
+ {resource :ResourceTemplate .InOrg (defOrg ).WithID (uuid .New ()),actions :AllActions ()},
1218
+ {resource :ResourceTemplate .InOrg (defOrg ),actions :AllActions ()},
1219
+
1220
+ // Group
1221
+ {resource :ResourceGroup .InOrg (defOrg ).WithID (gid ),actions : []policy.Action {policy .ActionRead }},
1222
+ },
1223
+ ),
1224
+
1225
+ // Not allowed:
1226
+ cases (func (c authTestCase )authTestCase {
1227
+ c .allow = false
1228
+ return c
1229
+ },
1230
+ []authTestCase {
1231
+ // Has the scope and allow list, but not the permission
1232
+ {resource :ResourceUser .WithOwner (user .ID ),actions : []policy.Action {policy .ActionRead }},
1233
+
1234
+ // `wid` matches on the uuid, but not the type
1235
+ {resource :ResourceGroup .WithID (wid ),actions : []policy.Action {policy .ActionRead }},
1236
+
1237
+ // no empty id for the create action
1238
+ {resource :ResourceGroup .InOrg (defOrg ),actions : []policy.Action {policy .ActionCreate }},
1239
+ },
1240
+ ),
1241
+ )
1242
+
1243
+ // Wildcard type
1244
+ user = Subject {
1245
+ ID :"me" ,
1246
+ Roles :Roles {
1247
+ must (RoleByName (RoleOwner ())),
1248
+ },
1249
+ Scope :Scope {
1250
+ Role :Role {
1251
+ Identifier :RoleIdentifier {
1252
+ Name :"WildcardType" ,
1253
+ OrganizationID :defOrg ,
1254
+ },
1255
+ DisplayName :"WildcardType" ,
1256
+ // Allow almost everything
1257
+ Site :allPermsExcept (ResourceUser ),
1258
+ },
1259
+ AllowIDList : []AllowListElement {
1260
+ {Type :policy .WildcardSymbol ,ID :wid .String ()},
1261
+ },
1262
+ },
1263
+ }
1264
+
1265
+ testAuthorize (t ,"WildcardType" ,user ,
1266
+ // Allowed:
1267
+ cases (func (c authTestCase )authTestCase {
1268
+ c .allow = true
1269
+ return c
1270
+ },
1271
+ []authTestCase {
1272
+ // anything with the id is ok
1273
+ {resource :ResourceWorkspace .InOrg (defOrg ).WithOwner (user .ID ).WithID (wid ),actions : []policy.Action {policy .ActionRead }},
1274
+ {resource :ResourceGroup .InOrg (defOrg ).WithID (wid ),actions : []policy.Action {policy .ActionRead }},
1275
+ {resource :ResourceTemplate .InOrg (defOrg ).WithID (wid ),actions : []policy.Action {policy .ActionRead }},
1276
+ },
1277
+ ),
1278
+
1279
+ // Not allowed:
1280
+ cases (func (c authTestCase )authTestCase {
1281
+ c .allow = false
1282
+ return c
1283
+ },
1284
+ []authTestCase {
1285
+ // Anything without the id is not allowed
1286
+ {resource :ResourceWorkspace .InOrg (defOrg ).WithOwner (user .ID ),actions : []policy.Action {policy .ActionCreate }},
1287
+ {resource :ResourceWorkspace .InOrg (defOrg ).WithOwner (user .ID ).WithID (uuid .New ()),actions : []policy.Action {policy .ActionRead }},
1288
+ },
1289
+ ),
1290
+ )
1291
+ }
1292
+
1166
1293
// cases applies a given function to all test cases. This makes generalities easier to create.
1167
1294
func cases (opt func (c authTestCase )authTestCase ,cases []authTestCase ) []authTestCase {
1168
1295
if opt == nil {