title: Getting Repository Public Key in GitHub Actions
body: <p>I am using GitHub Actions to try and manage some of the secrets within one of the environments in the repository where Actions are being triggered (same repo, basically).</p>
  <p>I am using the hosted Windows runner, with the following command to try and get the public key for the environment through PowerShell:</p>
  <pre><code>$keyData = curl -H @{&quot;Accept&quot; = &quot;application/vnd.github.v3+json&quot;; &quot;Authorization&quot; = &quot;token $env:SL_GITHUB_TOKEN&quot;} https://api.github.com/repos/I_PUT_MY_ACCOUNT_HERE/MY_REPOSITORY_HERE_AS_WELL/environments/Production/secrets/public-key | ConvertFrom-Json
  </code></pre>
  <p>The <code>SL_GITHUB_TOKEN</code> enviroment variable is a Personal Access Token (PAT) with maximum permissions (every checkbox selected when creating through the GitHub UI).</p>
  <p>However, when the code is executed <em>within</em> the GitHub Actions runner, I get an error:</p>
  <pre><code>message           : Must have admin rights to Repository.
  documentation_url : https://docs.github.com/rest/reference/actions#get-an-environment-public-key
  </code></pre>
  <p>This is odd, because I can run the <em>exact</em> same command locally on my computer, with the same PAT, and get the correct output (the public key, as expected).</p>
  <p>To make sure that the REST API is actually accessible in GitHub Actions runner, within the exact same step I added another command that uses the exact same PAT:</p>
  <pre><code>$userData = curl -H @{&quot;Accept&quot; = &quot;application/vnd.github.v3+json&quot;; &quot;Authorization&quot; = &quot;token $env:SL_GITHUB_TOKEN&quot;} https://api.github.com/users/MY_USER_NAME_ON_GH | ConvertFrom-Json
  </code></pre>
  <p>The correct data was returned, so it seems like something funky is going on with the Secrets API.</p>
  <p>What could be the issue here? Is it just the Secrets API that needs special permissions <em>within</em> the runner that I am missing? It's clearly not the PAT since the same token can be used locally with no issues.</p>