%3CLINGO-SUB%20id%3D%22lingo-sub-1711597%22%20slang%3D%22en-US%22%3EManaged%20Identity%20for%20Azure%20App%20Services%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1711597%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20App%20Services%20supports%20an%20interesting%20feature%20called%20Manage%20Identity%20from%20Azure%20Active%20Directory.%3CBR%20%2F%3EThis%20allows%20your%20App%20Services%20to%20easily%20connect%20to%20Azure%20Resources%20such%20as%20Azure%20KeyVault%2C%20Azure%20Storage%2C%20Azure%20SQL%20.%20The%20complete%20list%20of%20resources%20that%20support%20this%20feature%20are%20available%20in%20the%20following%20document%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fmanaged-identities-azure-resources%2Fservices-support-managed-identities%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Services%20that%20support%20managed%20identities%20-%20Azure%20AD%20%7C%20Microsoft%20Docs%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20could%20refer%20to%20our%20documentation%20for%20more%20details%20on%20this%20feature%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Foverview-managed-identity%3Ftabs%3Ddotnet%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EMSI-Validator%20helps%20you%20troubleshoot%20issues%20with%20Managed%20Identity%20for%20Azure%20App%20Services.%3CBR%20%2F%3EThe%20link%20to%20download%20this%20tool%20is%20available%20in%20the%20attachments%20section%20of%20the%20blog.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EInstallation%20Steps%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EDownload%20the%20zip%20file%20from%20the%20attachments.%3CBR%20%2F%3ECurrent%20version%20-%20v1.0.0.0%3C%2FLI%3E%0A%3CLI%3EExtract%20it%20to%20the%20local%20folder.%3C%2FLI%3E%0A%3CLI%3EDrag%20and%20drop%20%22%3CSTRONG%3Emsi-validator.exe%3C%2FSTRONG%3E%22%20to%20the%20Kudu%20console%20of%20the%20App%20Service%20(%3CA%20href%3D%22https%3A%2F%2F%253cwebapp-name%253e.scm.azurewebsites.net%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F%3CWEBAPP-NAME%3E.scm.azurewebsites.net%3C%2FWEBAPP-NAME%3E%3C%2FA%3E)%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2201-%20Download%20and%20installation.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F221998iDA1B5456D2EB2461%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2201-%20Download%20and%20installation.png%22%20alt%3D%2201-%20Download%20and%20installation.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3ECommands%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ETo%20Get%20an%20Access%20Token%20%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emsi-validator%20get-token%20-r%20%3CRESOURCE%3E%E2%80%8B%0A%0AValid%20Arguments%20for%20resource%20%3D%20keyvault%2C%20storage%2C%20sql%0ASample%3A%0Amsi-validator%20get-token%20-r%20keyvault%0Amsi-validator%20get-token%20-r%20storage%0Amsi-validator%20get-token%20-r%20sql%3C%2FRESOURCE%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3ETo%20Test%20the%20connection%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emsi-validator%20test-connection%20-r%20%3CRESOURCE%3E%20-e%20%3CENDPOINT%3E%0A%0AValid%20Arguments%20for%20resource%20%3D%20keyvault%2C%20storage%2C%20sql%0A%0ASample%3A%0A%0Amsi-validator%20test-connection%20-r%20%22keyvault%22%20-e%20%22https%3A%2F%2F%3CKEYVAULT-NAME%3E.vault.azure.net%2Fsecrets%2F%3CSECRET-KEY%3E%22%0Amsi-validator.exe%20test-connection%20-r%20storage%20-e%20https%3A%2F%2F%3CSTORAGE-NAME%3E.blob.core.windows.net%2F%3CCONTAINER-NAME%3E%2F%3CBLOB-PATH%3E%0Amsi-validator.exe%20test-connection%20-r%20sql%20-e%20%22Data%20Source%3D%3CSERVER-NAME%3E.database.windows.net%3BInitial%20Catalog%3D%3CDATABASE-NAME%3E%3B%22%0A%E2%80%8B%3C%2FDATABASE-NAME%3E%3C%2FSERVER-NAME%3E%3C%2FBLOB-PATH%3E%3C%2FCONTAINER-NAME%3E%3C%2FSTORAGE-NAME%3E%3C%2FSECRET-KEY%3E%3C%2FKEYVAULT-NAME%3E%3C%2FENDPOINT%3E%3C%2FRESOURCE%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3ETroubleshooting%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EFrom%20the%20Identity%20Blade%20of%20the%20App%20Service%2C%20ensure%20that%20Managed%20Identity%20is%20turned%20on.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2200%20-%20check%20in%20azure%20portal.png%22%20style%3D%22width%3A%20749px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222084iEC05969956D18FEC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2200%20-%20check%20in%20azure%20portal.png%22%20alt%3D%2200%20-%20check%20in%20azure%20portal.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3ENavigate%20to%20Kudu%20Console%20(%3CA%20href%3D%22https%3A%2F%2F%253cwebapp-name%253e.scm.azurewebsites.net%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F%3CWEBAPP-NAME%3E.scm.azurewebsites.net%3C%2FWEBAPP-NAME%3E%3C%2FA%3E)%20%26gt%3B%20Environment%20Section%20and%20search%20for%20MSI%20(Ctrl%20%2B%20F)%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2202%20-%20check%20env%20variables.png%22%20style%3D%22width%3A%20931px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F221999i55C99E4E8B4F0D27%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2202%20-%20check%20env%20variables.png%22%20alt%3D%2202%20-%20check%20env%20variables.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EThe%20Environmental%20Variables%20%22%3CSTRONG%3EMSI_ENDPOINT%3C%2FSTRONG%3E%22%20and%20%22%3CSTRONG%3EMSI_SECRET%3C%2FSTRONG%3E%22%20would%20have%20been%20set%20automatically.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3ERun%20the%20command%20%22%3CSTRONG%3Emsi-validator%20get-token%20-r%20%3CRESOURCE%3E%3C%2FRESOURCE%3E%3C%2FSTRONG%3E%22%20and%20check%20if%20a%20token%20is%20being%20returned.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2203%20-%20inspect%20the%20token.png%22%20style%3D%22width%3A%20854px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222085iC7AB349875D1A107%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2203%20-%20inspect%20the%20token.png%22%20alt%3D%2203%20-%20inspect%20the%20token.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EAn%20access%20token%20should%20be%20returned.%3CBR%20%2F%3E%3C%2FSPAN%3EOtherwise%2C%20it%20indicates%20that%20MSI%20service%20has%20issues%20reaching%20out%20to%20Azure%20Active%20Directory%20to%20fetch%20a%20token.%3CBR%20%2F%3E%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CBR%20%2F%3E%3CSTRONG%3EThings%20to%20check%20%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDoes%20the%20App%20Service%20have%20regional%20VNet%20Integration%20%2F%20is%20the%20App%20in%20ASE%3F%20%3CBR%20%2F%3EAre%20there%20any%20User%20Defined%20Routes%20on%20the%20subnet%20to%20which%20the%20App%20Service%20is%20integrated%20%3F%3CBR%20%2F%3EIf%20Yes%20%2C%20is%20the%20device%20to%20which%20the%20traffic%20is%20force%20tunneled%2C%20blocking%20any%20Azure%20Active%20Directory%20Dependency%20%3F%3C%2FLI%3E%0A%3CLI%3EDo%20you%20still%20face%20the%20issue%20if%20Managed%20Identity%20is%20disabled%20and%20enabled%20again%20%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3ERun%20the%20command%20%22%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3Emsi-validator%20test-connection%20-r%20%3CRESOURCE%3E%20-e%20%22%3CENDPOINT%3E%22%3C%2FENDPOINT%3E%3C%2FRESOURCE%3E%3C%2FSTRONG%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%20%22%20and%20check%20if%20data%20is%20returned%20from%20the%20resource%20or%20inspect%20the%20error%20message..%3CBR%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3EKeyVault%3A%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%20font-weight%3A%20300%3B%22%3EFrom%20the%20below%20error%20message%2C%20we%20see%20that%20the%20App%20Service%20doesn%E2%80%99t%20have%20necessary%20permissions%20to%20access%20the%20KeyVault.%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2204%20-%20keyvault%20issue.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222001i0B95E6796493BEF2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2204%20-%20keyvault%20issue.png%22%20alt%3D%2204%20-%20keyvault%20issue.png%22%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%20font-weight%3A%20300%3B%22%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FSTRONG%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3EResolution%3A%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3COL%20class%3D%22lia-list-style-type-lower-roman%22%3E%0A%3CLI%20class%3D%22lia-indent-padding-left-30px%22%3ENavigate%20to%20the%20%3CSTRONG%3EAccess%20Policies%20Blade%3C%2FSTRONG%3E%20of%20KeyVault%20from%20the%20Azure%20Portal.%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-indent-padding-left-30px%22%3EClick%20on%20%22%3CSTRONG%3E%2B%20Add%20Access%20Policy%3C%2FSTRONG%3E%22%3CBR%20%2F%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2205%20-%20keyvault%20select%20access%20policies.png%22%20style%3D%22width%3A%20739px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222002iB360285AB338164D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2205%20-%20keyvault%20select%20access%20policies.png%22%20alt%3D%2205%20-%20keyvault%20select%20access%20policies.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EProvide%20the%20necessary%20permission.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2206%20-%20select%20permissions.png%22%20style%3D%22width%3A%20427px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222003iF16C66EB1B7F2147%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2206%20-%20select%20permissions.png%22%20alt%3D%2206%20-%20select%20permissions.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EChoose%20the%20Service%20Principal%20(name%20of%20the%20App%20Service)%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2207%20-%20select%20service%20principal.png%22%20style%3D%22width%3A%20592px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222004i1073F996BAAE7B0B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2207%20-%20select%20service%20principal.png%22%20alt%3D%2207%20-%20select%20service%20principal.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3EStorage%3A%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2208%20-%20storage%20issue.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222005i2209318ADE1157D8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2208%20-%20storage%20issue.png%22%20alt%3D%2208%20-%20storage%20issue.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EResolution%20%3A%3CBR%20%2F%3E%3C%2FSTRONG%3ENavigate%20to%20the%20Access%20Control%20IAM)%20%26gt%3B%20Add%20Role%20assignment%20and%20choose%20the%20necessary%20storage%20related%20permission.%20The%20roles%20should%20be%20configured%20as%20per%20your%20application's%20use%20case.%3CSTRONG%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2209%20-%20storage%20role%20assginments.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222006iAEF178027C0CB633%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2209%20-%20storage%20role%20assginments.png%22%20alt%3D%2209%20-%20storage%20role%20assginments.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESQL%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EThe%20application%20could%20fail%20while%20connecting%20to%20Azure%20SQL%20using%20MSI%20with%20the%20error%20message%3A%20%22%3CSTRONG%3EUnable%20to%20connect%20to%20SQL.%20Exception%20%3A%20Login%20failed%20for%20user%20'%3CTOKEN-IDENTIFIED%3E'%3C%2FTOKEN-IDENTIFIED%3E%3C%2FSTRONG%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%2210%20-%20sql%20issue.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222007i35880C5AC0ACC9DF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%2210%20-%20sql%20issue.png%22%20alt%3D%2210%20-%20sql%20issue.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EResolution%3A%3CBR%20%2F%3E%3C%2FSTRONG%3EIf%20you%20want%2C%20you%20can%20add%20the%20identity%20to%20an%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoftDocs%2Fazure-docs%2Fblob%2Fmaster%2Farticles%2Factive-directory%2Ffundamentals%2Factive-directory-manage-groups.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20AD%20group%3C%2FA%3E%2C%20then%20grant%20SQL%20Database%20access%20to%20the%20Azure%20AD%20group%20instead%20of%20the%20identity.%20For%20example%2C%20the%20following%20commands%20add%20the%20managed%20identity%20from%20the%20previous%20step%20to%20a%20new%20group%20called%26nbsp%3BmyAzureSQLDBAccessGroup%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Egroupid%3D%24(az%20ad%20group%20create%20--display-name%20myAzureSQLDBAccessGroup%20--mail-nickname%20myAzureSQLDBAccessGroup%20--query%20objectId%20--output%20tsv)%0Amsiobjectid%3D%24(az%20webapp%20identity%20show%20--resource-group%20myResourceGroup%20--name%20%3CAPP-NAME%3E%20--query%20principalId%20--output%20tsv)%0Aaz%20ad%20group%20member%20add%20--group%20%24groupid%20--member-id%20%24msiobjectid%0Aaz%20ad%20group%20member%20list%20-g%20%24groupid%0A%3C%2FAPP-NAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EIn%20the%20Cloud%20Shell%2C%20sign%20in%20to%20SQL%20Database%20by%20using%20the%20SQLCMD%20command.%20Replace%26nbsp%3B%3CSERVER-NAME%3E%26nbsp%3Bwith%20your%20server%20name%2C%26nbsp%3B%3CDB-NAME%3E%26nbsp%3Bwith%20the%20database%20name%20your%20app%20uses%2C%20and%26nbsp%3B%3CAAD-USER-NAME%3E%26nbsp%3Band%26nbsp%3B%3CAAD-PASSWORD%3E%26nbsp%3Bwith%20your%20Azure%20AD%20user's%20credentials.%3C%2FAAD-PASSWORD%3E%3C%2FAAD-USER-NAME%3E%3C%2FDB-NAME%3E%3C%2FSERVER-NAME%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Esqlcmd%20-S%20%3CSERVER-NAME%3E.database.windows.net%20-d%20%3CDB-NAME%3E%20-U%20%3CAAD-USER-NAME%3E%20-P%20%22%3CAAD-PASSWORD%3E%22%20-G%20-l%2030%3C%2FAAD-PASSWORD%3E%3C%2FAAD-USER-NAME%3E%3C%2FDB-NAME%3E%3C%2FSERVER-NAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EIn%20the%20SQL%20prompt%20for%20the%20database%20you%20want%2C%20run%20the%20following%20commands%20to%20grant%20the%20permissions%20your%20app%20needs.%20For%20example%2C%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20USER%20%5B%3CIDENTITY-NAME%3E%5D%20FROM%20EXTERNAL%20PROVIDER%3B%0AALTER%20ROLE%20db_datareader%20ADD%20MEMBER%20%5B%3CIDENTITY-NAME%3E%5D%3B%0AALTER%20ROLE%20db_datawriter%20ADD%20MEMBER%20%5B%3CIDENTITY-NAME%3E%5D%3B%0AALTER%20ROLE%20db_ddladmin%20ADD%20MEMBER%20%5B%3CIDENTITY-NAME%3E%5D%3B%0AGO%3C%2FIDENTITY-NAME%3E%3C%2FIDENTITY-NAME%3E%3C%2FIDENTITY-NAME%3E%3C%2FIDENTITY-NAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIDENTITY-NAME%3E%26nbsp%3Bis%20the%20name%20of%20the%20managed%20identity%20in%20Azure%20AD.%20If%20the%20identity%20is%20system-assigned%2C%20the%20name%20always%20the%20same%20as%20the%20name%20of%20your%20App%20Service%20app.%20To%20grant%20permissions%20for%20an%20Azure%20AD%20group%2C%20use%20the%20group's%20display%20name%20instead%20(for%20example%2C%26nbsp%3BmyAzureSQLDBAccessGroup).%3CBR%20%2F%3E%3CBR%20%2F%3EType%26nbsp%3BEXIT%26nbsp%3Bto%20return%20to%20the%20Cloud%20Shell%20prompt.%3CBR%20%2F%3E%3CEM%3EThe%20back-end%20services%20of%20managed%20identities%20also%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoftDocs%2Fazure-docs%2Fblob%2Fmaster%2Farticles%2Fapp-service%2Foverview-managed-identity.md%23obtain-tokens-for-azure-resources%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emaintains%20a%20token%20cache%3C%2FA%3E%26nbsp%3Bthat%20updates%20the%20token%20for%20a%20target%20resource%20only%20when%20it%20expires.%20If%20you%20make%20a%20mistake%20configuring%20your%20SQL%20Database%20permissions%20and%20try%20to%20modify%20the%20permissions%26nbsp%3Bafter%26nbsp%3Btrying%20to%20get%20a%20token%20with%20your%20app%2C%20you%20don't%20actually%20get%20a%20new%20token%20with%20the%20updated%20permissions%20until%20the%20cached%20token%20expires.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FIDENTITY-NAME%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3EModify%20connection%20string%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ERemember%20that%20the%20same%20changes%20you%20made%20in%26nbsp%3BWeb.config%26nbsp%3Bor%26nbsp%3Bappsettings.json%26nbsp%3Bworks%20with%20the%20managed%20identity%2C%20so%20the%20only%20thing%20to%20do%20is%20to%20remove%20the%20existing%20connection%20string%20in%20App%20Service%2C%20which%20Visual%20Studio%20created%20deploying%20your%20app%20the%20first%20time.%20Use%20the%20following%20command%2C%20but%20replace%26nbsp%3B%3CAPP-NAME%3E%26nbsp%3Bwith%20the%20name%20of%20your%20app.%3C%2FAPP-NAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eaz%20webapp%20config%20connection-string%20delete%20--resource-group%20myResourceGroup%20--name%20%3CAPP-NAME%3E%20--setting-names%20MyDbConnection%3C%2FAPP-NAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EYou%20could%20refer%20to%20our%20official%20documentation%20regarding%20this%20at%20%3C%2FSPAN%3E%3CA%20style%3D%22font-family%3A%20inherit%3B%20background-color%3A%20%23ffffff%3B%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fapp-service-web-tutorial-connect-msi%23grant-permissions-to-managed-identity%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETutorial%3A%20Access%20data%20with%20managed%20identity%20-%20Azure%20App%20Service%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGitHub%20Link%20%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fvijaysaayi%2FMSI-Validator%2Ftree%2Fmaster%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fvijaysaayi%2FMSI-Validator%2Ftree%2Fmaster%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1711597%22%20slang%3D%22en-US%22%3E%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3EAzure%20App%20Service%20supports%20an%20interesting%20feature%20called%20Managed%20Identity%20from%20Azure%20Active%20Directory.%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3EThis%20allows%20your%20App%20Service%20to%20easily%20connect%20to%20Azure%20Resources%20such%20as%20Azure%20KeyVault%2C%20Azure%20Storage%2C%20Azure%20SQL%20etc.%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3EYou%20could%20refer%20to%20our%20official%20documentation%20for%20more%20details%20on%20this%20feature%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Foverview-managed-identity%3Ftabs%3Ddotnet%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3EMSI-Validator%20helps%20you%20troubleshoot%20issues%20with%20Managed%20Identity%20on%20App%20Services.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1711597%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20App%20Service%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMobile%20Apps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWeb%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Azure App Services supports an interesting feature called Manage Identity from Azure Active Directory.
This allows your App Services to easily connect to Azure Resources such as Azure KeyVault, Azure Storage, Azure SQL . The complete list of resources that support this feature are available in the following document:
Azure Services that support managed identities - Azure AD | Microsoft Docs

