Pernyataan restrict

Pernyataan Restrict membatasi kumpulan entitas tabel/tampilan yang terlihat oleh pernyataan kueri yang mengikutinya. Misalnya, dalam database yang mencakup dua tabel (A,B), aplikasi dapat mencegah sisa kueri mengakses dan hanya "melihat" bentuk tabel B terbatas dengan A menggunakan tampilan.

Skenario utama pernyataan batas adalah untuk aplikasi tingkat menengah yang menerima kueri dari pengguna dan ingin menerapkan mekanisme keamanan tingkat baris atas kueri tersebut. Aplikasi tingkat menengah dapat mengawali kueri pengguna dengan model logis, satu set pernyataan let yang mendefinisikan tampilan yang membatasi akses pengguna ke data, misalnya ( T | where UserId == "..."). Sebagai pernyataan terakhir yang ditambahkan, ini membatasi akses pengguna ke model logis saja.

Catatan

Pernyataan batas dapat digunakan untuk membatasi akses ke entitas di database atau kluster lain (wildcard tidak didukung dalam nama kluster).

Sintaks

restrictaccessto(EntitySpecifiers)

Pelajari selengkapnya tentang konvensi sintaksis.

Parameter

Nama Jenis Diperlukan Deskripsi
EntitySpecifiers string ✔️ Satu atau beberapa penentu entitas yang dipisahkan koma. Nilai yang mungkin adalah:
- Pengidentifikasi yang didefinisikan oleh pernyataan let sebagai tampilan tabular
- Referensi tabel atau fungsi, mirip dengan yang digunakan oleh pernyataan serikat
- Pola yang ditentukan oleh deklarasi pola

Catatan

  • Semua tabel, tampilan tabular, atau pola yang tidak ditentukan oleh pernyataan batasan menjadi "tidak terlihat" ke kueri lainnya.
  • Pernyataan biarkan, atur, dan tabular digabungkan/dipisahkan oleh titik koma, jika tidak, pernyataan tersebut tidak akan dianggap sebagai bagian dari kueri yang sama.

Contoh

Pernyataan let

Contoh berikut menggunakan pernyataan let yang muncul sebelum restrict pernyataan .

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

Tabel atau fungsi

Contoh berikut menggunakan referensi ke tabel atau fungsi yang ditentukan dalam metadata 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);

Pola

Contoh berikut menggunakan pola kartubebas yang dapat mencocokkan kelipatan pernyataan let atau tabel/fungsi.

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'

Mencegah pengguna mengkueri data pengguna lain

Contoh berikut menunjukkan cara aplikasi tingkat menengah dapat menyetujui kueri pengguna dengan model logis yang mencegah pengguna mengkueri data pengguna lain.

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

Kapabilitas ini tidak didukung di Azure Monitor