Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github.ActionsEnvironmentSecret gives 404 Not Found #248

Open
phitoduck opened this issue Oct 1, 2022 · 5 comments · Fixed by zemn-me/monorepo-old#12
Open

github.ActionsEnvironmentSecret gives 404 Not Found #248

phitoduck opened this issue Oct 1, 2022 · 5 comments · Fixed by zemn-me/monorepo-old#12
Labels
awaiting-upstream Awaiting upstream dependency kind/bug Some behavior is incorrect or out of spec

Comments

@phitoduck
Copy link

phitoduck commented Oct 1, 2022

What happened?

Hi there,

TL;DR I believe github.ActionsEnvironmentSecret may be hitting an out of date GitHub endpoint.

I'm trying to create a new github.Repository via Pulumi and also create 3 GitHub actions environments with several secrets in each.

This forum answer made me realize you have to encrypt strings before you can send them to the GitHub API via the pulumi resource.

The github.get_actions_public_key(repository) recommended in the forum answer calls this endpoint (GitHub docs on the endpoint here) to fetch the "GitHub environment public key".

Here is the error message I get on pulumi up when I try to do this:

Diagnostics:
  github:index:ActionsEnvironmentSecret (Sandbox-environment--environment--env-secret):
    error: GET https://api.github.com/repositories/543829938/environments/sample-repo:Sandbox/secrets/public-key: 404 Not Found []

Note the repository URL is 543829938 in this example, and the environment name is Sandbox. The repo name is sample-repo.

I was able to reproduce the error by hitting the GitHub API myself like so:

REPO_ID=543829938
ENVIRONMENT_NAME=Sandbox
REPO_NAME=sample-repo
curl \
    -H "Accept: application/vnd.github+json" \
    -H "Authorization: Bearer $GITHUB_TOKEN" \
    https://api.github.com/repositories/$REPO_ID/environments/$REPO_NAME:$ENVIRONMENT_NAME/secrets/public-key

# result
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/actions#get-an-environment-public-key"
}

I was able to solve it by removing the $REPO_NAME: portion of the request path:

REPO_ID=543829938
ENVIRONMENT_NAME=Sandbox
REPO_NAME=sample-repo
curl \
    -H "Accept: application/vnd.github+json" \
    -H "Authorization: Bearer $GITHUB_TOKEN" \
    https://api.github.com/repositories/$REPO_ID/environments/$ENVIRONMENT_NAME/secrets/public-key

# response
{
  "key_id": "568250167242549743",
  "key": "4sJ/GHfjfYtb6kE0+CazB6MopDEiJ1E22Gh4ntzN+Cw="
}

Can the underlying provider be modified so that the correct URL endpoint is used?

Steps to reproduce

from base64 import b64encode
from nacl import encoding, public # pip install pynacl

def encrypt_github_action_secret(public_encryption_key: str, secret_value: str) -> str:
    """
    Encrypt a Unicode string using the public key.

    The implementation for this function came from the GitHub API docs here:
    https://docs.github.com/en/rest/actions/secrets#create-or-update-an-organization-secret

    We found that by landing on this forum question on how to create GitHub Actions secrets:
    https://github.com/pulumi/pulumi/discussions/9377
    """
    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")


repo = github.Repository(
    resource_name="sample-repo",
    name="sample-repo",
    archive_on_destroy=False,
)

public_key = github.get_actions_public_key(repository=repo)

env = github.RepositoryEnvironment(
    resource_name=f"sandbox-environment",
    repository=repo,
    environment="Sandbox",
)

encrypted_secret = encrypt_github_action_secret(public_encryption_key=public_key.key, secret_value="I'm a secret!")
github.actions_environment_secret.ActionsEnvironmentSecret(
    resource_name=f"{env._name}--{secret_name.lower()}--env-secret",
    secret_name=secret_name,
    encrypted_value=encrypted_secret,
    environment=env,
    repository=env.repository,
)

Expected Behavior

A public key is fetched.

Actual Behavior

A public key is not found, instead a 404 error is returned.

View Live: https://app.pulumi.com/phitoduck/repogen/repogen/updates/22

     Type                                      Name                                              Status                  Info
     pulumi:pulumi:Stack                       repogen-repogen                                   **failed**              1 error
 +   └─ github:index:ActionsEnvironmentSecret  Sandbox-environment--environment--env-secret   **creating failed**     1 error
 
