Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon 是否可以使用本地环境测试托管身份


是否可以使用本地环境测试托管身份


在本地环境中测试托管身份并不简单,因为托管身份主要是为在Azure资源中使用的。但是,有多种方法可以在本地模拟或模拟托管身份:

1。注册Azure Arc:您可以在Azure Arc中注册本地计算机,从而使您可以为计算机分配托管身份。这可以是系统分配或用户分配的托管身份。注册后,您可以通过为托管身份分配必要的权限来在本地测试托管身份[1]。

2。在本地模拟托管身份:另一种方法是通过运行模拟实例元数据服务在本地模仿Azure托管身份服务。这涉及模拟令牌API以返回访问令牌,通常使用Azure CLI凭据。此方法使您可以测试使用托管身份的代码,而无需实际将其放在本地计算机上[3]。

3。使用DefaultazureCrecreCredential:对于大多数开发方案,建议使用`defaustazureCredential“。此凭据会自动尝试各种身份验证方法,包括Visual Studio,Azure CLI和Azure AD集成身份验证,以在本地验证您的应用程序。尽管不直接使用托管身份,但它提供了类似的无缝身份验证经验[5] [7]。

总而言之,虽然托管身份本身不能直接在本地环境中使用,但您可以模拟它们,也可以使用诸如`defaultazurecrecrecrecreCredential“进行本地开发”之类的替代身份验证方法。

引用:
[1] https://www.foxdeploy.com/blog/how-to-migrate-migrate-an-azure-function-app-to-sapp-to-use-a-managed-indistity.html
[2] https://stackoverflow.com/questions/67845857/can-a-a-user-shassed-managed-nideity-be-be-be-locustally-locally
[3] https://gist.github.com/maskati/e0d74330dcf15848b043825cf6b2f8b7
[4] https://learn.microsoft.com/en-us/entra/enterity/managed-indentities-indentities-indiesities-ientities-iendity-resources/overview-for-developers
[5] https://www.reddit.com/r/azure/comments/1cilud6/managed_identities_and_local_developer_experience/
[6] https://learn.microsoft.com/en-us/entra/enterity/managed-indiestities-indentities-indiesities-iendities-iendities-iendities-iendity-manage-manage-user-user-sapsigned-managed-indistity
[7] https://stackoverflow.com/questions/75930046/how-to-to-run-azure-function-locally-using-usis-user-user-usigh-maned-maned-nideity-configura
[8] https://www.codemag.com/article/2107041/eliminate-secrets-from-your-applications-with-azure-managed-nideity
[9] https://learn.microsoft.com/en-us/azure/app-service/overview-managed-istentity