Obtenez access_token à partir de IDENTITY_HEADER et IDENTITY_ENDPOINT : system('curl "$IDENTITY_ENDPOINT?resource=https://management.azure.com/&api-version=2017-09-01" -H secret:$IDENTITY_HEADER');.
Ensuite, interrogez l'API REST Azure pour obtenir l'ID d'abonnement et plus encore.
$Token ='eyJ0eX..'$URI ='https://management.azure.com/subscriptions?api-version=2020-01-01'# $URI = 'https://graph.microsoft.com/v1.0/applications'$RequestParams =@{Method ='GET'Uri = $URIHeaders =@{'Authorization'="Bearer $Token"}}(Invoke-RestMethod @RequestParams).value# List resources and check for runCommand privileges$URI = 'https://management.azure.com/subscriptions/b413826f-108d-4049-8c11-d52d5d388768/resources?api-version=2020-10-01'
$URI = 'https://management.azure.com/subscriptions/b413826f-108d-4049-8c11-d52d5d388768/resourceGroups/<RG-NAME>/providers/Microsoft.Compute/virtualMachines/<RESOURCE/providers/Microsoft.Authorization/permissions?apiversion=2015-07-01'
Version Azure API via Python
import requests# Remplacez 'your_subscription_id' et 'your_resource_group' par vos informationssubscription_id ='your_subscription_id'resource_group ='your_resource_group'api_version ='2021-04-01'resource_provider ='Microsoft.Compute'resource_type ='virtualMachines'resource_name ='your_vm_name'# URL de l'APIurl = f'https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/{resource_provider}/{resource_type}/{resource_name}?api-version={api_version}'
# En-têtes de la requêteheaders ={'Authorization':'Bearer '+'your_access_token','Content-Type':'application/json'}# Effectuer la requête GETresponse = requests.get(url, headers=headers)# Afficher la réponseprint(response.json())
Utilisation de l'API Azure avec PowerShell
# Remplacez 'your_subscription_id' et 'your_resource_group' par vos informations$subscriptionId ="your_subscription_id"$resourceGroup ="your_resource_group"$apiVersion ="2021-04-01"$resourceProvider ="Microsoft.Compute"$resourceType ="virtualMachines"$resourceName ="your_vm_name"# URL de l'API$url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/$resourceProvider/$resourceType/$resourceName?api-version=$apiVersion"
# En-têtes de la requête$headers =@{"Authorization"="Bearer your_access_token""Content-Type"="application/json"}# Effectuer la requête GET$response =Invoke-RestMethod-Uri $url -Headers $headers -Method Get# Afficher la réponse$response |ConvertTo-Json
import logging, osimport azure.functions as funcdefmain(req: func.HttpRequest) -> func.HttpResponse:logging.info('Python HTTP trigger function processed a request.')IDENTITY_ENDPOINT = os.environ['IDENTITY_ENDPOINT']IDENTITY_HEADER = os.environ['IDENTITY_HEADER']cmd = 'curl "%s?resource=https://management.azure.com&apiversion=2017-09-01" -H secret:%s' % (IDENTITY_ENDPOINT, IDENTITY_HEADER)
val = os.popen(cmd).read()return func.HttpResponse(val, status_code=200)
Liste des Services
Les pages de cette section sont classées par service Azure. Vous y trouverez des informations sur le service (comment il fonctionne et ses capacités) ainsi que sur la manière d'énumérer chaque service.