Udostępnij za pośrednictwem


Instrukcja ograniczenia

Dotyczy: ✅Microsoft Fabric

Instrukcja restrict ogranicza zestaw jednostek tabeli/widoku, które są widoczne dla instrukcji zapytań, które są zgodne z nią. Na przykład w bazie danych, która zawiera dwie tabele (A, B), aplikacja może uniemożliwić pozostałej części zapytania uzyskiwanie dostępu B i tylko "zobacz" ograniczoną formę tabeli A przy użyciu widoku.

Głównym scenariuszem instrukcji ograniczeń jest aplikacja warstwy środkowej, która akceptuje zapytania od użytkowników i chce zastosować mechanizm zabezpieczeń na poziomie wiersza względem tych zapytań. Aplikacja warstwy środkowej może prefiksować zapytanie użytkownika za pomocą modelu logicznego, zestaw instrukcji let do definiowania widoków, które ograniczają dostęp użytkownika do danych, na przykład ( T | where UserId == "..."). Podczas dodawania ostatniej instrukcji ogranicza ona dostęp użytkownika tylko do modelu logicznego.

Uwaga

Instrukcję restrict można użyć do ograniczenia dostępu do jednostek w innej bazie danych lub klastrze (symbole wieloznaczne nie są obsługiwane w nazwach klastrów).

Składnia

restrict access to ( EntitySpecifiers)

Dowiedz się więcej na temat konwencji składni.

Parametry

Nazwisko Type Wymagania opis
EntitySpecifiers string ✔️ Co najmniej jeden specyfikator jednostki rozdzielanej przecinkami. Możliwe wartości to:
- Identyfikator zdefiniowany przez instrukcję let jako widok tabelaryczny
- Odwołanie do tabeli lub funkcji, podobne do jednego używanego przez instrukcję union
- Wzorzec zdefiniowany przez deklarację wzorca

Uwaga

  • Wszystkie tabele, widoki tabelaryczne lub wzorce, które nie są określone przez instrukcję restrict, stają się "niewidoczne" dla pozostałej części zapytania.
  • Instrukcje let, set i tabelaryczne są nawleczone razem/oddzielone średnikiem, w przeciwnym razie nie są traktowane jako część tego samego zapytania.

Przykłady

W przykładach w tej sekcji pokazano, jak używać składni, aby ułatwić rozpoczęcie pracy.

Przykłady w tym artykule używają publicznie dostępnych tabel w pomocy klastra, takich jak tabela StormEvents w bazie danych przykładów.

Przykłady w tym artykule używają publicznie dostępnych tabel, takich jak tabela StormEvents w przykładowej analizie pogody przykładowych danych.

Instrukcja let

W przykładzie użyto instrukcji let wyświetlanej przed instrukcją restrict.

// Limit access to 'Test' let statement only
let Test = () { print x=1 };
restrict access to (Test);

Tabele lub funkcje

W przykładzie użyto odwołań do tabel lub funkcji zdefiniowanych w metadanych bazy danych.

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

Wzorce

W przykładzie użyto wzorców wieloznacznych, które mogą odpowiadać wielokrotnościom instrukcji let lub tabel/funkcji.

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'

Uniemożliwianie użytkownikowi wykonywania zapytań dotyczących innych danych użytkownika

W przykładzie pokazano, jak aplikacja warstwy środkowej może poprzedzać zapytanie użytkownika modelem logicznym, który uniemożliwia użytkownikowi wykonywanie zapytań o dane innych użytkowników.

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