Skip to content

Conversation

@1234-ad
Copy link

@1234-ad 1234-ad commented Jan 25, 2026

Description

Implements configurable permissions for Actions job tokens as proposed in #24635.

This PR adds support for:

  • Repository-level default permissions configuration
  • Workflow-level permissions: keyword (GitHub Actions compatible)
  • Job-level permissions: override
  • Automatic read-only restriction for fork pull requests
  • REST API for managing permissions

Changes

Database

  • New table: action_token_permissions - Stores default permission configurations
  • Modified table: action_task - Added token_scopes field for calculated permissions

Core Features

  1. Permission Configuration (models/actions/token_permissions.go)

    • Repository and organization-level defaults
    • Granular control over permission scopes
    • Conversion to AccessTokenScope
  2. Workflow Parser (modules/actions/permissions.go)

    • Parses permissions: from workflow YAML
    • Supports both string (read-all, write-all, {}) and map formats
    • Job-level and workflow-level permissions
  3. Token Scope Calculation (models/actions/task.go)

    • Merges workflow permissions with repository defaults
    • Enforces read-only for fork PRs
    • Stores calculated scopes in task
  4. REST API (routers/api/v1/repo/actions_permissions.go)

    • GET /repos/{owner}/{repo}/actions/permissions
    • PUT /repos/{owner}/{repo}/actions/permissions

Documentation

  • Comprehensive usage guide (docs/content/usage/actions-token-permissions.en-us.md)
  • Implementation notes (IMPLEMENTATION_NOTES.md)
  • API examples and best practices

Examples

Workflow with Permissions

name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write
  packages: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Create Release
        run: gh release create ${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Job-Level Override

name: CI/CD

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test

  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    steps:
      - run: deploy.sh

API Usage

# Set repository default permissions
curl -X PUT \
  -H "Authorization: token YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "default_permissions": "read",
    "contents_permission": "write",
    "issues_permission": "write",
    "pull_requests_permission": "write"
  }' \
  https://gitea.example.com/api/v1/repos/owner/repo/actions/permissions

Compatibility

  • GitHub Actions Compatible - Uses same permissions: syntax
  • Backward Compatible - Existing workflows work without changes
  • Migration Safe - Database migration with default values

Security

  • Fork PR tokens automatically restricted to read-only
  • Metadata always readable (required for basic operations)
  • Permission validation on API endpoints
  • Follows principle of least privilege

Testing

  • Unit tests for permission models
  • Integration tests for workflow parsing
  • API endpoint tests
  • End-to-end workflow execution tests

Checklist

  • Database migration created
  • API endpoints implemented
  • Documentation written
  • GitHub Actions compatible syntax
  • Fork PR protection
  • Tests added (to be completed)
  • Web UI (future enhancement)

Related Issues

Closes #24635

Future Enhancements

  • Organization-level default permissions
  • Web UI for permission configuration
  • Audit logging for permission changes
  • Permission templates
  • Cross-repository access within organizations

Note: This is a comprehensive implementation that provides the foundation for configurable Actions token permissions. The syntax is fully compatible with GitHub Actions, making migration seamless for users.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 25, 2026
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/docs modifies/migrations labels Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/docs modifies/go Pull requests that update Go code modifies/migrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Support configuring permissions of automatic tokens of Actions jobs

2 participants