Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
unlock

GitHub Action

Access Tokens for GitHub Actions

v3.0.0

Access Tokens for GitHub Actions

unlock

Access Tokens for GitHub Actions

GitHub Action to request temporary access tokens

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Access Tokens for GitHub Actions

uses: qoomon/[email protected]

Learn more about this action in qoomon/actions--access-token

Choose a version

  GitHub Actions Access Tokens

Obtain temporary Access Tokens for GitHub Actions workflows by requesting GitHub App Installation Access Tokens. Authorization is based on the GitHub Actions OIDC tokens and .github/access.yaml file in the target repositories.

Workflow

  1. This GitHub action will request an access token for a Granting Repository from the App Server, authorize by the GitHub Action ID Token (JWT signed by GitHub).
  2. The App Server requests a GitHub App Installation Token to read .github/access.yaml file in Granting Repository.
  3. The App Server reads .github/access.yaml file from Granting Repository and determine which permissions should be granted to Requesting Repository, authorized by the GitHub App Installation Token from step 2..
  4. The App Server requests a GitHub App Installation Token with granted permissions for Source Directory and send it back in response to this GitHub action from step 1..
  5. This GitHub action sets the token as environment variable $GITHUB_ACCESS_MANAGER_TOKEN and as step output ${{ steps.access-manager.outputs.GITHUB_ACCESS_MANAGER_TOKEN }}.
  6. Further steps can then utilize this token to access resources of the Granting Repository.

Usage

Install Access Manager App to Granting Repository example/blue

Restrict Write Permission for Access Policy File to Repository Admins only

access-policy-ruleset

Grant Access Permissions in Granting Repository example/blue

  • Create .github/access.yaml file
  • Set self to enclosing repository.
    • This ensures no unintended access in case you fork a repository with .github/access.yaml file.
  • Add policies and permissions, see examples below.
    • repository value supports wildcards * e.g. repository: octa-org/*
    • metadata: read permission is implicitly always granted.
Example Configurations
  • Self access to trigger workflows from another workflow
    origin: qoomon/example 
    policies:
    - repository: self
      permissions:
        actions: write
  • Grant read access to GitHub Packages for an explicit repository
    self: qoomon/example
    policies:
    - repository: qoomon/sandbox
      permissions:
        packages: read
  • Grant read access to GitHub Packages for an entire organization
    self: qoomon/example
    policies:
    - repository: octa-org/*
      permissions:
        packages: read

Setup GitHub Action Workflow for Requesting Repository (example/green)

Example Workflow Files
  • Clone a remote repository
    on:
      # ...
      
    permissions:
      id-token: write # required to request id-token
      
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Request access token
            uses: qoomon/github-actions-access-manager@v2
            with:
              repositories: |
                qoomon/sandbox
              permissions: |
                contents:read
          - name: Clone remote repository
            run: |
              git config --global credential.helper store
              git clone https://_:[email protected]/qoomon/sandbox.git
          # ...
  • Trigger another workflow within the repository
    on:
      # ...
      
    permissions:
      id-token: write # required to request id-token
      
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Request access token
            id: access-manager
            uses: qoomon/github-actions-access-manager@v2
            with:
              repositories: self
              permissions: actions:write
          - name: Trigger workflow
            run: |
              gh workflow run post_deploy_checks.yml \
                --ref my-branch \
                --field logLevel=debug
            env:
              GITHUB_TOKEN: ${{steps.access-manager.outputs.GITHUB_ACCESS_MANAGER_TOKEN}}
          # ...

Deploy your own Access Manager App

Create a GitHub App

  • Create a new User App or a new Organizations App
  • Fill out mandatory fields
  • Deactivate Webhook
  • Choose Repository permissions you want to manage or see following suggestions
    • Actions: Read and write
    • Contents: Read-only
    • Packages: Read-only
  • Add Mandatory Repository permissions
    • Single file: Read-only
      • Add file path .github/access.yaml

Install GitHub App for Granting Repository

Run GitHub Actions Access Manager Server

  • Fork this repository
  • Create Vercel App of your fork
  • change default endpoint in github action action.yaml to your vercel app url.
  • Use your fork as GitHub action to request a access token,

Development

Run Server Locally

  • Start Server
    npm --prefix server/ start 
  • Run GitHub Action
    export NODE_ENV=development
    export ACTIONS_ACCESS_MANAGER_ENDPOINT=http://localhost:3000/v2/access_token
    
    export ACTIONS_ID_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImVCWl9jbjNzWFlBZDBjaDRUSEJLSElnT3dPRSIsImtpZCI6Ijc4MTY3RjcyN0RFQzVEODAxREQxQzg3ODRDNzA0QTFDODgwRUMwRTEifQ.e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IjoxNjY2Mjk4NzYxfQ.37dPzBp031doaTq1alL4s1vpn7ODAX8ks2_cPbloJd-Scaf9fbkdZjYON0Ogm0Gu3yURvSusFVbej22KwHYdTmxQh-NyudXpmqTnTI7RY-9ouiEScY0-D9mc7oUI8INb7phwUOdzOECb48HbPNA04MVwJ2YGQwyWBIXixScMMv3Au3g22NK6Kc_-MPXuSCbBzj2ZLyn2g57BMGs_OveFZy0uRzv5YuzS-QdjBgpesWuJrLgE4DPk3YTkpaLC0rTWo4feNUa53TZStrOREODO-TcWgIAkUJBcNoE3vhJJkBn2NFeovxzW5yj_sO3Kq4E24XYtUrXR52z_34yz9hzdsQ
    
    INPUT_REPOSITORIES=qoomon/github-actions-access-manager \
    INPUT_PERMISSIONS=contents:read \
    node index.js

Resources