Github secrets rotation

From UVOO Tech Wiki
Jump to navigation Jump to search
#!/bin/bash

# Authenticate to Azure (if not already authenticated)
az login

# Get the storage account access key
storage_account_name="your_storage_account_name"
storage_key=$(az storage account keys list --account-name $storage_account_name --query "[0].value" -o tsv)

# Encode the key for safe usage in the GitHub Actions API
encoded_key=$(echo "$storage_key" | base64 -w 0)

# Set the GitHub API URL and authorization header
github_api_url="https://api.github.com/repos/your_org/your_repo/actions/secrets/STORAGE_ACCOUNT_KEY"
authorization_header="Authorization: token your_personal_access_token"

# Update the secret using curl
curl -X PUT -H "$authorization_header" -H "Accept: application/vnd.github+json" -d "{\"encrypted_value\":\"$encoded_key\"}" "$github_api_url"