Restrict 문
restrict 문은 테이블/뷰 엔터티 집합을 제한하며 이 엔터티 집합을 따르는 쿼리 문에 표시됩니다. 예를 들어 두 개의 테이블이A
B
포함된 데이터베이스에서 애플리케이션은 쿼리의 나머지 부분에 액세스하지 B
못하게 하고 보기를 사용하여 제한된 형식의 테이블 A
만 "볼"수 있습니다.
restrict 문의 주요 시나리오는 사용자의 쿼리를 수락하고 해당 쿼리에 대해 행 수준 보안 메커니즘을 적용하려는 중간 계층 애플리케이션을 위한 것입니다.
중간 계층 애플리케이션은 사용자의 쿼리 접두사를 논리 모델접두사로 사용할 수 있습니다. let 문 집합은 데이터에 대한 사용자의 액세스를 제한하는 뷰를 정의합니다(예: T | where UserId == "..."
). 마지막 문이 추가될 때 논리 모델에 대한 사용자 액세스만 제한합니다.
참고 항목
restrict 문을 사용하여 다른 데이터베이스 또는 클러스터의 엔터티에 대한 액세스를 제한할 수 있습니다(와일드카드는 클러스터 이름에서 지원되지 않음).
구문
restrict
access
to
(
EntitySpecifiers)
구문 규칙에 대해 자세히 알아봅니다.
매개 변수
이름 | Type | 필수 | 설명 |
---|---|---|---|
EntitySpecifiers | string |
✔️ | 하나 이상의 쉼표로 구분된 엔터티 지정자입니다. 가능한 값은 다음과 같습니다. - let 문에 의해 테이블 형식 보기로 정의된 식별자 - union 문에서 사용하는 것과 유사한 테이블 또는 함수 참조 - 패턴 선언으로 정의된 패턴 |
참고 항목
- restrict 문에 의해 지정되지 않은 모든 테이블, 테이블 형식 뷰 또는 패턴은 쿼리의 나머지 부분에 "보이지 않습니다".
- 테이블 형식 문은 세미콜론으로 함께 연결/구분됩니다. 그렇지 않으면 동일한 쿼리의 일부로 간주되지 않습니다.
예제
이 섹션의 예제에서는 구문을 사용하여 시작하는 방법을 보여 줍니다.
이 문서의 예제에서는 샘플 데이터베이스의
StormEvents
테이블과 같은 도움말 클러스터공개적으로 사용할 수 있는 테이블을 사용합니다.
Let 문
이 예제에서는 문 앞에 나타나는 restrict
사용합니다.
// Limit access to 'Test' let statement only
let Test = () { print x=1 };
restrict access to (Test);
테이블 또는 함수
이 예제에서는 데이터베이스 메타데이터에 정의된
// Assuming the database that the query uses has table Table1 and Func1 defined in the metadata,
// and other database 'DB2' has Table2 defined in the metadata
restrict access to (database().Table1, database().Func1, database('DB2').Table2);
패턴
이 예제에서는 let 문 또는 테이블/함수의 배수와 일치시킬 수 있는 와일드카드 패턴을 사용합니다.
let Test1 = () { print x=1 };
let Test2 = () { print y=1 };
restrict access to (*);
// Now access is restricted to Test1, Test2 and no tables/functions are accessible.
// Assuming the database that the query uses has table Table1 and Func1 defined in the metadata.
// Assuming that database 'DB2' has table Table2 and Func2 defined in the metadata
restrict access to (database().*);
// Now access is restricted to all tables/functions of the current database ('DB2' is not accessible).
// Assuming the database that the query uses has table Table1 and Func1 defined in the metadata.
// Assuming that database 'DB2' has table Table2 and Func2 defined in the metadata
restrict access to (database('DB2').*);
// Now access is restricted to all tables/functions of the database 'DB2'
사용자가 다른 사용자 데이터를 쿼리하지 못하도록 방지
이 예제에서는 중간 계층 애플리케이션이 사용자가 다른 사용자의 데이터를 쿼리하지 못하도록 하는 논리 모델을 사용하여 사용자의 쿼리 앞에 추가할 수 있는 방법을 보여 줍니다.
// Assume the database has a single table, UserData,
// with a column called UserID and other columns that hold
// per-user private information.
//
// The middle-tier application generates the following statements.
// Note that "username@domain.com" is something the middle-tier application
// derives per-user as it authenticates the user.
let RestrictedData = view () { Data | where UserID == "username@domain.com" };
restrict access to (RestrictedData);
// The rest of the query is something that the user types.
// This part can only reference RestrictedData; attempting to reference Data
// will fail.
RestrictedData | summarize MonthlySalary=sum(Salary) by Year, Month
// Restricting access to Table1 in the current database (database() called without parameters)
restrict access to (database().Table1);
Table1 | count
// Restricting access to Table1 in the current database and Table2 in database 'DB2'
restrict access to (database().Table1, database('DB2').Table2);
union
(Table1),
(database('DB2').Table2))
| count
// Restricting access to Test statement only
let Test = () { range x from 1 to 10 step 1 };
restrict access to (Test);
Test
// Assume that there is a table called Table1, Table2 in the database
let View1 = view () { Table1 | project Column1 };
let View2 = view () { Table2 | project Column1, Column2 };
restrict access to (View1, View2);
// When those statements appear before the command - the next works
let View1 = view () { Table1 | project Column1 };
let View2 = view () { Table2 | project Column1, Column2 };
restrict access to (View1, View2);
View1 | count
// When those statements appear before the command - the next access is not allowed
let View1 = view () { Table1 | project Column1 };
let View2 = view () { Table2 | project Column1, Column2 };
restrict access to (View1, View2);
Table1 | count