You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-8Lines changed: 48 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,61 @@ Fetch Specific Secrets from Azure key vault and configure as repo secrets
4
4
5
5
# Mandatory Environment variables
6
6
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.
8
8
9
9
```commandline
10
-
AZURE_CLIENT_ID
11
-
AZURE_TENANT_ID
12
-
AZURE_CLIENT_ID
10
+
GITHUB_REPOSITORY_OWNER
13
11
```
14
12
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
+

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
16
46
17
47
```commandline
18
-
GITHUB_REPOSITORY_OWNER
48
+
AZURE_CLIENT_ID
49
+
AZURE_TENANT_ID
50
+
AZURE_CLIENT_SECRET
19
51
```
20
52
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
23
54
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`
0 commit comments