I'm trying to create/update a GitHub secret using bash on Ubuntu.
Their api docs say that I should
- get the public key from the repo
- encrypt the secret with it
- create/update the GitHub secret
but examples are only in NodeJS & Python & I'm not sure how to use the libsodium which is mentioned in bash on Ubuntu to achieve what I need.
https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret
I was able to get the public key
& key_id
using
$ curl -s \
-H "authorization: Bearer $MY_ACCESS_TOKEN" \
https://api.github.com/repos/MYORG/MYREPO/actions/secrets/public-key
{
"key_id": "123456789012345678",
"key": "abcdHXZ2BrPAFPrZHy1AAct3B12k7BPgxXgdtxcABCo="
}
I was able to generate what seems to be a valid encrypted value of my secret using Python 3 example:
#!/usr/bin/python3
from base64 import b64encode
from nacl import encoding, public
def encrypt(public_key: str, secret_value: str) -> str:
public_key = public.PublicKey(public_key.encode("utf-8"), encoding.Base64Encoder())
sealed_box = public.SealedBox(public_key)
encrypted = sealed_box.encrypt(secret_value.encode("utf-8"))
return b64encode(encrypted).decode("utf-8")
print(encrypt("abcdHXZ2BrPAFPrZHy1AAct3B12k7BPgxXgdtxcABCo=", "ABCDEF1234"))
$ ./encrypt-secret.py
ST5Blke5GXO2FyMLUbYAhkmzLKJ3cljd1lI97q028gcrq3XC9aTqPlNzbMQAI5iHoj/70ao0/GOrhg==
But I'm looking for a bash implementation.