restrict ステートメント

restrict ステートメントは、その後に続くクエリ ステートメントに表示されるテーブル/ビュー エンティティのセットを制限します。 たとえば、2 つのテーブル (AB) を含むデータベースでは、アプリケーションは、ビューを使用することにより、クエリの残りの部分についての B へのアクセスを防ぐと同時に、限られた形式のテーブル A のみが「参照」できます。

restrict ステートメントの主なシナリオは、ユーザーからのクエリを受け入れ、それらのクエリに対して行レベルのセキュリティ メカニズムを適用する中間層アプリケーション向けです。 中間層アプリケーションでは、例として (T | where UserId == "...") など、ユーザーによるデータへのアクセスを制限するビューを定義する Let ステートメントのセットである 論理モデル を使用してユーザーのクエリにプレフィックスとして付けることができます。 最後に追加されたステートメントとして、ユーザーによるアクセスを論理モデルのみに制限します。

Note

restrict ステートメントを使用して、別のデータベースまたはクラスター内のエンティティへのアクセスを制限することができます (クラスター名ではワイルドカードはサポートされていません)。

構文

restrictaccessto(EntitySpecifiers)

構文規則について詳しく知る。

パラメーター

名前 必須 説明
EntitySpecifiers string ✔️ 1 つ以上のコンマ区切りエンティティ指定子。 次の値を指定できます。
- let ステートメントによって表形式ビューとして定義された識別子
- union ステートメントで使用される参照と同様のテーブルまたは関数参照
- パターン宣言によって定義されたパターン

注意

  • restrict ステートメントで指定されていないすべてのテーブル、表形式ビュー、またはパターンは、クエリの残りの部分では "非表示" になります。
  • Let、set、および tabular ステートメントはセミコロンで区切られ、それ以外の場合は同じクエリの一部とは見なされません。

let ステートメント

次の例では、before restrict ステートメントに出現する let ステートメントを使用します。

// 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

この機能は、Azure Monitor ではサポートされていません。