You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/synapse-analytics/sql/develop-storage-files-storage-access-control.md
+61-30Lines changed: 61 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ This article describes the types of credentials you can use and how credential l
21
21
22
22
## Supported storage authorization types
23
23
24
-
A user that has logged into a SQL on-demand resource must be authorized to access and query the files in Azure Storage. Three authorization types are supported:
24
+
A user that has logged into a SQL on-demand resource must be authorized to access and query the files in Azure Storage if the files are not publicly available. Three authorization types are supported:
@@ -42,6 +42,8 @@ You can get an SAS token by navigating to the **Azure portal -> Storage Account
42
42
>
43
43
> SAS token: ?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-04-18T20:42:12Z&st=2019-04-18T12:42:12Z&spr=https&sig=lQHczNvrk1KoYLCpFdSsMANd0ef9BrIPBNJ3VYEIq78%3D
44
44
45
+
You need to create database-scoped or server-scoped credential to enable access using SAS token.
46
+
45
47
### [User Identity](#tab/user-identity)
46
48
47
49
**User Identity**, also known as "pass-through", is an authorization type where the identity of the Azure AD user that logged into
@@ -94,7 +96,7 @@ Before accessing the data, the Azure Storage administrator must grant permission
94
96
95
97
### [Anonymous access](#tab/public-access)
96
98
97
-
You can access publicly available files placed on Azure storage accounts that allow anonymous access.
99
+
You can access publicly available files placed on Azure storage accounts that [allow anonymous access](/azure/storage/blobs/storage-manage-access-to-resources.md).
98
100
99
101
---
100
102
@@ -124,30 +126,14 @@ To query a file located in Azure Storage, your SQL on-demand end point needs a c
124
126
- Server-level CREDENTIAL is used for ad-hoc queries executed using `OPENROWSET` function. Credential name must match the storage URL.
125
127
- DATABASE SCOPED CREDENTIAL is used for external tables. External table references `DATA SOURCE` with the credential that should be used to access storage.
126
128
127
-
A credential is added by running [CREATE CREDENTIAL](/sql/t-sql/statements/create-credential-transact-sql?toc=/azure/synapse-analytics/toc.json&bc=/azure/synapse-analytics/breadcrumb/toc.json&view=azure-sqldw-latest). You'll need to provide a CREDENTIAL NAME argument. It must match either part of the path or the whole path to data in Storage (see below).
128
-
129
-
> [!NOTE]
130
-
> The FOR CRYPTOGRAPHIC PROVIDER argument is not supported.
131
-
132
-
For all supported authorization types, credentials can point to an account or a container.
133
-
134
-
Server-level CREDENTIAL name must match the full path to the storage account (and optionally container) in the following format: `<prefix>://<storage_account_path>/<storage_path>`
| Azure Data Lake Storage Gen1 | https | <storage_account>.azuredatalakestore.net/webhdfs/v1 |
140
-
| Azure Data Lake Storage Gen2 | https | <storage_account>.dfs.core.windows.net |
141
-
142
-
> [!NOTE]
143
-
> There is special server-level CREDENTIAL `UserIdentity` that [forces Azure AD pass-through](#force-azure-ad-pass-through).
144
-
145
-
Optionally, to allow a user to create or drop a credential, admin can GRANT/DENY ALTER ANY CREDENTIAL permission to a user:
129
+
To allow a user to create or drop a credential, admin can GRANT/DENY ALTER ANY CREDENTIAL permission to a user:
146
130
147
131
```sql
148
132
GRANT ALTER ANY CREDENTIAL TO [user_name];
149
133
```
150
134
135
+
Database users who access external storage must have permission to use credentials.
136
+
151
137
### Grant permissions to use credential
152
138
153
139
To use the credential, a user must have `REFERENCES` permission on a specific credential. To grant a `REFERENCES` permission ON a storage_credential for a specific_user, execute:
@@ -164,11 +150,28 @@ GRANT REFERENCES ON CREDENTIAL::[UserIdentity] TO [public];
164
150
165
151
## Server-scoped credential
166
152
167
-
Server-scoped credentials are used when SQL login calls `OPENROWSET` function without `DATA_SOURCE` to read files on some storage account. The name of server-scoped credential **must** match the URL of Azure storage.
153
+
Server-scoped credentials are used when SQL login calls `OPENROWSET` function without `DATA_SOURCE` to read files on some storage account. The name of server-scoped credential **must** match the URL of Azure storage. A credential is added by running [CREATE CREDENTIAL](/sql/t-sql/statements/create-credential-transact-sql?toc=/azure/synapse-analytics/toc.json&bc=/azure/synapse-analytics/breadcrumb/toc.json&view=azure-sqldw-latest). You'll need to provide a CREDENTIAL NAME argument. It must match either part of the path or the whole path to data in Storage (see below).
154
+
155
+
> [!NOTE]
156
+
> The FOR CRYPTOGRAPHIC PROVIDER argument is not supported.
157
+
158
+
Server-level CREDENTIAL name must match the full path to the storage account (and optionally container) in the following format: `<prefix>://<storage_account_path>/<storage_path>`. Storage account paths are described in the following table:
The following script creates a server-level credential that can be used by `OPENROWSET` function to access any file on Azure storage using SAS token. Create this credential to enable SQL principal that executes `OPENROWSET` function to read files protected with SAS key on the Azure storage that matches URL in credential name.
173
+
The following script creates a server-level credential that can be used by `OPENROWSET` function to access any file on Azure storage using SAS token. Create this credential to enable SQL principal that executes `OPENROWSET` function to read files protected
174
+
with SAS key on the Azure storage that matches URL in credential name.
172
175
173
176
Exchange <*mystorageaccountname*> with your actual storage account name, and <*mystorageaccountcontainername*> with the actual container name:
174
177
@@ -181,7 +184,7 @@ GO
181
184
182
185
### [User Identity](#tab/user-identity)
183
186
184
-
The following script creates a server-level credential that enables user to impersonate using his Azure AD identity.
187
+
The following script creates a server-level credential that enables user to impersonate using Azure AD identity.
185
188
186
189
```sql
187
190
CREATE CREDENTIAL [UserIdentity]
@@ -215,6 +218,7 @@ GO
215
218
216
219
Database-scoped credentials are used when any principal calls `OPENROWSET` function with `DATA_SOURCE` or selects data from [external table](develop-tables-external-tables.md) that don't access public files. The database scoped credential doesn't need to match the name of storage account because it will be explicitly used in DATA SOURCE that defines the location of storage.
217
220
221
+
Database-scoped credentials enable access to Azure storage using the following authentication types:
Database user can read the content of the files from the data source using external table or [OPENROWSET](develop-openrowset.md) function that references the data source:
288
+
289
+
```sql
290
+
SELECT TOP 10*FROMdbo.userPublicData;
291
+
GO
292
+
SELECT TOP 10*FROM OPENROWSET(BULK 'parquet/user-data/*.parquet', DATA_SOURCE = [mysample], FORMAT=PARQUET) as rows;
293
+
GO
272
294
```
273
295
274
-
**External table that access data source using credential**
296
+
**Accessing data source using credential**
275
297
276
-
Modify the following script to create an external table that access Azure storage using SAS token, Azure AD identity of user, or managed identity of workspace.
298
+
Modify the following script to create an external table that accesses Azure storage using SAS token, Azure AD identity of user, or managed identity of workspace.
277
299
278
300
```sql
279
301
-- Create master key in databases with some password (one-off per database)
@@ -294,7 +316,7 @@ CREATE EXTERNAL FILE FORMAT [SynapseParquetFormat] WITH ( FORMAT_TYPE = PARQUET)
294
316
GO
295
317
296
318
CREATE EXTERNAL DATA SOURCE mysample
297
-
WITH ( LOCATION ='https://*******.blob.core.windows.net/samples',
319
+
WITH ( LOCATION ='https://*******.blob.core.windows.net/samples'
298
320
-- Uncomment one of these options depending on authentication method that you want to use to access data source:
Database user can read the content of the files from the data source using [external table](develop-tables-external-tables.md) or [OPENROWSET](develop-openrowset.md) function that references the data source:
332
+
333
+
```sql
334
+
SELECT TOP 10*FROMdbo.userdata;
335
+
GO
336
+
SELECT TOP 10*FROM OPENROWSET(BULK 'parquet/user-data/*.parquet', DATA_SOURCE = [mysample], FORMAT=PARQUET) as rows;
337
+
GO
338
+
```
339
+
309
340
## Next steps
310
341
311
342
The articles listed below will help you learn how query different folder types, file types, and create and use views:
0 commit comments