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

Error : Invalid actions OIDC token due to sub_invalid #9

Closed
BenSouchet opened this issue Jan 10, 2022 · 3 comments
Closed

Error : Invalid actions OIDC token due to sub_invalid #9

BenSouchet opened this issue Jan 10, 2022 · 3 comments

Comments

@BenSouchet
Copy link

Hi,
I try create a scheduled workflow that is identical to the pages-build-deployment workflows provided by Github for Pages.

I wanted to use the same actions (actions/jekyll-build-pages & actions/deploy-pages) but I have an issue (error) with actions/deploy-pages:

Failed to create deployment for ecdfe6d6276a0e9c2f5f1701e690bf8d69169602.
{"message":"Invalid actions OIDC token due to sub_invalid, validate around 1641819761.","documentation_url":"https://docs.github.com/rest/reference/repos#create-a-github-pages-deployment"}
Error: Error: Request failed with status code 400
Error: Error: Request failed with status code 400
Sending telemetry for run id 1677474470

This is the workflow I made:

permissions:
  contents: read
  pages: write
  id-token: write

name: Daily Build

# Controls when the workflow will run
on:
  # Triggers the workflow everyday
  # DEBUG: currently every 5mins
  schedule:
    - cron: '*/5 * * * *'
  workflow_dispatch:

# Workflow with two jobs: "Build" then "Deploy"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Build page with Jekyll
        uses: actions/jekyll-build-pages@v1-beta
        with:
          source: ./
          destination: ./_site
          future: false
      - name: Archive build output
        run: tar --dereference --hard-dereference --directory _site/ -cvf artifact.tar .
      - name: Upload Artifact
        uses: actions/upload-artifact@main
        with:
          name: github-pages
          path: ./artifact.tar
          if-no-files-found: warn

  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        uses: actions/deploy-pages@v1-beta

Is there anything more to do in order to use the deploy-pages action ?

I tried to understand if I needed to add or request a token but I admit being a little bit lost 🤔

@tcbyrd I'm sure you can tell me what i'm doing wrong 🙂

PS: link to one failed deploy

@BenSouchet
Copy link
Author

After a lot of research I managed to make the deployment work, here are the modifications I made:

permissions:
  contents: read
  pages: write
+ deployments: write
  id-token: write
...

  deploy:
    needs: build
    runs-on: ubuntu-latest
+   environment:
+     name: github-pages
+     url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: 'Deploy to GitHub Pages'
+       id: deployment
        uses: actions/deploy-pages@v1-beta

Don't understand exactly why theses lines was necessary, this does not seem to correlate with the error message I had.

If someone can tell me if what I added is correct, if everything is necessary (or not).
Thanks

@tcbyrd
Copy link
Collaborator

tcbyrd commented Jan 10, 2022

@BenSouchet that's correct. We'll be documenting it more thoroughly, but in general the reason for this is the deployment needs to know what environment you're attempting to deploy to, and this metadata is validated against the OIDC token to ensure we respect any environment protection rules that may exist. By default there are no protection rules (anyone with write can deploy to that environment), but the workflow needs to know what environment you're targeting so we can validate it.

Also you shouldn't need deployments: write in the token permissions. Actions has the ability to create the deployment natively when you add the environment stanza. The token permission is only needed if you want to use GITHUB_TOKEN to manually call the deployment API.

@BenSouchet
Copy link
Author

@tcbyrd Thanks for the explanation, It's more clear now 🙂

misirlou-tg added a commit to misirlou-tg/misirlou-tg.GitHub.io that referenced this issue Apr 4, 2022
chris34 added a commit to ubuntu-Deutschland-eV/verein.ubuntu-de.org that referenced this issue Apr 17, 2022
Environment variables define which branch & python version gets deployed.

For examples of the used github action see
actions/deploy-pages#20
actions/deploy-pages#9

Additional changes:

In https://github.com/ubuntu-Deutschland-eV/verein.ubuntu-de.org/settings/environments/
-> github-pages -> set deployment branches to 'selected branches' with 'master'
Thus, pushes to `gh-pages` can not deploy the branch (as it's done normally).
Nevertheless, the branch `gh-pages` will contain a file `CNAME` that holds
the custom domain name for the github page.
Additionaly, only the master branch can deploy a new version to github pages.

The domain `verein.ubuntu-de.org` is also verified to make takeovers harder
see https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/verifying-your-custom-domain-for-github-pages#verifying-a-domain-for-your-organization-site
muno92 added a commit to muno92/RegexTester that referenced this issue May 3, 2022
n8henrie added a commit to n8henrie/simplenet that referenced this issue Jun 28, 2022
OhmGeek added a commit to OhmGeek/OhmGeek.co.uk that referenced this issue Jul 17, 2022
charleskorn added a commit to batect/docker-client that referenced this issue Jul 23, 2022
kachick added a commit to kachick/deploy-yard-to-pages that referenced this issue Aug 10, 2022
andreabedini added a commit to IntersectMBO/cardano-haskell-packages that referenced this issue Aug 23, 2022
andreabedini added a commit to IntersectMBO/cardano-haskell-packages that referenced this issue Aug 23, 2022
detarmstrong pushed a commit to detarmstrong/compare-datasets that referenced this issue Sep 24, 2022
Tandashi added a commit to JustDanceRequests/justdancerequests.github.io that referenced this issue Sep 29, 2022
schmidtp1 added a commit to schmidtp1/test that referenced this issue Oct 20, 2022
dijidiji added a commit to dijidiji/ja2-impgen that referenced this issue Oct 21, 2022
Environment is needed for deploy-pages as per actions/deploy-pages#9
terrafrost added a commit to phpseclib/phpseclib.github.io that referenced this issue Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants