Skip to content

Commit c52ca29

Browse files
DEVOPS-41 completed tests
1 parent bd1fcf7 commit c52ca29

File tree

5 files changed

+121
-8
lines changed

5 files changed

+121
-8
lines changed

.github/dependabot.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
day: wednesday
8+
# Assignees to set on pull requests
9+
assignees:
10+
- "githubofkrishnadhas"
11+
# prefix specifies a prefix for all commit messages. When you specify a prefix for commit messages,
12+
# GitHub will automatically add a colon between the defined prefix and the commit message provided the
13+
# defined prefix ends with a letter, number, closing parenthesis, or closing bracket.
14+
commit-message:
15+
prefix: "dependabot python package"
16+
# Use reviewers to specify individual reviewers or teams of reviewers for all pull requests raised for a package manager.
17+
reviewers:
18+
- "devwithkrishna/admin"
19+
# Raise pull requests for version updates to pip against the `main` branch
20+
target-branch: "main"
21+
# Labels on pull requests for version updates only
22+
labels:
23+
- "pip dependencies"
24+
# Increase the version requirements for Composer only when required
25+
versioning-strategy: increase-if-necessary
26+
# Dependabot opens a maximum of five pull requests for version updates. Once there are five open pull requests from Dependabot,
27+
# Dependabot will not open any new requests until some of those open requests are merged or closed.
28+
# Use open-pull-requests-limit to change this limit.
29+
open-pull-requests-limit: 10
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: github-get-secrets-from-azure-kv-and-configure-as-repo-secrets
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
keyvault_name:
6+
required: true
7+
type: string
8+
description: 'key vault name'
9+
default: ''
10+
repo_search_string:
11+
required: true
12+
type: string
13+
description: 'github repo name search string'
14+
default: ''
15+
16+
jobs:
17+
github-get-secrets-from-azure-kv-and-configure-as-repo-secrets:
18+
runs-on: ubuntu-latest
19+
env:
20+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
21+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
22+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: set up python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.11'
32+
33+
- name: package installations
34+
run: |
35+
pip install poetry
36+
poetry install
37+
38+
- name: run python program
39+
run: |
40+
poetry run python3 main.py --keyvault_name ${{ github.event.inputs.keyvault_name }} \
41+
--repo_search_string ${{ github.event.inputs.repo_search_string }}
42+
- name: job completed
43+
run: echo "Job is completed"
44+

README.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,61 @@ Fetch Specific Secrets from Azure key vault and configure as repo secrets
44

55
# Mandatory Environment variables
66

7-
The below are used for authentication and programatical usage
7+
* The below one is used to determine the owner of repo. This is a environment variable provided by GitHub.
88

99
```commandline
10-
AZURE_CLIENT_ID
11-
AZURE_TENANT_ID
12-
AZURE_CLIENT_ID
10+
GITHUB_REPOSITORY_OWNER
1311
```
1412

15-
The below one is used to determine the owner of repo. This is a environment variable provided by GitHub.
13+
* GH_APP_TOKEN --> This is GitHub App installation token generated by using action `https://github.com/marketplace/actions/create-a-github-app-installation-access-token`
14+
This token is used for all API calls.
15+
16+
17+
# What is been done here
18+
19+
* This is the proof of concept of updating github secrets from SECRETS present in azure KV
20+
21+
* Specific SECRETS are pulled from keyvault and update in multiple repos in a single stretch
22+
23+
* Here we are pulling secrets named ARM-CLIENT-ID and ARM-CLIENT-SECRET in a KV and update them in repo secrets.
24+
25+
* Also TENANT ID and SUBSCRIPTION ID of the KEY vault are also added a github secrets
26+
27+
28+
| Secret name in Keyvault | GitHub Secret name |
29+
|-------------------------|--------------------|
30+
| ARM-CLIENT-ID | ARM_CLIENT_ID |
31+
| ARM-CLIENT-SECRET | ARM_CLIENT_SECRET |
32+
| Subscription ID | ARM_SUBSCRIPTION_ID |
33+
| Tenant ID | ARM_TENANT_ID |
34+
35+
![repo-secrets.png](repo-secrets.png)
36+
37+
* `pynacl` is used to encrypt the secrets
38+
39+
* GitHub REST API is used to get details like repo names, repo public keys, repo public key ids etc.
40+
41+
* Auth to GitHub is done using, GitHub App installation token generated by using action `https://github.com/marketplace/actions/create-a-github-app-installation-access-token`
42+
This token is used for all API calls.
43+
44+
* Authentication to Azure is done using azure-identity package using service principal with secret as credentials.
45+
The below envrionment variables are used for authentication and programatical usage
1646

1747
```commandline
18-
GITHUB_REPOSITORY_OWNER
48+
AZURE_CLIENT_ID
49+
AZURE_TENANT_ID
50+
AZURE_CLIENT_SECRET
1951
```
2052

21-
GH_APP_TOKEN --> This is GitHub App installation token generated by using action `https://github.com/marketplace/actions/create-a-github-app-installation-access-token`
22-
This token is used for all API calls.
53+
# How code works
2354

55+
1. First uses GitHub rest api repo end point to list out all the repositories and filters based on the the search string event
56+
2. Then loops over the repos matching the search input and gets the repo public key and repo public key id
57+
3. Once its done, it authentcates with azure gets the keyvault secrets ready for the above secrets `ARM-CLIENT-ID` & `ARM-CLIENT-SECRET`
58+
4. It will add the service principal to access policies to `secret permissions` - `get`, `list`, `set`
59+
5. Also in mean time it uses azure resource graph queries to get the subscription id, tenant id, key vault resource group etc.
60+
6. Using `public key`, `public key id` and the `secret value` fetched from keyvault using pynacl the secret value is encrypted which is passed to create repo secrets function.
61+
6. Once all the details are fetched like `ARM-CLIENT-ID`, `ARM-CLIENT-SECRET`, `SUBSCRIPTION ID` & `TENANT ID`, it prepares to
62+
create github secrets with names `ARM_CLIENT_ID`, `ARM_CLIENT_SECRET`, `ARM_SUBSCRIPTION_ID` & `ARM_TENANT_ID`
2463

64+
![github-secrets-from-azure-kv.jpg](github-secrets-from-azure-kv.jpg)

github-secrets-from-azure-kv.jpg

176 KB
Loading

repo-secrets.png

15.5 KB
Loading

0 commit comments

Comments
 (0)