Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: seperate casbin meta and data storage permissions #6356

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename endpoint actions to include meta and data
  • Loading branch information
moogacs committed Nov 18, 2024
commit 69cd9d50795c6a2312f58488a307c192f6dc27da
64 changes: 32 additions & 32 deletions adapters/handlers/rest/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 34 additions & 34 deletions entities/models/permission.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions openapi-specs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 61,25 @@
"read_roles",
"manage_cluster",

"create_collections",
"read_collections",
"update_collections",
"delete_collections",
"create_meta_collections",
"read_meta_collections",
"update_meta_collections",
"delete_meta_collections",

"create_tenants",
"read_tenants",
"update_tenants",
"delete_tenants",
"create_meta_tenants",
"read_meta_tenants",
"update_meta_tenants",
"delete_meta_tenants",

"create_objects_collection",
"read_objects_collection",
"update_objects_collection",
"delete_objects_collection",
"create_data_collection_objects",
"read_data_collection_objects",
"update_data_collection_objects",
"delete_data_collection_objects",

"create_objects_tenant",
"read_objects_tenant",
"update_objects_tenant",
"delete_objects_tenant"
"create_data_tenant_objects",
"read_data_tenant_objects",
"update_data_tenant_objects",
"delete_data_tenant_objects"
]
}
},
Expand Down
48 changes: 12 additions & 36 deletions usecases/auth/authorization/conv/casbin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 20,18 @@ import (
)

const (
users = "users"
roles = "roles"
cluster = "cluster"
collections = "collections"
collectionsDomain = "meta_collections"
tenants = "tenants"
tenantsDomain = "meta_tenants"
objectsCollection = "objects_collection"
objectsCollectionDomain = "data_collection_objects"
objectsTenant = "objects_tenant"
objectsTenantDomain = "data_tenant_objects"
users = "users"
roles = "roles"
cluster = "cluster"
collections = "meta_collections"
tenants = "meta_tenants"
objectsCollection = "data_collection_objects"
objectsTenant = "data_tenant_objects"

// rolePrefix = "r_"
// userPrefix = "u_"
)

var (
domains = map[string]string{
"roles": "roles",
"cluster": "cluster",
"collections": "meta_collections",
"tenants": "meta_tenants",
"objects_collection": "data_collection_objects",
"objects_tenant": "data_tenant_objects",
}

permissionsFromDomains = map[string]string{
"roles": "roles",
"cluster": "cluster",
"meta_collections": "collections",
"meta_tenants": "tenants",
"data_collection_objects": "objects_collection",
"data_tenant_objects": "objects_tenant",
}
)

func newPolicy(policy []string) *authorization.Policy {
return &authorization.Policy{
Resource: fromCasbinResource(policy[1]),
Expand Down Expand Up @@ -197,14 173,14 @@ func policy(permission *models.Permission) (*authorization.Policy, error) {
return &authorization.Policy{
Resource: resource,
Verb: verb,
Domain: domains[domain],
Domain: domain,
}, nil
}

func permission(policy []string) *models.Permission {
mapped := newPolicy(policy)

action := fmt.Sprintf("%s_%s", authorization.Actions[mapped.Verb], permissionsFromDomains[mapped.Domain])
action := fmt.Sprintf("%s_%s", authorization.Actions[mapped.Verb], mapped.Domain)
action = strings.ReplaceAll(action, "_*", "")
permission := &models.Permission{
Action: &action,
Expand All @@ -214,12 190,12 @@ func permission(policy []string) *models.Permission {
all := "*"

switch mapped.Domain {
case collectionsDomain:
case collections:
permission.Collection = &splits[2]
case tenantsDomain:
case tenants:
permission.Collection = &splits[2]
permission.Tenant = &splits[4]
case objectsCollectionDomain, objectsTenantDomain:
case objectsCollection, objectsTenant:
permission.Collection = &splits[2]
permission.Tenant = &splits[4]
permission.Object = &splits[6]
Expand Down
32 changes: 16 additions & 16 deletions usecases/auth/authorization/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 47,25 @@ const (
ManageUsers = "manage_users"
ManageCluster = "manage_cluster"

CreateCollections = "create_collections"
ReadCollections = "read_collections"
UpdateCollections = "update_collections"
DeleteCollections = "delete_collections"
CreateCollections = "create_meta_collections"
ReadCollections = "read_meta_collections"
UpdateCollections = "update_meta_collections"
DeleteCollections = "delete_meta_collections"

CreateTenants = "create_tenants"
ReadTenants = "read_tenants"
UpdateTenants = "update_tenants"
DeleteTenants = "delete_tenants"
CreateTenants = "create_meta_tenants"
ReadTenants = "read_meta_tenants"
UpdateTenants = "update_meta_tenants"
DeleteTenants = "delete_meta_tenants"

CreateObjectsCollection = "create_objects_collection"
ReadObjectsCollection = "read_objects_collection"
UpdateObjectsCollection = "update_objects_collection"
DeleteObjectsCollection = "delete_objects_collection"
CreateObjectsCollection = "create_data_collection_objects"
ReadObjectsCollection = "read_data_collection_objects"
UpdateObjectsCollection = "update_data_collection_objects"
DeleteObjectsCollection = "delete_data_collection_objects"

CreateObjectsTenant = "create_objects_tenant"
ReadObjectsTenant = "read_objects_tenant"
UpdateObjectsTenant = "update_objects_tenant"
DeleteObjectsTenant = "delete_objects_tenant"
CreateObjectsTenant = "create_data_tenant_objects"
ReadObjectsTenant = "read_data_tenant_objects"
UpdateObjectsTenant = "update_data_tenant_objects"
DeleteObjectsTenant = "delete_data_tenant_objects"
)

var (
Expand Down