Access Control for Actions
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 12 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Access Control for GitHub Actions: A Comprehensive Enterprise Guide
Introduction: The Critical Need for Governance
In a modern software engineering organization, GitHub Actions has become the backbone of CI/CD pipelines. It allows developers to automate testing, building, and deployment workflows directly within the repository where their code lives. However, as an organization scales, the freedom to use any action from the public marketplace—or even internal custom actions—creates significant security and compliance risks. If a developer unknowingly includes a malicious action or a poorly maintained script in their pipeline, they could inadvertently expose secrets, corrupt build artifacts, or introduce vulnerabilities into the production environment.
Access control for GitHub Actions is the process of governing who can create, modify, and execute workflows, as well as defining which actions are permitted to run within your enterprise organization. This isn't just about security; it is about maintaining a stable, predictable, and compliant software supply chain. When you manage access control effectively, you ensure that your teams can work quickly without compromising the safety of your infrastructure. This lesson will guide you through the technical mechanisms and organizational strategies required to manage GitHub Actions at scale.
Not read yet
Understanding the GitHub Actions Governance Model
GitHub provides a layered approach to governance. You can control actions at the enterprise, organization, and repository levels. Understanding these layers is essential for building a strategy that balances developer productivity with security requirements.
The Scope of Governance
Governance in GitHub Actions is primarily handled through three distinct mechanisms:
- GitHub Marketplace Policies: Controlling which public actions are allowed to be used in your organization.
- Organization-level Secrets and Variables: Managing the credentials and configuration data that workflows consume.
- Self-hosted Runner Groups: Restricting which workflows can run on specific hardware or network segments.
Callout: The "Principle of Least Privilege" in CI/CD The Principle of Least Privilege dictates that any workflow should have exactly the permissions required to complete its task and nothing more. In the context of GitHub Actions, this means limiting access to secrets, restricting the scope of GITHUB_TOKEN, and ensuring that only verified actions are allowed to execute. By default, many configurations are too permissive; governance is the act of tightening these defaults to match your specific risk profile.
Not read yet
Configuring Action Policies at the Enterprise Level
For larger organizations, managing settings repository-by-repository is impossible. GitHub Enterprise allows you to set policies that apply to all organizations within your enterprise account. These policies act as the "guardrails" for your developers.
Restricting Marketplace Actions
You can dictate which actions are allowed to run in your organization. The three common configurations are:
- Allow all actions: This is the default but is often too risky for enterprise environments. It allows developers to use any action published on the GitHub Marketplace.
- Allow local actions only: This restricts the organization to only using actions defined within your own repositories. This is the most secure posture but requires significant effort to maintain a library of internal actions.
- Allow local and select Marketplace actions: This is the "sweet spot" for most companies. It allows you to create an "allowlist" of verified, vetted actions from the marketplace while blocking everything else.
Step-by-Step: Enabling Marketplace Policy
- Navigate to your Enterprise account settings.
- Select Policies from the sidebar.
- Click on Actions.
- Under GitHub-owned actions, ensure that "Allow local actions and GitHub-owned actions" is selected.
- Under Marketplace actions, select "Allow select actions."
- Click Add actions and search for the specific actions (e.g.,
actions/checkout@v4,actions/setup-node@v4) that you want to permit. - Save your settings.
Note: When you restrict marketplace actions, existing workflows that use unapproved actions will fail. Always communicate these changes to your engineering teams well in advance and provide a migration path or a request process for new actions.
Not read yet
Managing Internal Action Libraries
Instead of relying solely on public actions, high-maturity engineering organizations build internal "Golden Actions." These are custom actions developed by a platform engineering team, tested for security and performance, and distributed across the organization.
Creating a Shared Actions Repository
To share an action, create a dedicated repository (e.g., company-org/actions-library). Inside this repository, you can host multiple actions, each with its own action.yml file.
Example: A Simple Internal Action
# .github/actions/security-scan/action.yml
name: 'Company Security Scan'
description: 'Run our mandatory enterprise security scan'
runs:
using: 'composite'
steps:
- name: Run Scan
shell: bash
run: ./scripts/run-scan.sh
Distributing Actions via Repository Permissions
Once you have your actions-library repository, you need to ensure that other repositories in your organization have read access to it.
- If your organization is set to "Internal," all members can see the repository.
- If you want to keep the repository private, you must ensure that the workflows in your application repositories have the correct permissions to pull from the library.
Tip: Use semantic versioning (tags) for your internal actions. Never point your workflows to the
mainbranch of an action repository, as this can lead to unexpected changes breaking your production builds. Always use tags likev1.0.1.
Not read yet
Controlling Access to Secrets and Variables
Workflows often require sensitive information, such as API keys, cloud credentials, or database passwords. Managing access to these secrets is a critical component of access control.
The Role of Environments
GitHub Environments allow you to define rules for how secrets are accessed. You can require manual approval for a job to run, or restrict a secret so that it can only be used by workflows running on specific branches.
Using Environments for Access Control:
- Go to your repository Settings.
- Select Environments and create a new one, such as
production. - Under Environment secrets, add the credentials needed for deployment.
- Under Deployment branches, restrict access so that only the
mainbranch can trigger a workflow that uses this environment. - Enable Required reviewers to ensure that no deployment happens without human oversight.
Best Practices for Secret Governance
- Never use organization-level secrets for sensitive production keys: Use environment-level secrets instead. This ensures that only authorized workflows can access the keys.
- Audit secret usage: Periodically review which workflows are accessing which secrets.
- Rotate secrets regularly: Even with strong access control, secrets should be rotated automatically to minimize the impact of a potential leak.
Not read yet
Securing the GITHUB_TOKEN
The GITHUB_TOKEN is an automatically generated token that allows your workflow to interact with the repository. By default, it has broad permissions. You can and should restrict this token to follow the principle of least privilege.
Restricting Token Permissions
In your workflow file, you can explicitly set the permissions for the GITHUB_TOKEN. This prevents a compromised action from performing unauthorized operations, like deleting issues or modifying repository settings.
Example: Restricting Permissions
name: CI Workflow
on: [push]
# Set permissions for the entire workflow
permissions:
contents: read
issues: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Do something
run: echo "Hello World"
If you do not define the permissions block, GitHub grants broad default permissions. Always explicitly define only what the workflow needs. If a workflow only needs to read code, set contents: read and nothing more.
Not read yet
Self-Hosted Runner Governance
Self-hosted runners give you more control over the environment where your code runs, but they also introduce a significant security surface area. If a runner is compromised, an attacker could potentially access the host machine's network or file system.
Runner Groups
Runner groups are the primary way to manage access to self-hosted runners. You can create a group for "Internal Projects" and another for "Public Open Source Projects," then assign specific runners to these groups.
- Granting Access: You can restrict which repositories are allowed to use a specific runner group.
- Visibility: You can prevent unauthorized repositories from even seeing that the runner group exists.
Security Warning for Self-Hosted Runners
Warning: Never use self-hosted runners on repositories that allow external contributors (like public forks). A malicious user could submit a pull request containing a workflow that executes arbitrary code on your runner, potentially gaining access to your internal network. Always use GitHub-hosted runners for public projects.
Not read yet
Comparison: GitHub-Hosted vs. Self-Hosted Runners
| Feature | GitHub-Hosted Runners | Self-Hosted Runners |
|---|---|---|
| Security | Isolated, ephemeral, secure by default | Requires hardening and patching |
| Network | Public, limited internal access | Can access private/on-prem networks |
| Maintenance | None (GitHub manages) | Full (OS updates, software versions) |
| Access Control | Managed via organization settings | Managed via runner groups |
| Cost | Per-minute usage | Fixed hardware/cloud costs |
Common Pitfalls and How to Avoid Them
1. Over-privileged Actions
Developers often use third-party actions without auditing the code.
- The Fix: Only allow verified actions or create a "local copy" of the action in your own repository after reviewing the source code.
2. Hardcoding Secrets
It is common to see secrets hardcoded in workflow files or stored in plain-text environment variables.
- The Fix: Use repository or environment secrets. Use the
secrets:context to pass these into your steps. Never log secrets to the console.
3. Ignoring Workflow Security Logs
Many organizations fail to monitor the audit logs for GitHub Actions.
- The Fix: Enable audit logging for your enterprise and monitor for suspicious activity, such as workflows running at odd hours or unexpected changes to repository settings.
4. "Main" Branch Protection
Workflows that modify code (like auto-tagging or dependency updates) can bypass branch protection rules.
- The Fix: Ensure that "Require status checks to pass" is enabled for your main branch and that your automated workflows are included in those required checks.
5. Lack of Workflow Templates
When every team creates their own workflow from scratch, security configurations vary wildly.
- The Fix: Use "Reusable Workflows." Create a set of vetted, secure templates that teams can call from their own repositories. This ensures that every team uses the same security baseline.
Not read yet
Implementing Reusable Workflows
Reusable workflows are the most effective way to enforce governance at scale. Instead of asking every team to write their own security configuration, you provide a template that they must use.
Example: A Centralized Security Workflow
Create a repository called enterprise-workflows. Inside, define a workflow that runs your required security scans.
# .github/workflows/security-template.yml
on:
workflow_call:
secrets:
API_KEY:
required: true
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- name: Run Enterprise Scan
run: ./scan.sh --key ${{ secrets.API_KEY }}
Using the Template
In a developer's repository, they simply call this workflow:
jobs:
call-security:
uses: company-org/enterprise-workflows/.github/workflows/security-template.yml@main
secrets:
API_KEY: ${{ secrets.MY_API_KEY }}
By using this approach, you ensure that even if the developer doesn't understand the security requirements, they are still compliant because they are using your pre-configured, audited template.
Not read yet
Auditing and Compliance
Governance is not a "set it and forget it" task. You must periodically audit your access controls to ensure they are still effective.
Audit Log Review
GitHub provides an audit log that records every action taken within your enterprise. You can filter this log by:
action: To see who is creating or modifying workflows.repository: To see which repositories are being accessed.user: To see what a specific developer has done.
Automated Governance Checks
You can use GitHub's API to build your own governance tools. For example, you can create a script that runs nightly to check if any repository has disabled branch protection or if any repository is using an unauthorized action from the marketplace.
Example: Using the GitHub API to check repository settings
# Get the workflow settings for a repository
curl -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/ORG/REPO/actions/permissions
If the response shows that marketplace actions are enabled when they should be restricted, your script can automatically trigger an alert or even revert the setting.
Not read yet
Best Practices Checklist
To wrap up, here is a checklist of best practices for managing access control in GitHub Actions:
- Restrict Marketplace Access: Only allow verified actions or a specific allowlist.
- Use Reusable Workflows: Centralize your security and deployment logic into templates.
- Explicitly Define Permissions: Use the
permissionsblock in all workflow files. - Use Environment Secrets: Don't use organization-wide secrets for production deployments.
- Implement Branch Protection: Ensure that workflows modifying code must pass status checks.
- Audit Regularly: Review audit logs and verify settings via the GitHub API.
- Educate Teams: Provide clear documentation on why these controls exist and how to request new actions.
Frequently Asked Questions (FAQ)
Q: Can I block all third-party actions? A: Yes, you can set the policy to "Allow local actions only." However, this requires you to manually copy any marketplace action you want to use into your own repository. This is great for security but increases maintenance overhead.
Q: What happens if I update a reusable workflow? A: All repositories that call the reusable workflow will immediately start using the updated version. This is excellent for security patching, as you can fix a vulnerability in one place and have it propagate across the entire enterprise.
Q: How do I handle emergency access? A: Build a "break-glass" process. This could be a specific team (like Platform Engineering) that has the rights to temporarily override policies for urgent production incidents. Always ensure these overrides are logged and reverted after the incident.
Q: Are GitHub-hosted runners always better than self-hosted? A: For most use cases, yes. They are more secure and require zero maintenance. Only use self-hosted runners if you have a specific requirement, such as needing to access a private network that is not reachable from the public internet.
Not read yet
Conclusion and Key Takeaways
Managing access control for GitHub Actions is a fundamental aspect of enterprise software engineering. By moving from a "default-allow" posture to a "governed-access" model, you protect your organization from supply chain attacks, accidental secret exposure, and configuration drift.
Key Takeaways:
- Governance is a Balance: Effective access control should secure your environment without hindering the velocity of your engineering teams. Use reusable workflows and templates to make the "secure way" also the "easiest way."
- The Principle of Least Privilege: Always restrict the
GITHUB_TOKENpermissions and use environment-level secrets to ensure that workflows only have access to what they absolutely need. - Centralize Governance: Use Enterprise-level policies to enforce standards across all organizations and repositories. Do not rely on individual teams to configure their own security settings.
- Prefer Internal Actions: When possible, build and maintain your own internal action library. This gives you full visibility into the code and ensures that your dependencies are reliable and secure.
- Monitor and Audit: Access control is not static. Use the GitHub audit log and API-based checks to ensure that your configurations remain compliant over time.
- Communication is Vital: Changes to governance will impact developers. Always communicate policy changes clearly, provide documentation, and offer support for teams that need to migrate their workflows.
- Use Runner Groups: If you must use self-hosted runners, always use runner groups to restrict which repositories can access your infrastructure, and never use them for public-facing code.
By following these practices, you transform GitHub Actions from a potential security risk into a powerful, controlled, and efficient engine for your software delivery lifecycle. Remember that your goal is to provide a platform where developers can innovate safely, and robust access control is the foundation of that platform.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- Scheduled Event Triggers
- Scheduled Event Triggers Quiz5q
- Manual Workflow Dispatch
- Manual Workflow Dispatch Quiz5q
- Webhook Event Triggers
- Webhook Event Triggers Quiz5q
- Repository Events Configuration
- Repository Events Configuration Quiz5q
- Workflow Dispatch Inputs
- Workflow Dispatch Inputs Quiz5q
- Reusable Workflows with workflow_call
- Reusable Workflows with workflow_call Quiz5q
- Jobs and Steps Fundamentals
- Jobs and Steps Fundamentals Quiz5q
- Conditional Logic in Workflows
- Conditional Logic in Workflows Quiz5q
- Job Dependencies with needs
- Job Dependencies with needs Quiz5q
- Service Containers Configuration
- Service Containers Configuration Quiz5q
- Matrix Strategy Configuration
- Matrix Strategy Configuration Quiz5q
- YAML Anchors and Aliases
- YAML Anchors and Aliases Quiz5q
- Predefined Contexts Usage
- Predefined Contexts Usage Quiz5q
- Azure Integration Patterns
- Azure Integration Patterns Quiz5q
- AWS Integration Patterns
- AWS Integration Patterns Quiz5q
- Kubernetes Deployments
- Kubernetes Deployments Quiz5q
- Notification Integrations
- Notification Integrations Quiz5q
- Code Quality Integrations
- Code Quality Integrations Quiz5q
- Third-Party Service Integration
- Third-Party Service Integration Quiz5q
- Workflow Orchestration Patterns
- Workflow Orchestration Patterns Quiz5q
- Multi-Environment Workflows
- Multi-Environment Workflows Quiz5q
- Blue-Green and Canary Deployments
- Blue-Green and Canary Deployments Quiz5q
- GitHub-Hosted Runners Configuration
- GitHub-Hosted Runners Configuration Quiz5q
- Self-Hosted Runners Setup
- Self-Hosted Runners Setup Quiz5q
- Runner Groups Management
- Runner Groups Management Quiz5q
- IP Allow Lists and Networking
- IP Allow Lists and Networking Quiz5q
- Runner Troubleshooting
- Runner Troubleshooting Quiz5q
- Environment Protections
- Environment Protections Quiz5q
- Trustworthy Marketplace Actions
- Trustworthy Marketplace Actions Quiz5q
- Script Injection Mitigation
- Script Injection Mitigation Quiz5q
- GITHUB_TOKEN Permissions
- GITHUB_TOKEN Permissions Quiz5q
- OIDC Token for Cloud Federation
- OIDC Token for Cloud Federation Quiz5q
- Action Version Pinning
- Action Version Pinning Quiz5q
- Artifact Attestations and Provenance
- Artifact Attestations and Provenance Quiz5q
Spend your points to unlock exam-style practice questions
Spend points to unlock GH-200 exam-style practice questions.
Practice for GH-200