Diagnostics:
  github:index:ActionsEnvironmentSecret (Sandbox-environment--environment--env-secret):
    error: GET https://api.github.com/repositories/543829938/environments/sample-repo:Sandbox/secrets/public-key: 404 Not Found []

Output of pulumi about

CLI          
Version      3.40.2
Go Version   go1.19.1
Go Compiler  gc

Plugins
NAME    VERSION
github  5.0.0
python  unknown

Host     
OS       darwin
Version  10.15.7
Arch     x86_64

This project is written in python: executable='/Users/eric/.pyenv/shims/python3' version='3.10.4
'

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/phitoduck
User           phitoduck
Organizations  phitoduck

Dependencies:
NAME              VERSION
GitPython         3.1.27
phitoduck-projen  0.0.2
pip               22.2.2
pulumi-github     5.0.0
PyNaCl            1.5.0
python-dotenv     0.21.0
rich              12.5.1
setuptools        65.4.0
wheel             0.37.1

Pulumi locates its logs in /var/folders/cn/6x3hstc532b_gdnvrvn0p7600000gp/T/ by default

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@phitoduck phitoduck added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Oct 1, 2022
@phitoduck
Copy link
Author

This seems related, but not the same as #246

@phitoduck phitoduck changed the title github.get_actions_public_key(repository) returns 404 Not Found githubActionsEnvironmentSecret gives 404 Not Found Oct 1, 2022
@phitoduck phitoduck changed the title githubActionsEnvironmentSecret gives 404 Not Found github.ActionsEnvironmentSecret gives 404 Not Found Oct 1, 2022
@Frassle
Copy link
Member

Frassle commented Oct 1, 2022

Possibly related to integrations/terraform-provider-github#667

@lblackstone
Copy link
Member

Could this be related to integrations/terraform-provider-github#578?

integrations/terraform-provider-github#578 (comment) suggests setting the owner field of the Provider configuration as a workaround.

@lblackstone lblackstone added awaiting-upstream Awaiting upstream dependency and removed needs-triage Needs attention from the triage team labels Oct 3, 2022
@robsoned
Copy link

I'm also having a related problem here.

image

When I run pulumi up locally, it does work and create the GitHub secret. But, when running with GitHub actions, it seems to duplicate the GITHUB_OWNER in the URL:

Error: **creating failed** error: GET https://api.github.com/repos/{GITHUB_OWNER}/{GITHUB_OWNER}/repository: 404 Not Found []

Github Action:

image
image

When I try removing the GITHUB_OWNER, the instead of duplicating GITHUB_OWNER. It adds my github username to the url:

github:index:ActionsEnvironmentSecret  creating (0s) error: GET https://api.github.com/repos/robsoned/{GITHUB_OWNER}/repo: 404 Not Found []

Maybe I'm missing something here, I'm passing the exact same env variables that I use locally to the GitHub actions.

Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 2, 2023
@Zemnmez
Copy link

Zemnmez commented Oct 2, 2023

I'm also having a similar (but not the same) issue:

  
    github:index:ActionsSecret (monorepo_bazel_remote_cache_server_actions_secret_cache_url):
      error: GET https://api.github.com/repos//zemn-me/monorepo/actions/secrets/public-key: 404 Not Found []

It looks like, somehow, there's an extra slash being interpolated for me. I tried to use the workaround above and it didn't fix the issue. Any suggestions?

Edit: managed to work around it by adding ../ before my repo name; it's now ../my-org/my-repo.

Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 2, 2023
github-merge-queue bot pushed a commit to zemn-me/monorepo-old that referenced this issue Oct 24, 2023
github-merge-queue bot pushed a commit to zemn-me/monorepo-old that referenced this issue Oct 24, 2023
Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 25, 2023
Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 25, 2023
Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 25, 2023
Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 25, 2023
Zemnmez added a commit to zemn-me/monorepo-old that referenced this issue Oct 25, 2023
* Revert "I think this should finally fix the issues..."

This reverts commit a2651d0.

* Revert "see if removing GITHUB_OWNER will make pulumi / tf happier"

This reverts commit eb9696f.

* Revert "try one last time to see if I can meddle with the repo name to get the github integration to work"

This reverts commit f35a857.

