AISE02 – Consider authentication – Part 1
11 mins read

AISE02 – Consider authentication – Part 1

By default, access to Azure AI services resources is restricted by using subscription keys. Management of access to these keys is a primary consideration for security.


Mặc định, quyền truy cập vào các tài nguyên dịch vụ AI của Azure bị hạn chế bằng cách (is restricted by) sử dụng các khóa đăng ký (subscription keys). Quản lý quyền truy cập vào các khóa này là một yếu tố quan trọng hàng đầu đối với bảo mật (a primary consideration for security).



You should regenerate keys regularly to protect against the risk of keys being shared with or accessed by unauthorized users. You can regenerate keys using the Azure portal, or using the az cognitiveservices account keys regenerate Azure command-line interface (CLI) command.

Each AI service is provided with two keys, enabling you to regenerate keys without service interruption. To accomplish this:

  1. If you’re using both keys in production, change your code so that only one key is in use. For example, configure all production applications to use key 1.
  2. Regenerate key 2.
  3. Switch all production applications to use the newly regenerated key 2.
  4. Regenerate key 1
  5. Finally, update your production code to use the new key 1.

For example, to regenerate keys in the Azure portal, you can do the following:

  1. In the Azure portal, go to your resource’s Keys and Endpoint pane.
  2. Then select Regenerate Key1 or select Regenerate Key2, depending on which one you want to regenerate at the time.

Bạn nên tái tạo lại các khóa định kỳ (regenerate keys regularly) để bảo vệ khỏi (to protect against) nguy cơ khóa bị chia sẻ hoặc truy cập (the risk of keys being shared with or accessed by) bởi người dùng không được phép (unauthorized users). Bạn có thể tái tạo khóa bằng cách sử dụng Azure portal (the Azure portal), hoặc sử dụng lệnh az cognitiveservices account keys regenerate trong giao diện dòng lệnh Azure (CLI) (Azure command-line interface).

Mỗi dịch vụ AI được cung cấp với hai khóa (two keys), cho phép bạn tái tạo khóa mà không làm gián đoạn dịch vụ (without service interruption). Để thực hiện điều này:

  1. Nếu bạn đang sử dụng cả hai khóa trong môi trường sản xuất (using both keys in production), hãy thay đổi mã của bạn để chỉ sử dụng một khóa duy nhất (only one key is in use). Ví dụ, cấu hình tất cả các ứng dụng sản xuất (configure all production applications) để sử dụng khóa 1.
  2. Tái tạo khóa 2 (Regenerate key 2).
  3. Chuyển tất cả các ứng dụng sản xuất (Switch all production applications) sang sử dụng khóa 2 mới được tái tạo (the newly regenerated key 2).
  4. Tái tạo khóa 1 (Regenerate key 1).
  5. Cuối cùng, cập nhật mã sản xuất của bạn (update your production code) để sử dụng khóa 1 mới.

Ví dụ, để tái tạo khóa trong Azure portal, bạn có thể làm như sau:

  1. Trong Azure portal, đi đến bảng Khóa và Điểm cuối (Keys and Endpoint) của tài nguyên của bạn (your resource’s Keys and Endpoint pane).
  2. Sau đó chọn Tái tạo Khóa 1 (Regenerate Key1) hoặc chọn Tái tạo Khóa 2 (Regenerate Key2), tùy thuộc vào việc bạn muốn tái tạo khóa nào vào thời điểm đó(want to regenerate at the time).


Azure Key Vault is an Azure service in which you can securely store secrets (such as passwords and keys). Access to the key vault is granted to security principals, which you can think of user identities that are authenticated using Microsoft Entra ID. Administrators can assign a security principal to an application (in which case it is known as a service principal) to define a managed identity for the application. The application can then use this identity to access the key vault and retrieve a secret to which it has access. Controlling access to the secret in this way minimizes the risk of it being compromised by being hard-coded in an application or saved in a configuration file.

You can store the subscription keys for an AI services resource in Azure Key Vault, and assign a managed identity to client applications that need to use the service. The applications can then retrieve the key as needed from the key vault, without risk of exposing it to unauthorized users.


Azure Key Vault là một dịch vụ của Azure cho phép bạn lưu trữ bí mật (can securely store secrets) (chẳng hạn như mật khẩu và khóa – passwords and keys) một cách an toàn. Quyền truy cập vào key vault được cấp cho (is granted to) các thực thể bảo mật (security principals), mà bạn có thể hiểu như là (can think of) các danh tính người dùng (user identities) được xác thực (are authenticated) bằng Microsoft Entra ID. Quản trị viên (Administrators) có thể gán một thực thể bảo mật (a security principal) cho một ứng dụng (trong trường hợp này được gọi là service principal) để định nghĩa một danh tính quản lý ( define a managed identity) cho ứng dụng. Ứng dụng sau đó có thể sử dụng danh tính này (this identity) để truy cập vào key vault (access the key vault) và lấy ra một bí mật (retrieve a secret) mà nó có quyền truy cập. Việc kiểm soát quyền truy cập vào bí mật (Controlling access to the secret) theo cách này giảm thiểu nguy cơ (minimizes the risk of) bị xâm phạm (being compromised)do được mã hóa cứng (by being hard-coded) trong ứng dụng hoặc lưu trong tệp cấu hình (saved in a configuration file).

Bạn có thể lưu trữ các khóa đăng ký cho tài nguyên dịch vụ AI trong Azure Key Vault và gán một danh tính quản lý (assign a managed identity) cho các ứng dụng khách (client applications) cần sử dụng dịch vụ. Các ứng dụng sau đó có thể lấy khóa khi cần (can then retrieve the key as needed) từ key vault mà không có nguy cơ bị lộ (without risk of exposing it) cho người dùng không được phép(unauthorized users).



When using the REST interface, some AI services support (or even require) token-based authentication. In these cases, the subscription key is presented in an initial request to obtain an authentication token, which has a valid period of 10 minutes. Subsequent requests must present the token to validate that the caller has been authenticated.


Khi sử dụng giao diện REST (the REST interface), một số dịch vụ AI hỗ trợ (hoặc thậm chí yêu cầu) xác thực dựa trên token (token-based authentication). Trong những trường hợp này, khóa đăng ký (the subscription key) được trình bày trong yêu cầu ban đầu (an initial request) để lấy một token xác thực (obtain an authentication token), có thời hạn hiệu lực là 10 phút (a valid period of 10 minutes). Các yêu cầu tiếp theo (Subsequent requests) phải trình bày token để xác thực rằng (must present the token to validate) người gọi đã được xác thực (the caller has been authenticated).

Tip

When using an SDK, the calls to obtain and present a token are handled for you by the SDK.


Khi sử dụng SDK, các cuộc gọi để lấy và trình bày token được SDK xử lý cho bạn.



Azure AI services supports Microsoft Entra ID authentication, enabling you to grant access to specific service principals or managed identities for apps and services running in Azure.


Các dịch vụ AI của Azure (Azure AI services) hỗ trợ xác thực Microsoft Entra ID (Azure AI services), cho phép bạn cấp quyền truy cập (enabling you to grant access) cho các dịch vụ chính (specific service principals) hoặc danh tính được quản lý cụ thể (managed identities) cho các ứng dụng và dịch vụ chạy trong Azure.

Note

For more information about authentication options for AI services, see the AI services documentation.


Để biết thêm thông tin về các tùy chọn xác thực cho các dịch vụ AI, hãy xem tài liệu về các dịch vụ AI.

(Source: https://learn.microsoft.com/vi-vn/training/modules/secure-ai-services/2-authentication)

Leave a Reply

Your email address will not be published. Required fields are marked *