Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spn cleanup #12

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/deploy/destroy-spns.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
param (
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]
$environmentName="",

[Parameter(Mandatory=$false)]
[string]
$uniqueRunId
)

az account show

###############################################################################################
# Configure names and options
###############################################################################################
Write-Host "Initialize deployment" -ForegroundColor Green

# import utility functions
. "$PSScriptRoot\Utilities\all.ps1"

. "$PSScriptRoot\steps\00-Config.ps1"


###############################################################################################
# Delete spns
###############################################################################################
Write-Host " Now destroying SPN $dbDeploySpnName !" -ForegroundColor Red
$appId = az ad app list `
--display-name $dbDeploySpnName `
--query [-1].appId `
--out tsv

Graph-DeleteApplication --appId $appId

Write-Host " Now destroying SPN $mountSpnName !" -ForegroundColor Red
$appId = az ad app list `
--display-name $mountSpnName `
--query [-1].appId `
--out tsv

Graph-DeleteApplication --appId $appId

###############################################################################################
# Purge secrets
###############################################################################################

Write-Host " Now purging secret for $dbDeploySpnName !" -ForegroundColor Red
LauJohansson marked this conversation as resolved.
Show resolved Hide resolved
az keyvault secret purge --name $dbDeploySpnName --vault-name $keyVaultName

Write-Host " Now purging secret for $mountSpnName !" -ForegroundColor Red
az keyvault secret purge --name $mountSpnName --vault-name $keyVaultName

Write-Host " SPNs Deleted" -ForegroundColor Green
28 changes: 28 additions & 0 deletions .github/workflows/spn-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# This pipeline can be runned if the SPNs needs to be destroyed
# In this way, it is easier to clean up the SPNs, instead of manually removing them in the portal
name: Spn-Cleanup

on:
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
concurrency:
group: azure-integration
cancel-in-progress: true

steps:
- uses: actions/checkout@v2
- name: Log in to azure
shell: pwsh
run: |
az login --service-principal `
-u ${{ secrets.SPN_CLIENT_ID }} `
-p ${{ secrets.SPN_CLIENT_SECRET }} `
--tenant ${{ secrets.SPN_TENANT_ID }}
- name: Delete Deployment
shell: pwsh
run: |
.github/deploy/destroy-spns.ps1