Condividi tramite


Istruzione restrict

L'istruzione restrict limita il set di entità di tabella/vista visibili alle istruzioni di query che lo seguono. Ad esempio, in un database che include due tabelle (A, B), l'applicazione può impedire al resto della query di accedere B e solo "vedere" una forma limitata di tabella A usando una vista.

Lo scenario principale dell'istruzione restrict è per le applicazioni di livello intermedio che accettano query dagli utenti e vogliono applicare un meccanismo di sicurezza a livello di riga su tali query. L'applicazione di livello intermedio può anteporre alla query dell'utente un modello logico, un set di istruzioni let che definiscono visualizzazioni che limitano l'accesso dell'utente ai dati, ad esempio ( T | where UserId == "..."). Quando viene aggiunta l'ultima istruzione, limita l'accesso dell'utente solo al modello logico.

Nota

L'istruzione restrict può essere usata per limitare l'accesso alle entità in un altro database o cluster (i caratteri jolly non sono supportati nei nomi del cluster).

Sintassi

restrictaccess to (EntitySpecifiers)

Altre informazioni sulle convenzioni di sintassi.

Parametri

Nome Digita Obbligatorio Descrizione
EntitySpecifiers string ✔️ Uno o più identificatori di entità delimitati da virgole. I valori possibili sono:
- Identificatore definito da un'istruzione let come visualizzazione tabulare
- Riferimento a una tabella o a una funzione, simile a quella usata da un'istruzione union
- Modello definito da una dichiarazione di criterio

Nota

  • Tutte le tabelle, le viste tabulari o i modelli non specificati dall'istruzione restrict diventano "invisibili" al resto della query.
  • Le istruzioni let, set e tabulari vengono unite/separate da un punto e virgola, altrimenti non verranno considerate parte della stessa query.

Esempi

Istruzione let

Nell'esempio seguente viene usata un'istruzione let che viene visualizzata prima restrict dell'istruzione .

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

Tabelle o funzioni

Nell'esempio seguente vengono utilizzati riferimenti a tabelle o funzioni definite nei metadati del database.

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

Criteri

Nell'esempio seguente vengono usati modelli con caratteri jolly che possono corrispondere a più istruzioni let o tabelle/funzioni.

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'

Impedire all'utente di eseguire query su altri dati utente

Nell'esempio seguente viene illustrato come un'applicazione di livello intermedio possa anteporre una query di un utente con un modello logico che impedisce all'utente di eseguire query sui dati di qualsiasi altro utente.

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

Questa funzionalità non è supportata in Monitoraggio di Azure