|
1 | | -# automatically-create-github-secrets |
2 | | -from azure keyvault pull secrets and using them update or create github secrets in a specified repo |
| 1 | +# automatically-create-delete-update-github-organization-secrets |
| 2 | +create , delete or update github organization secrets using github workflow |
| 3 | + |
| 4 | +# Pre requesites |
| 5 | +* This requires an authorization method which has organization-secret with write permission |
| 6 | +* Personal Access Token (PAT) is the recommended way to authenticate. In this demo PAT is USED. |
| 7 | +* You can generate a new one from Github settings |
| 8 | +* You need to encrypt a secret before you can create or update secrets. |
| 9 | + |
| 10 | + |
| 11 | +# How code works for create or update secret |
| 12 | + |
| 13 | + |
| 14 | +* First this will execute the `get_public_key.sh` shell script to get the Organization public key |
| 15 | + * This public key is required and used for encryption of secret |
| 16 | + |
| 17 | + `Reference`: [get-an-organization-public-key](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-organization-public-key) |
| 18 | + |
| 19 | +* Then it will execute the `get_public_key_id.sh` script to get the organization key id. |
| 20 | + * This is required for creation or updation of secret |
| 21 | + |
| 22 | +* Then the `python program` `encrypt_using_libnacl` this uses the public key from step 1 and encrypts the secret |
| 23 | +using the prefered method by GitHub. |
| 24 | + |
| 25 | + `Reference`: [create-or-update-an-organization-secret](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret) |
| 26 | + |
| 27 | + - Reference used for encryption : [example-encrypting-a-secret-using-python](https://docs.github.com/en/rest/guides/encrypting-secrets-for-the-rest-api?apiVersion=2022-11-28#example-encrypting-a-secret-using-python ) |
| 28 | + |
| 29 | +* Then `Python program` `create_or_update_github_org_secret` is used to take the public key id from step 2 and encrypted secret value from step 3 to create or update the secret. |
| 30 | + |
| 31 | +| status code | operation | |
| 32 | +|-------------|-----------| |
| 33 | +| 201 | Create Org secret| |
| 34 | +| 204 | Update an Org secret | |
| 35 | + |
| 36 | + |
| 37 | +- visibility of organization secret has been set to all organization repositories. selected means only the repositories specified by selected_repository_ids can access the secret. |
| 38 | +- Can be one of: `all`, `private`, `selected` |
| 39 | + |
| 40 | + |
| 41 | +## Inputs of workflow |
| 42 | + |
| 43 | +| input name | description| |
| 44 | +|------------|------------| |
| 45 | +| organization | name of github organization | |
| 46 | +| secret_name | organization Secret name | |
| 47 | +| secret_value | Secret value | |
| 48 | + |
| 49 | + |
| 50 | +# # How code works for deleting an organization secret |
| 51 | + |
| 52 | +* This runs the shell script `delete_github_org_secret.sh` which takes 2 inputs from github workflow |
| 53 | +1. organization name |
| 54 | +2. secret name |
| 55 | + |
| 56 | +* Then deletes the secret |
| 57 | + |
| 58 | +| input | description| |
| 59 | +|-------|--------------| |
| 60 | +| organization | GitHub Organization name | |
| 61 | +| secret_name | Secert to be deleted | |
| 62 | + |
0 commit comments