惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
Last Week in AI
Last Week in AI
博客园_首页
I
InfoQ
T
Tailwind CSS Blog
爱范儿
爱范儿
雷峰网
雷峰网
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
V
Visual Studio Blog
有赞技术团队
有赞技术团队
P
Proofpoint News Feed

博客园 - 衡子

Ubuntu24.04更改SSH端口 记录安装过程 Azure CLI创建管理员用户 创建VMSS中的instance 创建不带公网IP的VM Azure LSv3系列VM 自动挂载NVMe本地磁盘 Azure Linux VM使用Managed Identity获取Key-vault的Secret Azure AD SSO with Google Cloud Identity 通过VM SWAP OS DISK升级VM 通过API获取Azure KeyVault Securet Azure Front Door添加自定义域名 VM间网络PPS和带宽测试 Azure获取access token的方法 VM间记录时延 Windows Terminal的一些配置 安装hping Azure解除不再使用Directory的关联 使用VSCode Remote Containers功能实现开发环境统一 Azure AKS容器网络详解
Azure AD访问Azure Storage
衡子 · 2022-07-12 · via 博客园 - 衡子

通过Azure AD的service Principal申请access token,可以不使用Azure的Storage Account Key来访问Azure的存储资源。

具体方法如下:

name="whuser01"
sa="hwst"

sub_id=$(az account list --query "[?isDefault]" | jq -r .[].id)

az ad sp create-for-rbac -n $name --role reader --scopes /subscriptions/$sub_id

client_id=$(az ad sp list --display-name $name | jq -r .[].appId)
tenant_id=$(az ad sp list --display-name $name | jq -r .[].appOwnerOrganizationId)


secret="xxxxxxxx"

export token="$(curl -X POST \
    -d "grant_type=client_credentials" \
    -d "client_id=$client_id" \
    -d "client_secret=$secret" \
    -d "resource=https://storage.azure.com/" \
    https://login.microsoftonline.com/$tenant_id/oauth2/token | jq -r .access_token)"

curl --oauth2-bearer "$token" -i \
    -H 'x-ms-version: 2017-11-09' \
    https://$sa.blob.core.windows.net/?comp=list