icy-chef-34317
08/02/2024, 11:51 AMerror: 1 error occurred:
* PUT <https://api.github.com/repositories/REPO_ID/environments/ENVIRONMENT_NAME/secrets/CLIENT_ID>: 422 Bad request - validation failed due to an improperly encrypted secret []
I have tried the procedure outlined here:
https://docs.github.com/en/rest/guides/encrypting-secrets-for-the-rest-api?apiVersion=2022-11-28#example-encrypting-a-secret-using-python
as well as the one in those two Github issues but I had no luck.
When I try to get the repository key I am getting two different values, depending on what I use.
If I try to get the public key through Pulumi, using the get_actions_public_key function I get one value.
If I try to get using the Github CLI and the API I get another value.
Halp pls.modern-zebra-45309
08/02/2024, 11:57 AMmodern-zebra-45309
08/02/2024, 11:59 AMicy-chef-34317
08/02/2024, 12:06 PM#Github repository public key
public_key=github.get_actions_public_key(
repository="DevOps",
)
#repository
existing_repo=github.get_repository(
full_name="organization/DevOps",
)
#repository environment
test_env=github.RepositoryEnvironment(
"test-env",
repository=existing_repo.name,
environment="test",
can_admins_bypass=True
)
# function to encrypt the secret's value
# this is based off pynacl
def encrypt_github_action_secret(public_encryption_key: str, secret_value: str) -> str:
public_key = public.PublicKey(public_encryption_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")
encrypted_secret = encrypt_github_action_secret(public_encryption_key=public_key.key, secret_value="whatever")
# creating the actual environment secret
github.ActionsEnvironmentSecret(
"test-client-id",
environment=test_env.environment,
repository="DevOps",
secret_name="CLIENT_ID",
encrypted_value=encrypted_secret,
)
icy-chef-34317
08/02/2024, 12:11 PMicy-chef-34317
08/02/2024, 12:11 PMmodern-zebra-45309
08/02/2024, 12:18 PMmodern-zebra-45309
08/02/2024, 12:19 PMicy-chef-34317
08/02/2024, 12:58 PMicy-chef-34317
08/02/2024, 12:59 PMicy-chef-34317
08/02/2024, 1:01 PMicy-chef-34317
08/02/2024, 1:02 PMicy-chef-34317
08/02/2024, 1:02 PMfuture-hairdresser-70637
08/02/2024, 1:02 PMfuture-hairdresser-70637
08/02/2024, 1:04 PMsealed_box.encrypt
returns a "composed ciphertext", containing both the public part of the keypair and the ciphertext proper, encoded with the encoder."modern-zebra-45309
08/02/2024, 1:05 PMmodern-zebra-45309
08/02/2024, 1:06 PMicy-chef-34317
08/02/2024, 1:09 PMmodern-zebra-45309
08/02/2024, 1:11 PMicy-chef-34317
08/02/2024, 1:13 PMicy-chef-34317
08/02/2024, 1:14 PMmodern-zebra-45309
08/02/2024, 1:14 PMicy-chef-34317
08/02/2024, 1:14 PMmodern-zebra-45309
08/02/2024, 1:14 PMicy-chef-34317
08/02/2024, 1:14 PMmodern-zebra-45309
08/02/2024, 1:15 PMicy-chef-34317
08/02/2024, 1:15 PMicy-chef-34317
08/02/2024, 1:16 PMicy-chef-34317
08/02/2024, 1:16 PMicy-chef-34317
08/02/2024, 1:16 PMmodern-zebra-45309
08/02/2024, 1:16 PMicy-chef-34317
08/02/2024, 1:17 PMicy-chef-34317
08/02/2024, 1:17 PMmodern-zebra-45309
08/02/2024, 1:17 PMfuture-hairdresser-70637
08/02/2024, 1:18 PMicy-chef-34317
08/02/2024, 1:18 PMmodern-zebra-45309
08/02/2024, 1:18 PMmodern-zebra-45309
08/02/2024, 1:19 PMeven if I plug the key I got using the curl it's still not workingBut can you do it fully via curl?
future-hairdresser-70637
08/02/2024, 1:20 PMgh
doesicy-chef-34317
08/02/2024, 1:20 PMicy-chef-34317
08/02/2024, 1:20 PMicy-chef-34317
08/02/2024, 1:21 PMicy-chef-34317
08/02/2024, 1:21 PMicy-chef-34317
08/02/2024, 1:22 PMfuture-hairdresser-70637
08/02/2024, 1:22 PMicy-chef-34317
08/02/2024, 1:37 PMicy-chef-34317
08/02/2024, 1:37 PMicy-chef-34317
08/02/2024, 1:37 PMicy-chef-34317
08/02/2024, 1:37 PMfuture-hairdresser-70637
08/02/2024, 1:40 PMfuture-hairdresser-70637
08/02/2024, 2:43 PMplaintext_value
via pulumi the PUT request's secret value to github is encrypted in transit, so you could use a pulumi secret to keep the value encrypted at rest and it would be sent encrypted to github. verified via local proxyfuture-hairdresser-70637
08/02/2024, 2:43 PM