Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Microsoft Entra ID 認証 / サービスプリンシパル / シークレット / 証...
Search
Masahiko Ebisuda
January 03, 2025
Technology
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Microsoft Entra ID 認証 / サービスプリンシパル / シークレット / 証明書 / マネージドID / Azure外でもマネージドID
Youtubeでの解説はこちら。
https://www.youtube.com/live/-M_MgOC9fmA
Masahiko Ebisuda
January 03, 2025
More Decks by Masahiko Ebisuda
See All by Masahiko Ebisuda
ソブリンクラウドの現在地 - そもそも何か。どこまで使えるか。
ebibibi
1
130
AI時代の「本当の」ハイブリッドクラウド — エージェントが実現した、あの頃の夢
ebibibi
0
240
ローカルLLMでクラウドアプリもAI使い放題_NVIDIA DGX Spark × Azure ハイブリッド構成
ebibibi
0
220
ADに依存しないクラスタの世界へ_On-PremからAzureLocalまで_前半_.pdf
ebibibi
0
160
ファイルサーバー運用の新時代!Azure FilesとArc拡張の最前線
ebibibi
1
290
ハイブリッドクラウド研究会第63回勉強会 / ClaudeCode×Azure, GeminiCLI×Azure
ebibibi
1
160
AIもハイブリッドにできる?!ローカルLLMとクラウドの組み合わせの可能性!
ebibibi
0
310
AIエージェンとはAzureインフラも構築できるのか?
ebibibi
0
290
もうVPNは古い? VPNを使わずに オンプレサーバーを 管理する手法あれこれ
ebibibi
0
320
Other Decks in Technology
See All in Technology
Railsのように考える: See through the Master
snoozer05
PRO
4
1k
GoのInterface内部構造から学ぶ!最高パフォーマンスを出すコード設計
yappli_developers
0
150
Vibe Coding で作ったプロダクトをどう安全に動かすか / How to Safely Run Products Built with Vibe Coding
glidenote
0
140
EventBridge に「合流」はない ― サーバーレスのワークフローを育てるということ / No Join in EventBridge
yusukeshimizu
2
130
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
110
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.8k
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
210
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
4
290
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.3k
Deployment の 先にある AI Agent 基盤 - kagent vNext、Agent Substrate、Hermes から読み解く Agent Runtime の現在地 / k8s-matsuri-2-ai-agent-platform-amsy810
masayaaoyama
4
660
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The Spectacular Lies of Maps
axbom
PRO
1
1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Automating Front-end Workflow
addyosmani
1369
210k
Making the Leap to Tech Lead
cromwellryan
135
10k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
350
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
330
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Transcript
Microsoft Entra ID認証 サービスプリンシパル シークレット / 証明書 マネージドID Azure外でもマネージドID @ebi
Masahiko Ebisuda
日本ビジネスシステムズ株式会社 胡田 昌彦(えびすだ まさひこ) Youtube https://youtube.com/@ebibibi 自己紹介 こんな方にオススメ! 企業の情報システム部で働く方
一般ユーザーだけど、コンピューターに興味 があって、もっと詳しくなりたい方 Windows, Azure, M365等のMicrosoft 関連技術に興味がある方 チャンネル登録よろしくお願いします!
None
None
None
None
None
None
None
最終的にやりたいことは 「トークン」を取得したうえで 「API」を叩くことです ※ポータルからの操作でもコマンド操作でもアプリケーションでの操作でも 最後の最後はトークン付きでAPIがたたかれています
何を言っているのかわからない? まずは実際にやってみましょう! Resource Groups - Create Or Update - REST
API (Azure Resource Management) | Microsoft Docs https://docs.microsoft.com/ja- jp/rest/api/resources/resource-groups/create-or-update
None
トークンを https://jwt.io/ でデコードしてみましょう
トークンさえ入手できればよい それをAPIに投げればよい
誰がどうやって トークンを取得するのか?
誰がどうやってトークンを取得するのか? 様々なバリエーションがある Microsoft ID プラットフォームの認証フローとアプリのシナ リオ - Microsoft Entra |
Microsoft Docs https://docs.microsoft.com/ja-jp/azure/active- directory/develop/authentication-flows-app- scenarios#scenarios-and-supported-authentication- flows ※日本語版は誤植が過去あったので注意)
誰が ユーザープリンシパル サービスプリンシパル マネージドID どうやって 対話操作
資格情報 他にも色々あるけどまずはこれだけわかれば 「自動化」程度なら困らない(と思う)
基本の基本 ユーザーが対話的に認証する
誰が ユーザープリンシパル サービスプリンシパル マネージドID どうやって 対話操作
資格情報
サービス ユーザープリンシパルが対話操作でトー クンを取得するパターン
対話操作 サービス ユーザープリンシパルが対話操作でトー クンを取得するパターン
対話操作 トークン取得 サービス ユーザープリンシパルが対話操作でトー クンを取得するパターン
対話操作 トークン取得 サービス ユーザープリンシパルが対話操作でトー クンを取得するパターン
PowerShell # 認証する Connect-AzAccount # 現在のコンテキストを確認する(認証したID,AADテナント,対象のサブスクリプション等) Get-AzContext # 対象サブスクリプションが適切でない場合には切り替える #Get-AzSubscription
#Select-AzSubscription -Subscription <SubscriptionIDを入力> # トークンが取得できることを確認する Get-AzAccessToken $token = (Get-AzAccessToken).token # リソースグループを作成する $subscriptionId = (Get-AzContext).Subscription.Id $resourceGroupName = "testrg1" $url = "https://management.azure.com/subscriptions/${subscriptionId}/resourcegroups/${resourceGroupName}?api- version=2021-04-01" $headers = @{ "Authorization" = "Bearer $token" "Content-type" = "application/json" } $body = '{location:"JapanEast"}' Invoke-RestMethod -Method PUT -Uri $url -Headers $headers -Body $body
None
専用のコマンドレットが存在 ※認証済みなら裏でトークンを取得して APIに投げてくれる
PowerShell # 認証する Connect-AzAccount # トークンを取得する $token = (Get-AzAccessToken).token #
リソースグループを作成する $subscriptionId = (Get-AzContext).Subscription.Id $resourceGroupName = "testrg1" $url = "https://management.azure.com/subscriptions/${subscriptionId}/resourcegroups/$ {resourceGroupName}?api-version=2021-04-01" $headers = @{ "Authorization" = "Bearer $token" "Content-type" = "application/json" } $body = '{location:"JapanEast"}' Invoke-RestMethod -Method PUT -Uri $url -Headers $headers -Body $body
PowerShell # 認証する Connect-AzAccount # リソースグループを作成する New-AzResourceGroup -Name testrg2 -Location
JapanEast
PowerShell # 認証する Connect-AzAccount # リソースグループを作成する New-AzResourceGroup -Name testrg2 -Location
JapanEast 対話的な認証では自動化できない!
サービスプリンシパルを使う
誰が ユーザープリンシパル サービスプリンシパル マネージドID どうやって 対話操作
資格情報
サービスプリンシパルが資格情報でトー クンを取得するパターン サービス
サービスプリンシパルが資格情報でトー クンを取得するパターン 資格情報 サービス
サービスプリンシパルが資格情報でトー クンを取得するパターン 資格情報 トークン取得 サービス
サービスプリンシパルが資格情報でトー クンを取得するパターン 資格情報 トークン取得 サービス
サービスプリンシパル / パスワードベースの認証 1. AADにアプリケーションを登録しサービスプリンシパルを作成する - アプリケーション - サービスプリンシパル 2.
サービスプリンシパルにRBACで権限を付与する 3. シークレットを作成する 4. PowerShellでサービスプリンシパルとして認証する PowerShell $applicationId = "" $clientSecret = "" $tenantId = "" $securedSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force $creds = New-Object System.Management.Automation.PSCredential($applicationId, $securedSecret) Connect-AzAccount -ServicePrincipal -Tenant $tenantId -Credential $creds Get-AzContext Get-AzAccessToken New-AzResourceGroup -Name testrg3 -Location JapanEast
サービスプリンシパル / パスワードベースの認証 1. AADにアプリケーションを登録しサービスプリンシパルを作成する - アプリケーション - サービスプリンシパル 2.
サービスプリンシパルにRBACで権限を付与する 3. シークレットを作成する 4. PowerShellでサービスプリンシパルとして認証する PowerShell $applicationId = "" $clientSecret = "" $tenantId = "" $securedSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force $creds = New-Object System.Management.Automation.PSCredential($applicationId, $securedSecret) Connect-AzAccount -ServicePrincipal -Tenant $tenantId -Credential $creds Get-AzContext Get-AzAccessToken New-AzResourceGroup -Name testrg3 -Location JapanEast シークレットを生で書くのはダメ!
サービスプリンシパル / 証明書ベースの認証 1. AADにアプリケーションを登録しサービスプリンシパルを作成する - アプリケーション - サービスプリンシパル 2.
サービスプリンシパルにRBACで権限を付与する 3. (どこで作成してもいいが、今回はローカルのWindows上で)証明書を生成する 4. サービスプリンシパルに証明書をアップロードする 5. PowerShellでサービスプリンシパルとして認証する PowerShell $applicationId = "" $tenantId = "" # 証明書作成 New-SelfSignedCertificate -CertStoreLocation "cert:\CurrentUser\My" ` -Subject "CN=CertforSP" -KeySpec KeyExchange $Thumbprint = (Get-ChildItem cert:\CurrentUser\My\ | Where-Object {$_.Subject -eq "CN=CertforSP" })[0].Thumbprint # 認証 Connect-AzAccount -ServicePrincipal -CertificateThumbprint $Thumbprint ` -ApplicationId $applicationId -TenantId $tenantId Get-AzContext Get-AzAccessToken New-AzResourceGroup -Name testrg4 -Location JapanEast
サービスプリンシパル / 証明書ベースの認証 1. AADにアプリケーションを登録しサービスプリンシパルを作成する - アプリケーション - サービスプリンシパル 2.
サービスプリンシパルにRBACで権限を付与する 3. (どこで作成してもいいが、今回はローカルのWindows上で)証明書を生成する 4. サービスプリンシパルに証明書をアップロードする 5. PowerShellでサービスプリンシパルとして認証する PowerShell $applicationId = "" $tenantId = "" # 証明書作成 New-SelfSignedCertificate -CertStoreLocation "cert:\CurrentUser\My" ` -Subject "CN=CertforSP" -KeySpec KeyExchange $Thumbprint = (Get-ChildItem cert:\CurrentUser\My\ | Where-Object {$_.Subject -eq "CN=CertforSP" })[0].Thumbprint # 認証 Connect-AzAccount -ServicePrincipal -CertificateThumbprint $Thumbprint ` -ApplicationId $applicationId -TenantId $tenantId Get-AzContext Get-AzAccessToken New-AzResourceGroup -Name testrg4 -Location JapanEast 証明書の管理がめんどくさい!
None
None
誰が ユーザープリンシパル サービスプリンシパル マネージドID どうやって 対話操作
資格情報
Azure上のリソースに を用意してくれる
Azure VM上でマネージドIDのアクセストー クンを取得する Invoke-WebRequest -Uri 'http://169.254.169.254/metadata/identity/oaut h2/token?api-version=2018-02- 01&resource=https%3A%2F%2Fmanagement.azure.com %2F’ `
-Headers @{Metadata=“true”} 169.254.169.254 というIPアドレスからトークンが取得できる! マネージドIDがONであれば何もしなくてもいきなりトークンが取れる!
None
None
How managed identities for Azure resources work with Azure virtual
machines - Managed identities for Azure resources | Microsoft Learn https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-managed-identities-work-vm
Microsoft Entra IDにサー ビスプリンシパルを作成 証明書作成、登録、更新 トークン取得のProxy
PowerShell # 認証する Connect-AzAccount # リソースグループを作成する New-AzResourceGroup -Name testrg2 -Location
JapanEast 対話的な認証では自動化できない!
PowerShell # 認証する Connect-AzAccount -Identity # リソースグループを作成する New-AzResourceGroup -Name testrg2
-Location JapanEast パスワードも証明書も必要ない! 超簡単!
None
None
None
None
None
None
None
None
None
None
None
None
IMDS_ENDPOINT= http://localhost:40342 IDENTITY_ENDPOINT= http://localhost:40342/metadata/identity/oauth2/token
None
PowerShell # 認証する Connect-AzAccount -Identity # リソースグループを作成する New-AzResourceGroup -Name testrg2
-Location JapanEast パスワードも証明書も必要ない! 超簡単!
ファイルにアクセス出来ない ケースがあるので注意 ※原因知ってる人いたら教えてください。バグ?
None
None
None
None
None
None
None