Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Microsoft Entra ID 認証 / サービスプリンシパル / シークレット / 証...
Search
Masahiko Ebisuda
January 03, 2025
Technology
0
36
Microsoft Entra ID 認証 / サービスプリンシパル / シークレット / 証明書 / マネージドID / Azure外でもマネージドID
Youtubeでの解説はこちら。
https://www.youtube.com/live/-M_MgOC9fmA
Masahiko Ebisuda
January 03, 2025
Tweet
Share
More Decks by Masahiko Ebisuda
See All by Masahiko Ebisuda
WSUSが非推奨に!? Windowsの更新管理を改めて勉強する!
ebibibi
0
1.4k
認証にシークレットも証明書も不要?! オンプレミスのサーバーでマネージドIDを利用!
ebibibi
0
170
Arc Jumpstart HCIBox Azure Stack HCI 23H2対応バージョン 展開してみた。
ebibibi
0
410
Azureならファイルサーバー そのままPaaS化OK!
ebibibi
0
280
2025年10月1日 Azure VMからインターネットアクセスができなくなる!?
ebibibi
0
250
クラウド&エッジ 次世代スーパーマーケットの アーキテクチャ解説&デモ
ebibibi
0
220
企業IT向け:Azure OpenAIでChatGPTを閉域で安全に展開
ebibibi
0
450
企業IT向け Azure OpenAIでChatGPTを 閉域で安全に展開
ebibibi
0
1.4k
Azure Policyでハイブリッドな構成管理
ebibibi
0
250
Other Decks in Technology
See All in Technology
Classmethod AI Talks(CATs) #17 司会進行スライド(2025.02.19) / classmethod-ai-talks-aka-cats_moderator-slides_vol17_2025-02-19
shinyaa31
0
120
データの品質が低いと何が困るのか
kzykmyzw
6
1.1k
OpenID BizDay#17 KYC WG活動報告(法人) / 20250219-BizDay17-KYC-legalidentity
oidfj
0
250
現場で役立つAPIデザイン
nagix
33
12k
Cloud Spanner 導入で実現した快適な開発と運用について
colopl
1
680
関東Kaggler会LT: 人狼コンペとLLM量子化について
nejumi
3
590
白金鉱業Meetup Vol.17_あるデータサイエンティストのデータマネジメントとの向き合い方
brainpadpr
6
760
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
6.2k
次世代KYC活動報告 / 20250219-BizDay17-KYC-nextgen
oidfj
0
260
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
400
プロダクトエンジニア構想を立ち上げ、プロダクト志向な組織への成長を続けている話 / grow into a product-oriented organization
hiro_torii
1
200
Building Products in the LLM Era
ymatsuwitter
10
5.5k
Featured
See All Featured
Writing Fast Ruby
sferik
628
61k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Speed Design
sergeychernyshev
27
790
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Bash Introduction
62gerente
611
210k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Why Our Code Smells
bkeepers
PRO
336
57k
Bootstrapping a Software Product
garrettdimon
PRO
306
110k
Producing Creativity
orderedlist
PRO
344
39k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Practical Orchestrator
shlominoach
186
10k
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