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
-[Authentication Behavior by Environment](#authentication-behavior-by-environment)
18
20
19
21
This guide demonstrates how to add an optional login and document level access control system to the sample. This system can be used to restrict access to indexed data to specific users based on what [Azure Active Directory (Azure AD) groups](https://learn.microsoft.com/azure/active-directory/fundamentals/how-to-manage-groups) they are a part of, or their [user object id](https://learn.microsoft.com/partner-center/find-ids-and-domain-names#find-the-user-object-id).
20
22
@@ -30,6 +32,16 @@ This guide demonstrates how to add an optional login and document level access c
30
32
31
33
Two Azure AD apps must be registered in order to make the optional login and document level access control system work correctly. One app is for the client UI. The client UI is implemented as a [single page application](https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-app-registration). The other app is for the API server. The API server uses a [confidential client](https://learn.microsoft.com/azure/active-directory/develop/msal-client-applications) to call the [Microsoft Graph API](https://learn.microsoft.com/graph/use-the-api).
32
34
35
+
### Automatic Setup
36
+
37
+
The easiest way to setup the two apps is to use the `azd` CLI. We've written scripts that will automatically create the two apps and configure them for use with the sample. To trigger the automatic setup, run the following commands:
38
+
39
+
1. Run `azd env set AZURE_USE_AUTHENTICATION true` to enable the login UI and App Service authentication.
40
+
1. Ensure access control is enabled on your search index. If your index doesn't exist yet, run prepdocs with `AZURE_USE_AUTHENTICATION` set to `true`. If your index already exists, run `./scrips/manageacl.ps1 --acl-action enable_acls`.
41
+
1. (Optional) To require access control when using the app, run `azd env set AZURE_ENFORCE_ACCESS_CONTROL true`.
42
+
1. Run `azd env set AZURE_AUTH_TENANT_ID <YOUR-TENANT-ID>` to set the tenant ID associated with authentication.
43
+
2. Run `azd up` to deploy the app.
44
+
33
45
### Manual Setup
34
46
35
47
The following instructions explain how to setup the two apps using the Azure Portal.
@@ -40,15 +52,15 @@ The following instructions explain how to setup the two apps using the Azure Por
40
52
* Select the Azure AD Service.
41
53
* In the left hand menu, select **Application Registrations**.
42
54
* Select **New Registration**.
43
-
* In the **Name** section, enter a meaningful application name. This name will be displayed to users of the app, for example `Azure Search OpenAI Demo API`.
55
+
* In the **Name** section, enter a meaningful application name. This name will be displayed to users of the app, for example `Azure Search OpenAI Chat API`.
44
56
* Under **Supported account types**, select **Accounts in this organizational directory only**.
45
57
* Select **Register** to create the application
46
58
* In the app's registration screen, find the **Application (client) ID**.
47
59
* Run the following `azd` command to save this ID: `azd env set AZURE_SERVER_APP_ID <Application (client) ID>`.
48
60
* Azure Active Directory (Azure AD) supports three types of credentials to authenticate an app using the [client credentials](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow): passwords (app secrets), certificates, and federated identity credentials. For a higher level of security, either [certificates](https://learn.microsoft.com/azure/active-directory/develop/howto-create-self-signed-certificate) or federated identity credentials are recommended. This sample currently uses an app secret for ease of provisioning.
49
61
* Select **Certificates & secrets** in the left hand menu.
50
62
* In the **Client secrets** section, select **New client secret**.
51
-
* Type a description, for example `Azure Search OpenAI Demo Key`.
63
+
* Type a description, for example `Azure Search OpenAI Chat Key`.
52
64
* Select one of the available key durations.
53
65
* The generated key value will be displayed after you select **Add**.
54
66
* Copy the generated key value and run the following `azd` command to save this ID: `azd env set AZURE_SERVER_APP_SECRET <generated key value>`.
@@ -64,10 +76,10 @@ The following instructions explain how to setup the two apps using the Azure Por
64
76
* Fill in the values as indicated:
65
77
* For **Scope name**, use **access_as_user**.
66
78
* For **Who can consent?**, select **Admins and users**.
67
-
* For **Admin consent display name**, type **Access Azure Search OpenAI Demo API**.
68
-
* For **Admin consent description**, type **Allows the app to access Azure Search OpenAI Demo API as the signed-in user.**.
69
-
* For **User consent display name**, type **Access Azure Search OpenAI Demo API**.
70
-
* For **User consent description**, type **Allow the app to access Azure Search OpenAI Demo API on your behalf**.
79
+
* For **Admin consent display name**, type **Access Azure Search OpenAI Chat API**.
80
+
* For **Admin consent description**, type **Allows the app to access Azure Search OpenAI Chat API as the signed-in user.**.
81
+
* For **User consent display name**, type **Access Azure Search OpenAI Chat API**.
82
+
* For **User consent description**, type **Allow the app to access Azure Search OpenAI Chat API on your behalf**.
71
83
* Leave **State** set to **Enabled**.
72
84
* Select **Add scope** at the bottom to save the scope.
73
85
* (Optional) Enable group claims. Include which Azure AD groups the user is part of as part of the login in the [optional claims](https://learn.microsoft.com/azure/active-directory/develop/optional-claims). The groups are used for [optional security filtering](https://learn.microsoft.com/azure/search/search-security-trimming-for-azure-search) in the search results.
@@ -83,7 +95,7 @@ The following instructions explain how to setup the two apps using the Azure Por
83
95
* Select the Azure AD Service.
84
96
* In the left hand menu, select **Application Registrations**.
85
97
* Select **New Registration**.
86
-
* In the **Name** section, enter a meaningful application name. This name will be displayed to users of the app, for example `Azure Search OpenAI Demo Web App`.
98
+
* In the **Name** section, enter a meaningful application name. This name will be displayed to users of the app, for example `Azure Search OpenAI Chat Web App`.
87
99
* Under **Supported account types**, select **Accounts in this organizational directory only**.
88
100
* Under `Redirect URI (optional)` section, select `Single-page application (SPA)` in the combo-box and enter the following redirect URI:
89
101
* If you are running the sample locally, use `http://localhost:50505/redirect`.
@@ -97,7 +109,7 @@ The following instructions explain how to setup the two apps using the Azure Por
97
109
* Select **Save**
98
110
* In the left hand menu, select **API permissions**. You will add permission to access the **access_as_user** API on the server app. This permission is required for the [On Behalf Of Flow](https://learn.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#protocol-diagram) to work.
99
111
* Select **Add a permission**, and then **My APIs**.
100
-
* In the list of applications, select your server application **Azure Search OpenAI Demo API**
112
+
* In the list of applications, select your server application **Azure Search OpenAI Chat API**
101
113
* Ensure **Delegated permissions** is selected.
102
114
* In the **Select permissions** section, select the **access_as_user** permission
103
115
* Select **Add permissions**.
@@ -166,8 +178,8 @@ Manually enable document level access control on a search index and manually set
166
178
Run `azd up` or use `azd env set` to manually set `AZURE_SEARCH_SERVICE` and `AZURE_SEARCH_INDEX` environment variables prior to running the script.
167
179
168
180
The script supports the following commands. Note that the syntax is the same regardless of whether [manageacl.ps1](./scripts/manageacl.ps1) or [manageacl.sh](./scripts/manageacl.sh) is used.
169
-
*`./scripts/manageacls.ps1 --enable-acls`: Creates the required `oids` (User ID) and `groups` (Group IDs) [security filter](https://learn.microsoft.com/azure/search/search-security-trimming-for-azure-search) fields for document level access control on your index. Does nothing if these fields already exist.
170
-
* Example usage: `./scripts/manageacls.ps1 --enable-acls`
181
+
*`./scripts/manageacls.ps1 --acl-action enable_acls`: Creates the required `oids` (User ID) and `groups` (Group IDs) [security filter](https://learn.microsoft.com/azure/search/search-security-trimming-for-azure-search) fields for document level access control on your index. Does nothing if these fields already exist.
182
+
* Example usage: `../scripts/manageacls.ps1 --acl-action enable_acls`
171
183
*`./scripts/manageacls.ps1 --document [name-of-pdf.pdf] --acl-type [oids or groups]--acl-action view`: Prints access control values associated with either User IDs or Group IDs for a specific document.
172
184
* Example to view all Group IDs from the Benefit_Options PDF: `./scripts/manageacls.ps1 --document Benefit_Options.pdf --acl-type oids --acl-action view`.
173
185
*`./scripts/manageacls.ps1 --document [name-of-pdf.pdf] --acl-type [oids or groups]--acl-action add --acl [ID of group or user]`: Adds an access control value associated with either User IDs or Group IDs for a specific document.
@@ -182,10 +194,26 @@ The script supports the following commands. Note that the syntax is the same reg
182
194
The following environment variables are used to setup the optional login and document level access control:
183
195
184
196
*`AZURE_USE_AUTHENTICATION`: Enables Azure AD based optional login and document level access control. Set to true before running `azd up`.
197
+
*`AZURE_ENFORCE_ACCESS_CONTROL`: Makes Azure AD based login and document level access control required instead of optional. There is no way to use the app without an authenticated account. Set to true before running `azd up`
185
198
*`AZURE_SERVER_APP_ID`: (Required) Application ID of the Azure AD app for the API server.
186
199
*`AZURE_SERVER_APP_SECRET`: [Client secret](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow) used by the API server to authenticate using the Azure AD API server app.
187
200
*`AZURE_CLIENT_APP_ID`: Application ID of the Azure AD app for the client UI.
188
-
*`AZURE_TENANT_ID`: [Tenant ID](https://learn.microsoft.com/azure/active-directory/fundamentals/how-to-find-tenant) associated with the Azure AD used for login and document level access control. This is set automatically by `azd up`.
201
+
*`AZURE_AUTH_TENANT_ID`: [Tenant ID](https://learn.microsoft.com/azure/active-directory/fundamentals/how-to-find-tenant) associated with the Azure AD used for login and document level access control. Defaults to `AZURE_TENANT_ID` if not defined.
189
202
*`AZURE_ADLS_GEN2_STORAGE_ACCOUNT`: (Optional) Name of existing [Data Lake Storage Gen2 storage account](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-introduction) for storing sample data with [access control lists](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-access-control). Only used with the optional Data Lake Storage Gen2 [setup](#azure-data-lake-storage-gen2-setup) and [prep docs](#azure-data-lake-storage-gen2-prep-docs) scripts.
190
203
*`AZURE_ADLS_GEN2_STORAGE_FILESYSTEM`: (Optional) Name of existing [Data Lake Storage Gen2 filesystem](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-introduction) for storing sample data with [access control lists](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-access-control). Only used with the optional Data Lake Storage Gen2 [setup](#azure-data-lake-storage-gen2-setup) and [prep docs](#azure-data-lake-storage-gen2-prep-docs) scripts.
191
204
*`AZURE_ADLS_GEN2_STORAGE_FILESYSTEM_PATH`: (Optional) Name of existing path in a [Data Lake Storage Gen2 filesystem](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-introduction) for storing sample data with [access control lists](https://learn.microsoft.com/azure/storage/blobs/data-lake-storage-access-control). Only used with the optional Data Lake Storage Gen2 [prep docs](#azure-data-lake-storage-gen2-prep-docs) script.
205
+
206
+
### Authentication behavior by environment
207
+
208
+
This application uses an in-memory token cache. User sessions are only available in memory while the application is running. When the application server is restarted, all users will need to log-in again.
209
+
210
+
The following table describes the impact of the `AZURE_USE_AUTHENTICATION` and `AZURE_ENFORCE_ACCESS_CONTROL` variables depending on the environment you are deploying the application in:
| True | False | App Services | Use integrated auth <br /> Login page blocks access to app <br /> User can opt-into access control in developer settings <br /> Allows unrestricted access to sources |
215
+
| True | True | App Services | Use integrated auth <br /> Login page blocks access to app <br /> User must use access control |
216
+
| True | False | Local or Codespaces | Do not use integrated auth <br /> Can use app without login <br /> User can opt-into access control in developer settings <br /> Allows unrestricted access to sources |
217
+
| True | True | Local or Codespaces | Do not use integrated auth <br /> Cannot use app without login <br /> Behavior is chat box is greyed out with default “Please login message” <br /> User must use login button to make chat box usable <br /> User must use access control when logged in |
218
+
| False | False | All | No login or access control |
# If you encounter a blocking error during a DefaultAzureCredential resolution, you can exclude the problematic credential by using a parameter (ex. exclude_shared_token_cache_credential=True)
0 commit comments