跳到正文
Skillpedia
API 与服务器(后端)48k · #3937

azure-identity-rust

它能做什么

这个工具可以帮助用 Rust 编写的程序安全地连接到 Microsoft Azure 服务。它负责管理程序如何证明自己的身份,以及它是否有权限访问资源。

适用场景

  • ✓当你在本地开发一个需要访问 Azure 的 Rust 程序时。
  • ✓当程序已经运行在 Azure 服务上(比如虚拟机或网页应用)时。
  • ✓当你配置程序使用“服务主体”(service principal),并通过密钥或证书访问 Azure 时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-identity-rust/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-identity-rust/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我怎样才能用我的命令行凭据,让 Rust 程序连接到 Azure?”

每周 5 个新技能,1 分钟读完。

工作原理

它会尝试多种方式来证明程序的身份,首先检查你电脑上安装的开发者工具。如果找不到,它还可以使用直接在 Azure 中配置的身份,或者你提供的密钥。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Azure Identity SDK for Rust

Authentication library for Azure SDK clients using Microsoft Entra ID (formerly Azure AD).

The examples below require a reviewed compatible crate set and replacement of every resource placeholder. Do not use production data for demonstration writes.

Installation

cargo add azure_identity@=1.0.0 azure_core@=1.1.0

Environment Variables

# Service Principal (for production/CI)
export AZURE_TENANT_ID="<your-tenant-id>"
export AZURE_CLIENT_ID="<your-client-id>"
: "${AZURE_CLIENT_SECRET:?Inject through the approved host or CI secret manager}"
export AZURE_CLIENT_SECRET

# User-assigned Managed Identity (optional)
export AZURE_CLIENT_ID="<managed-identity-client-id>"

DeveloperToolsCredential

The recommended credential for local development. Tries developer tools in order (Azure CLI, Azure Developer CLI):

use azure_identity::DeveloperToolsCredential;
use azure_security_keyvault_secrets::SecretClient;

let credential = DeveloperToolsCredential::new(None)?;
let client = SecretClient::new(
    "https://my-vault.vault.azure.net/",
    credential.clone(),
    None,
)?;

Credential Chain Order

Order Credential Environment
1 AzureCliCredential az login
2 AzureDeveloperCliCredential azd auth login

Credential Types

Credential Usage
DeveloperToolsCredential Local development - tries CLI tools
ManagedIdentityCredential Azure VMs, App Service, Functions, AKS
WorkloadIdentityCredential Kubernetes workload identity
ClientSecretCredential Service principal with secret
ClientCertificateCredential Service principal with certificate
AzureCliCredential Direct Azure CLI auth
AzureDeveloperCliCredential Direct azd CLI auth
AzurePipelinesCredential Azure Pipelines service connection
ClientAssertionCredential Custom assertions (federated identity)

ManagedIdentityCredential

For Azure-hosted resources:

use azure_identity::{ManagedIdentityCredential, ManagedIdentityCredentialOptions, UserAssignedId};

// System-assigned managed identity
let credential = ManagedIdentityCredential::new(None)?;

// User-assigned managed identity
let options = ManagedIdentityCredentialOptions {
    user_assigned_id: Some(UserAssignedId::ClientId("<user-assigned-mi-client-id>".into())),
    ..Default::default()
};
let credential = ManagedIdentityCredential::new(Some(options))?;

ClientSecretCredential

For service principal with secret:

use azure_identity::ClientSecretCredential;

let credential = ClientSecretCredential::new(
    "<tenant-id>".into(),
    "<client-id>".into(),
    "<client-secret>".into(),
    None,
)?;

Best Practices

  1. Use DeveloperToolsCredential for local dev — automatically picks up Azure CLI
  2. Use ManagedIdentityCredential in production — no secrets to manage
  3. Clone credentials — credentials are Arc-wrapped and cheap to clone
  4. Reuse credential instances — same credential can be used with multiple clients
  5. Provide the async runtime — add Tokio with the features required by your application; do not assume a crate-specific tokio feature exists

The reviewed example set uses azure_identity 1.0.0 and compatible Azure core/credential crates. Record and commit Cargo.lock; source/API review is not a compiler or live-service test.

Reference Links

Resource Link
API Reference https://docs.rs/azure_identity
Source Code https://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/identity/azure_identity
crates.io https://crates.io/crates/azure_identity

When to Use

Use when choosing or configuring Entra ID credentials for Rust Azure SDK clients: local developer tools, managed/workload identity or a reviewed service principal.

Limitations

  • Examples are fragments inside async application code, with compatible pinned Azure crates and the required Tokio/Serde/Futures dependencies; verify the selected version’s API before use. They were reviewed against official source/reference, not compiled or run against a cloud account here.

…

常见问题

本地开发时,最好的使用方式是什么?

使用 `DeveloperToolsCredential`。它会尝试使用 Azure CLI 或 Azure Developer CLI,而你可能已经为登录配置好了这些工具。

如果我的程序已经在 Azure 中运行,该怎么办?

使用 `ManagedIdentityCredential`。Azure 自己会处理身份验证,不需要密码或密钥。

同一套身份验证配置可以用于多个客户端吗?

可以。凭据复制的成本很低,并且可以用于多个 Azure 客户端。

详情

作者的原始描述

Azure Identity SDK for Rust authentication. Use for DeveloperToolsCredential, ManagedIdentityCredential, ClientSecretCredential, and token-based authentication.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#3937
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能