Giter VIP home page Giter VIP logo

github-actions-access-manager's Introduction

  GitHub Actions Access Manager

Manage access from GitHub actions workflows by providing temporary app access tokens to repository resources.

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

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
    self: 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.eyJqdGkiOiJjOTAzODNiMC01YTVjLTQ2YTMtODUxZi0wYzQwMDRiMWRkYmUiLCJzdWIiOiJyZXBvOnFvb21vbi9naXRodWItYWN0aW9ucy1hY2Nlc3MtbWFuYWdlcjpyZWY6cmVmcy9oZWFkcy9tYWluIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3Fvb21vbiIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImE5Yzk1NDYyM2RkYWE5NTVhMmE3Zj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feNUa53TZStrOREODO-TcWgIAkUJBcNoE3vhJJkBn2NFeovxzW5yj_sO3Kq4E24XYtUrXR52z_34yz9hzdsQ
    
    INPUT_REPOSITORIES=qoomon/github-actions-access-manager \
    INPUT_PERMISSIONS=contents:read \
    node index.js

Resources

github-actions-access-manager's People

Contributors

qoomon avatar nickcrews avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.