前言

[Azure 筆記] 前言

本文有相當部份由 AI 生成
若未驗證,會標記為「有待驗證」


原文

Create triggers and bindings


Application setting

為了有更好的安全性
在使用 Azure Functions 時
請使用 application settings 來儲存 secret
(例如 keys, token, connection string)

Application settings 以 name value pair 的方式儲存你的資料
你的 function 在運行時可以以 environment variable 的方式讀取 application settings

在 local 進行開發時
Local functions 沒有 application setting
不過你可以使用 local settings file 作代替

Configure an identity-based connection

某些 Azure Function 內的 connection 是使用 identity 而不是 secret
至於使用的是 identity 還是 secret
則是視乎你用的是那一種 extension

Identity-based connection

Identity-based connection 讓你不需要管理 key 和 secret
而是使用 managed identity 來進行身份驗證和授權

Azure environment

在 Azure 環境可用的 managed identity 有兩種
分別是 system-assigned identityuser-assigned identity

System-assigned Identity

預設會使用這個 identity
Azure 會自動為你的 function 建立一個系統指派的身分識別
並用它來進行身份驗證。

User-assigned Identity

如果你需要更靈活的控制 identity
你可以使用 user-assigned identity

若你需要使用它
你需要在設定中指定 credentialclientID 屬性
(而不是設定 resource ID)

 

Other environment (e.g. Local development)

當 Azure Functions 在本地開發環境(例如 Visual Studio 或 VS Code)中運行時,系統會使用 developer identity 來進行 identity-based connection

Developer identity 是指你當前登入 Azure CLI 或 Visual Studio 的帳戶 (這句有待驗證)

你可以自定義 developer identity
你可以透過設定來更改使用的身份
例如使用本地的服務主體(Service Principal)或其他憑證
(這段有待驗證)

 

Grant permission to the identity

在執行不同的行動時
請求執行的 identity 需要有相應的 permission

例如
如果 Azure Functions 需要從 Azure Blob Storage 讀取資料
使用的 identity 必須具備讀取 Blob Storage 的權限

How to grant the permission (本節有待驗證)

常見的授權方式有以下兩種

使用 Azure 角色型存取控制(Azure RBAC)

什麼是 Azure RBAC?

Azure RBAC(Role-Based Access Control)是一種基於角色的權限管理機制
允許你將特定的角色指派給身份
從而授予該身份對特定資源的存取權限

如何操作?

  1. 在 Azure 入口網站中,找到你要存取的資源(例如 Azure Storage Account、Azure Key Vault 等)。
  2. 進入該資源的 存取控制(IAM) 頁面。
  3. 點擊 新增角色指派(Add Role Assignment)
  4. 選擇適當的角色(例如「儲存體 Blob 資料讀者」用於讀取 Blob Storage)。
  5. 將角色指派給你的身份(系統指派身份或使用者指派身份)。

範例角色

  • 讀取 Blob StorageStorage Blob Data Reader
  • 寫入 Blob StorageStorage Blob Data Contributor
  • 讀取 Key Vault 密鑰Key Vault Secrets User

在服務的存取政策(Access Policy)中指定身份

某些 Azure 服務(例如 Azure Key Vault)使用 存取政策(Access Policy) 來管理身份對資源的存取權限

如何操作?

  1. 在 Azure 入口網站中,找到你要存取的服務(例如 Azure Key Vault)。
  2. 進入該服務的 存取政策(Access Policies) 頁面。
  3. 新增一個存取政策,並指定你的身份(受控身份)。
  4. 授予該身份所需的權限(例如讀取密鑰、列出密鑰等)。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


Trending