본문으로 건너뛰기

도메인이 포함된 RBAC

도메인이 포함된 역할 정의​

Casbin에서는 역할을 **도메인 범위(domain-scoped)**로 지정할 수 있습니다. 즉, 동일한 사용자가 다른 도메인(테넌트)에서 다른 역할을 가질 수 있습니다. 이는 한 사용자가 여러 테넌트에서 작업하는 멀티 테넌트 및 클라우드 시스템에 적합합니다.

세 개의 요소로 구성된 역할 정의를 사용하며, 세 번째 요소는 도메인입니다:

[role_definition]
g = _, _, _

세 번째 필드는 도메인입니다. 정책 예시:

p, admin, tenant1, data1, read
p, admin, tenant2, data2, read

g, alice, admin, tenant1
g, alice, user, tenant2

따라서: tenant1의 admin은 data1을 읽을 수 있습니다. Alice는 tenant1에서 admin이고 tenant2에서 user입니다. 그녀는 data1을 읽을 수 있지만 data2는 읽을 수 없습니다(tenant2의 admin만 data2를 읽을 수 있음).

Matcher: g에 도메인을 포함시키고 일치하도록 요구합니다:

[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act

사용자 정의 도메인 토큰 이름​

관례적으로 도메인은 dom으로 명명되지만, 요청 및 정책 정의에서 임의의 이름(tenant, workspace 등)을 사용할 수 있습니다:

[request_definition]
r = sub, tenant, obj, act

[policy_definition]
p = sub, tenant, obj, act

[role_definition]
g = _, _, _

[matchers]
m = g(r.sub, p.sub, r.tenant) && r.tenant == p.tenant && r.obj == p.obj && r.act == p.act

도메인에 대한 패턴 매칭(예: keyMatch)을 사용하면, Casbin은 요청과 정책 모두에서 도메인이 인덱스 1에 있는 한 모델에서 도메인 토큰을 추론합니다:

[matchers]
m = g(r.sub, p.sub, r.tenant) && keyMatch(r.tenant, p.tenant) && r.obj == p.obj && r.act == p.act

For domain APIs (e.g. GetAllUsersByDomain()) with a custom domain token name or position, set the index after creating the enforcer. Full example: rbac_with_domains_model.conf.

토큰 이름 및 위치

도메인은 일반적으로 dom으로 명명되고 두 번째 위치(sub, dom, obj, act)에 배치됩니다. Go Casbin에서는 다른 이름이나 위치를 사용할 수 있으며, 이 경우 초기화 후 e.SetFieldIndex("p", constant.DomainIndex, index)를 호출하여 GetAllUsersByDomain() 같은 API가 올바르게 작동하도록 합니다.

# Using `domain` instead of `dom`
[policy_definition]
p = sub, obj, act, domain
e.SetFieldIndex("p", constant.DomainIndex, 3) // index starts from 0
users := e.GetAllUsersByDomain("domain1") // without SetFieldIndex, this will raise an error

중첩 단위(Nested Units)​

도메인이 트리 구조를 형성하는 경우(예: 회사가 부서와 팀을 포함함) 그리고 특정 단위에 부여된 역할이 하위 트리 전체에 적용되어야 하는 경우, 중첩 조직(Nested Organizations) 문서를 참조하세요.

Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.