Share via


Restrict deyimi

restrict deyimi, bunu izleyen sorgu deyimleri tarafından görülebilen tablo/görünüm varlıkları kümesini sınırlar. Örneğin, iki tablo içeren bir veritabanında (A, B), uygulama sorgunun geri kalanının erişmesini B engelleyebilir ve bir görünüm kullanarak yalnızca sınırlı bir tablo A biçimine "bakın".

Restrict deyiminin ana senaryosu, kullanıcılardan gelen sorguları kabul eden ve bu sorgular üzerinde satır düzeyi güvenlik mekanizması uygulamak isteyen orta katman uygulamalarına yöneliktir. Orta katman uygulaması, kullanıcının sorgusuna bir mantıksal model, örneğin ( T | where UserId == "...") kullanıcının verilere erişimini kısıtlayan görünümleri tanımlayan let deyimleri kümesi ön ekini ekleyebilir. Eklenen son deyim olarak, kullanıcının yalnızca mantıksal modele erişimini kısıtlar.

Not

Restrict deyimi, başka bir veritabanı veya kümedeki varlıklara erişimi kısıtlamak için kullanılabilir (küme adlarında joker karakterler desteklenmez).

Syntax

restrictaccessto(EntitySpecifiers)

Söz dizimi kuralları hakkında daha fazla bilgi edinin.

Parametreler

Ad Tür Gerekli Açıklama
EntitySpecifiers string ✔️ Bir veya daha fazla virgülle ayrılmış varlık tanımlayıcısı. Olası değerler şunlardır:
- Let deyimi tarafından tablo görünümü olarak tanımlanan tanımlayıcı
- Birleşim deyimi tarafından kullanılana benzer bir tablo veya işlev başvurusu
- Desen bildirimi tarafından tanımlanan desen

Not

  • Restrict deyimi tarafından belirtilmeyen tüm tablolar, tablo görünümleri veya desenler sorgunun geri kalanında "görünmez" duruma gelir.
  • Let, set ve tabular deyimleri birlikte/noktalı virgülle ayrılır, aksi takdirde aynı sorgunun parçası olarak kabul edilmezler.

Örnekler

Let deyimi

Aşağıdaki örnek, deyiminden önce restrict görünen bir let deyimini kullanır.

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

Tablolar veya işlevler

Aşağıdaki örnek, veritabanı meta verilerinde tanımlanan tablolara veya işlevlere başvurular kullanır.

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

Desenler

Aşağıdaki örnek, let deyimlerinin veya tabloların/işlevlerin katlarını eşleştirebilen joker karakter desenlerini kullanır.

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'

Kullanıcının diğer kullanıcı verilerini sorgulamasını engelleme

Aşağıdaki örnek, bir orta katman uygulamasının kullanıcının sorgusunu, kullanıcının başka bir kullanıcının verilerini sorgulamasını engelleyen bir mantıksal modelle nasıl ön ekleyebileceğinizi gösterir.

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

Bu özellik Azure İzleyici'de desteklenmez