-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add workflow that rotates client secrets in azure automatically #87
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
Open
barkerl
wants to merge
5
commits into
main
Choose a base branch
from
feat/reusable-azuretoken-rotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d0ed433
feat: add workflow that rotates client secrets in azure automatically
barkerl 9f946fc
fix: improve imputs to make this more flexible on workflow call
barkerl 68120c0
chore: remove checkout as it isn't needed
barkerl c9bbdaa
chore: add documentation to readme and amend secrets
barkerl db3fa27
chore: amend name
barkerl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: Rotate Azure Client Secret and Push to AWS Secrets Manager | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| aws-secret-id: | ||
| description: "Name of the AWS secret containing Azure client credentials" | ||
| required: true | ||
| type: string | ||
| aws-account-id: | ||
| description: "AWS Account ID where the secret is stored" | ||
| required: true | ||
| type: string | ||
| aws-github-actions-role: | ||
| description: "The role to assume in AWS to access Secrets Manager" | ||
| required: true | ||
| type: string | ||
| aws-region: | ||
| description: "AWS region where the secret is stored" | ||
| required: false | ||
| type: string | ||
| default: "eu-west-1" | ||
|
|
||
| secrets: | ||
| AZURE_TENANT_ID: | ||
| description: "Azure Tenant ID" | ||
| required: true | ||
| AZURE_SUBSCRIPTION_ID: | ||
| description: "Azure Subscription ID" | ||
| required: true | ||
| AZURE_OIDC_CLIENT_ID: | ||
| description: "Azure AD App (client) ID for OIDC login" | ||
| required: true | ||
|
|
||
| jobs: | ||
| rotate-and-push: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
|
|
||
| # Logs into Azure using OIDC, requires the inputs azure-oidc-client-id, azure-tenant-id and azure-subscription-id to be set in the repo secrets. These are set as inputs to provide some flexibility for adoption. Also requires an OIDC federated credential to be set up in the Azure AD App registration that requires Microsoft Graph API permissions (like Application.ReadWrite.All) to reset app credentials | ||
| - name: Azure login with OIDC | ||
| uses: azure/login@v1 | ||
| with: | ||
| client-id: ${{ secrets.AZURE_OIDC_CLIENT_ID }} | ||
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | ||
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: arn:aws:iam::${{ inputs.aws-account-id }}:role/${{ inputs.aws-github-actions-role }} | ||
| aws-region: ${{ inputs.aws-region }} | ||
|
|
||
| # Need to ensure that secret-id maps to what is stored in AWS Secrets Manager, static for now. | ||
| - name: Retrieve clientId | ||
| id: get-clientid | ||
| run: | | ||
| CLIENT_ID=$(aws secretsmanager get-secret-value \ | ||
| --secret-id "${{ inputs.aws-secret-id }}" \ | ||
| --query SecretString \ | ||
| --output text | jq -r '.clientId') | ||
|
|
||
| echo "::add-mask::$CLIENT_ID" | ||
| echo "CLIENT_ID=$CLIENT_ID" >> $GITHUB_ENV | ||
|
|
||
| - name: Create new client secret | ||
| run: | | ||
| NEW_SECRET=$(az ad app credential reset \ | ||
| --id $CLIENT_ID \ | ||
| --append \ | ||
| --years 1 \ | ||
| --query password -o tsv) | ||
|
|
||
| echo "::add-mask::$NEW_SECRET" | ||
| echo "AZURE_NEW_SECRET=$NEW_SECRET" >> $GITHUB_ENV | ||
|
|
||
| - name: Update AWS secret | ||
| run: | | ||
| aws secretsmanager put-secret-value \ | ||
| --secret-id "${{ inputs.aws-secret-id }}" \ | ||
| --secret-string "{\"clientId\":\"$CLIENT_ID\",\"clientSecret\":\"$AZURE_NEW_SECRET\"}" | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow looks good to me, the only query I have is re this last bit.
Would it make sense that
AZURE_NEW_SECRETis an output to this workflow instead of updating in place?Currently, for example, the equivalent CVS secret has more detail that just clientId & clientSecret in the JSON, therefore this would overwrite those extra values.
The other option would be we retrieve the secret as is and merge the two objects together, which will update these keys but also retain the other contents?