You could refer to our documentation for more details on this feature here

MSI-Validator helps you troubleshoot issues with Managed Identity for Azure App Services.
The link to download this tool is available in the attachments section of the blog.

 

Installation Steps:

  1. Download the zip file from the attachments.
    Current version - v1.0.0.0
  2. Extract it to the local folder.
  3. Drag and drop "msi-validator.exe" to the Kudu console of the App Service (https://<webapp-name>.scm.azurewebsites.net)01- Download and installation.png

Commands:

  1. To Get an Access Token :
    msi-validator get-token -r <resource>​
    
    Valid Arguments for resource = keyvault, storage, sql
    Sample:
    msi-validator get-token -r keyvault
    msi-validator get-token -r storage
    msi-validator get-token -r sql
  2. To Test the connection
    msi-validator test-connection -r <resource> -e <endpoint>
    
    Valid Arguments for resource = keyvault, storage, sql
    
    Sample:
    
    msi-validator test-connection -r "keyvault" -e "https://<keyvault-name>.vault.azure.net/secrets/<secret-key>"
    msi-validator.exe test-connection -r storage -e https://<storage-name>.blob.core.windows.net/<container-name>/<blob-path>
    msi-validator.exe test-connection -r sql -e "Data Source=<server-name>.database.windows.net;Initial Catalog=<database-name>;"
    ​

Troubleshooting:

  1. From the Identity Blade of the App Service, ensure that Managed Identity is turned on.
    00 - check in azure portal.png
  2. Navigate to Kudu Console (https://<webapp-name>.scm.azurewebsites.net) > Environment Section and search for MSI (Ctrl + F)
    02 - check env variables.png

    The Environmental Variables "MSI_ENDPOINT" and "MSI_SECRET" would have been set automatically.

  3. Run the command "msi-validator get-token -r <resource>" and check if a token is being returned.
    03 - inspect the token.png
    An access token should be returned.
    Otherwise, it indicates that MSI service has issues reaching out to Azure Active Directory to fetch a token.


    Things to check :

    • Does the App Service have regional VNet Integration / is the App in ASE?
      Are there any User Defined Routes on the subnet to which the App Service is integrated ?
      If Yes , is the device to which the traffic is force tunneled, blocking any Azure Active Directory Dependency ?
    • Do you still face the issue if Managed Identity is disabled and enabled again ?

  4. Run the command "msi-validator test-connection -r <resource> -e "<endpoint>" " and check if data is returned from the resource or inspect the error message..

    KeyVault:
    From the below error message, we see that the App Service doesn’t have necessary permissions to access the KeyVault. 
    04 - keyvault issue.png
    Resolution:
  1. Navigate to the Access Policies Blade of KeyVault from the Azure Portal.
  2. Click on "+ Add Access Policy"
     05 - keyvault select access policies.png
  3. Provide the necessary permission.
    06 - select permissions.png
  4. Choose the Service Principal (name of the App Service)
    07 - select service principal.png

Storage:

08 - storage issue.png

Resolution :
Navigate to the Access Control IAM) > Add Role assignment and choose the necessary storage related permission. The roles should be configured as per your application's use case.
09 - storage role assginments.png

SQL:
The application could fail while connecting to Azure SQL using MSI with the error message: "Unable to connect to SQL. Exception : Login failed for user '<token-identified principal>'"

10 - sql issue.png

Resolution:
If you want, you can add the identity to an Azure AD group, then grant SQL Database access to the Azure AD group instead of the identity. For example, the following commands add the managed identity from the previous step to a new group called myAzureSQLDBAccessGroup: 

 

groupid=$(az ad group create --display-name myAzureSQLDBAccessGroup --mail-nickname myAzureSQLDBAccessGroup --query objectId --output tsv)
msiobjectid=$(az webapp identity show --resource-group myResourceGroup --name <app-name> --query principalId --output tsv)
az ad group member add --group $groupid --member-id $msiobjectid
az ad group member list -g $groupid

 

 

In the Cloud Shell, sign in to SQL Database by using the SQLCMD command. Replace <server-name> with your server name, <db-name> with the database name your app uses, and <aad-user-name> and <aad-password> with your Azure AD user's credentials.

 

 

sqlcmd -S <server-name>.database.windows.net -d <db-name> -U <aad-user-name> -P "<aad-password>" -G -l 30

 

 

In the SQL prompt for the database you want, run the following commands to grant the permissions your app needs. For example,

 

 

CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
ALTER ROLE db_datawriter ADD MEMBER [<identity-name>];
ALTER ROLE db_ddladmin ADD MEMBER [<identity-name>];
GO

 

 

<identity-name> is the name of the managed identity in Azure AD. If the identity is system-assigned, the name always the same as the name of your App Service app. To grant permissions for an Azure AD group, use the group's display name instead (for example, myAzureSQLDBAccessGroup).

Type EXIT to return to the Cloud Shell prompt.
The back-end services of managed identities also maintains a token cache that updates the token for a target resource only when it expires. If you make a mistake configuring your SQL Database permissions and try to modify the permissions after trying to get a token with your app, you don't actually get a new token with the updated permissions until the cached token expires.

Modify connection string

Remember that the same changes you made in Web.config or appsettings.json works with the managed identity, so the only thing to do is to remove the existing connection string in App Service, which Visual Studio created deploying your app the first time. Use the following command, but replace <app-name> with the name of your app.

 

 

az webapp config connection-string delete --resource-group myResourceGroup --name <app-name> --setting-names MyDbConnection

 

 

You could refer to our official documentation regarding this at Tutorial: Access data with managed identity - Azure App Service | Microsoft Docs

 

GitHub Link :

https://github.com/vijaysaayi/MSI-Validator/tree/master