Using Azure Service Endpoints in Build vNext
Team members can benefit from Azure's ability to subscribe to service endpoints, allowing them to create builds that interact with Azure accounts without passwords or tokens.
Join the DZone community and get the full member experience.Join For Free
figure 1: azure file copy task configured in a vnext build
the nice part is the azure subscription setting that allows you to choose one of the azure endpoints configured for the project. using service endpoints, you can ask the person that has passwords/keys for an azure account to configure an endpoint. once it is configured it can be used by team members with sufficient right to access it, without requiring them to know the password or token or anything else .
thanks to services endpoints, you can allow members of the team to create builds that can interact with azure accounts without giving them any password or token
if you look around you'll find a nice blog post that explains how to connect your vsts account using a service principal .
figure 2: configure a service endpoint for azure with service principal authentication
another really interesting aspect of service endpoints, is the ability to choose people that can administer the account and people that can use the endpoint, thus giving you full security control over who can do what.
figure 3: you can manage security for each service endpoint configured
finally, using service endpoint, you have a centralized way to manage accessing your azure subscription resources , if for some reason a subscription should be removed and not used anymore, you can simply remove the endpoint. this is a better approach than having data and passwords or tokens scattered all over the vsts account (builds, etc).
i’ve followed all the steps in the article to connect your vsts account using a service principal , but when it was time to execute the azure file copy action, i got a strange error.
executing the powershell script: c:\lr\mms\services\mms\taskagentprovisioner\tools\agents\default\tasks\azurefilecopy\1.0.25\azurefilecopy.ps1 looking for azure powershell module at c:\program files (x86)\microsoft sdks\azure\powershell\servicemanagement\azure\azure.psd1 azurepscmdletsversion= 0.9.8.1 get-serviceendpoint -name 75a5dd41-27eb-493a-a4fb-xxxxxxxxxxxx -context microsoft.teamfoundation.distributedtask.agent.worker.common.taskcontext tenantid= ******** azuresubscriptionid= xxxxxxxx-xxxxxxx-xxxx-xxxx-xxxxxxxxxx azuresubscriptionname= msdn principal add-azureaccount -serviceprincipal -tenant $tenantid -credential $pscredential there is no subscription associated with account ********. select-azuresubscription -subscriptionid xxxxxxxx-xxxxxxx-xxxx-xxxx-xxxxxxxxxx the subscription id xxxxxxxx-xxxxxxx-xxxx-xxxx-xxxxxxxxxx doesn't exist. parameter name: id the switch-azuremode cmdlet is deprecated and will be removed in a future release. the switch-azuremode cmdlet is deprecated and will be removed in a future release. storage account: portalvhdsxxxxxxxxxxxxxxxxx1 not found. please specify existing storage account
this error is really strange because the first error line told me:
the subscription id xxxxxx-xxxxxx-xxxxxx-xxxxxxxxxxxxx doesn’t exist.
this cannot be the real error, because i’m really sure that my azure subscription is active and it is working everywere else. thanks to the help of roopesh nair , i was able to find my mistake. it turns out that the storage account i’m trying to access is an old one created with azure classic mode, and it is not accessible with service principal. a service endpoint using service principal can manage only azure resource manager-based entities.
shame on me because i was aware of this limitation, but for some reason i completely forgot it this time.
another sign of the problem is the error line telling me: storage account xxxxxxxxx not found, that should ring a warning bell about the script not being able to find that specific resource, because it was created with classic mode .
the solution is simple, i could use blob storage created with azure resource manager, or i can configure another service endpoint, this time based on a management certificate. the second option is preferrable, because having two service endpoints, one configured with service principal and the other configured with certificate allows me to manage all types of azure resources .
configuring an endpoint with a certificate is really simple. you should only copy data from the management certificate inside the endpoint configuration and you are ready to go.
figure 4: configure a certificate-based endpoint
now my build task's azure file copy works as expected and i can choose the right service endpoint based on what type of resource i should access (classic or arm).
Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.