* Revert "- provide GITHUB_TOKEN to Staging (oops)"

This reverts commit 1f6ab05.

* Revert "remove presubmit requirement for staging"

This reverts commit d7e3dc3.

* Revert "Remove the insanely expensive NAT gateway and test for missing"

This reverts commit 5d86ec7.

* Revert "re introduce ../ to see if we can make the bastard Actions secret.'"

This reverts commit 2647abf.

* Revert "follow aws provided example better https://github.com/aws-samples/container-patterns/blob/ea823c0c43a0818e1d1e73ea0b646846af504563/pattern/pulumi-ecs-service-in-vpc/files/service-in-vpc.ts\#L17"

This reverts commit 352a3f0.

* Revert "instruct the Fargate service to wait on the internet gateway and nat gateways on a hunch"

This reverts commit 10a0dc0.

* Revert "move listener out of awsx/alb -- couldnt work out how to correctly specify ARN."

This reverts commit 565587a.

* Revert "fixes"

This reverts commit 0184110.

* Revert "fix missed parent"

This reverts commit 47e9309.

* Revert "fix alb name"

This reverts commit 91461b2.

* Revert "progress"

This reverts commit e05fc98.

* Revert "progress"

This reverts commit d8b3bbf.

* Revert "remove code that didnt do anything"

This reverts commit 7d6e9fd.

* Revert "fix build in ts/pulumi/..."

This reverts commit 67826bf.

* Revert "Manually add transient peer @aws-sdk/region-config-resolver"

This reverts commit 81d1615.

* Revert "upgrade aws-sdk in an attempt to get @aws-sdk/region-config-resolver available"

This reverts commit 54465eb.

* Revert "- Add @aws-sdk/region-config-resolver (pulumi was complaining"

This reverts commit f67876f.

* Revert "Attempt to fix Pulumi dependency issue by upgrading deps."

This reverts commit 379626e.

* Revert "Change error to warning for Pulumi testing."

This reverts commit 8759be5.

* Revert "Try to test if the GitHub credentials are incorrect."

This reverts commit 14636e7.

* Revert "Try to see if we can use the correct repo name again."

This reverts commit a00b58c.

* Revert "try to automagically get a gateway set up. also i need to fix pulumi which was interrupted in a broken state apparently"

This reverts commit 8e28892.

* Revert "currently there is a problem where the fargate compute units cannot access the outside internet. perhaps this will fix it..."

This reverts commit 0814c09.

* Revert "I hope this counts as progress"

This reverts commit 5c331db.

* Revert "many changes"

This reverts commit a1906bc.

* Revert "giving up for the night. i might have to implement this awsx feature myself, because i dont know why its trying to proxy :https"

This reverts commit 5650545.

* Revert "try to fix 443 error..."

This reverts commit f89f7c8.

* Revert "try to correct ports"

This reverts commit 14d412e.

* Revert "correct ports"

This reverts commit 9127801.

* Revert "public IP"

This reverts commit adfd3ad.

* Revert "write the dockerfile instead of just trying to send its text"

This reverts commit bf58a88.

* Revert "expose ALB directly to the internet"

This reverts commit 3774738.

* Revert "just a minor push to force a redeploy"

This reverts commit 127f167.

* Revert "fix formatting"

This reverts commit 68a892b.

* Revert "oops"

This reverts commit c7cc113.

* Revert "add new access token and create staging secret"

This reverts commit f95b9cd.

* Revert "crazy hack that just might work to fix pulumi/pulumi-github#248"

This reverts commit cd94510.

* Revert "fix for pulumi/pulumi-github#248"

This reverts commit fa089a1.

* Revert "the api is annoying. so we are doing this instead"

This reverts commit b09d530.

* Revert "use fullName with actions secret"

This reverts commit ec218df.

* Revert "set GITHUB_TOKEN for pulumi access"

This reverts commit 6a52c00.

* Revert "update bazel_rce code to github org monorepo"

This reverts commit d231257.

* Revert "Bazel remote caching"

This reverts commit 9929e93.

* re-add access to GITHUB_TOKEN so old infra can be torn down.

* add dummy bootstrap_bazel_remote_cache.sh

* chmod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-upstream Awaiting upstream dependency kind/bug Some behavior is incorrect or out of spec
Projects
None yet
5 participants