A Probot GitHub App that uses GitHub Copilot to protect GitHub environments from malicious workflow deployments. This bot analyzes GitHub Actions workflows before deployment and uses GitHub Copilot's AI capabilities to detect potentially malicious activities.
- GitHub Copilot-Powered Security Analysis: Uses GitHub Copilot API to analyze workflow content with advanced understanding of GitHub Actions patterns
- Environment Protection: Protects specific environments (production, staging, etc.) from malicious deployments
- Configurable Rules: Supports both environment variables and repository-specific configuration
- Flexible Responses: Can approve, reject, or request manual review based on analysis confidence
- Comprehensive Logging: Detailed logging for security audit trails
- Webhook Reception: Listens for
deployment_protection_rule.requestedevents - Environment Check: Verifies if the target environment is protected
- Workflow Analysis: Fetches and analyzes the workflow content using GitHub Copilot
- Security Decision: Makes approval/rejection decisions based on Copilot analysis
- Response: Responds to GitHub with the protection rule decision
- Node.js 18 or higher
- A GitHub App with the following permissions:
- Repository permissions:
- Actions: Read
- Contents: Read
- Metadata: Read
- Subscribe to events:
- Deployment protection rule
- Repository permissions:
-
Clone and Install:
git clone <your-repo> cd actions-copilot npm install
-
Configure Environment:
cp .env.example .env # Edit .env with your configuration -
Build the Project:
npm run build
-
Start the Bot:
npm start
For development:
npm run dev
| Variable | Description | Default |
|---|---|---|
LLM_API_URL |
GitHub Copilot API endpoint URL | https://api.githubcopilot.com/chat/completions |
LLM_API_KEY |
GitHub token for Copilot API access | Required |
LLM_MODEL |
Model to use for analysis | gpt-4o |
LLM_MAX_TOKENS |
Maximum tokens for Copilot response | 1000 |
LLM_TEMPERATURE |
Temperature for Copilot analysis | 0.2 |
PROTECTED_ENVIRONMENTS |
Comma-separated list of protected environments | production,staging |
BLOCK_ON_MALICIOUS |
Whether to block on malicious detection | true |
ALLOWED_ACTIONS |
Comma-separated list of allowed GitHub Actions | Empty |
BLOCKED_KEYWORDS |
Comma-separated list of blocked keywords | rm -rf,curl,wget,download |
You can also configure the bot per repository by creating .github/actions-copilot-config.json:
{
"llm": {
"apiUrl": "https://api.githubcopilot.com/chat/completions",
"model": "gpt-4o",
"maxTokens": 1000,
"temperature": 0.2
},
"protectionRules": {
"enabledEnvironments": ["production"],
"blockOnMaliciousDetection": true,
"allowedActions": ["actions/checkout", "actions/setup-node"],
"blockedKeywords": ["rm -rf", "curl", "sudo"]
}
}LLM_API_URL=https://api.githubcopilot.com/chat/completions
LLM_API_KEY=your_github_token_here
LLM_MODEL=gpt-4oLLM_API_URL=https://api.openai.com/v1/chat/completions
LLM_API_KEY=sk-...
LLM_MODEL=gpt-4LLM_API_URL=https://api.anthropic.com/v1/messages
LLM_API_KEY=sk-ant-...
LLM_MODEL=claude-3-sonnet-20240229LLM_API_URL=https://your-resource.openai.azure.com/openai/deployments/your-deployment/chat/completions?api-version=2023-12-01-preview
LLM_API_KEY=your-azure-key
LLM_MODEL=gpt-4- API Key Security: Store LLM API keys securely and rotate them regularly
- Rate Limiting: Be aware of LLM API rate limits for high-volume repositories
- Fallback Behavior: The bot defaults to blocking deployments if LLM analysis fails
- Audit Logging: All decisions are logged for security audit purposes
- Create a GitHub App in your organization settings
- Set Webhook URL to your bot's endpoint
- Configure Permissions:
- Repository permissions: Actions (Read), Contents (Read), Metadata (Read)
- Subscribe to events: Deployment protection rule
- Install the App on repositories where you want protection
src/
├── handlers/
│ └── environment-protection.ts # Main webhook handler
├── services/
│ ├── config-service.ts # Configuration management
│ └── llm-service.ts # LLM API integration
├── types/
│ └── index.ts # TypeScript type definitions
└── index.ts # Main application entry point
npm testnpm run buildActions Copilot can be easily deployed as a Docker container.
-
Build and run with Docker Compose (easiest):
# Copy environment template cp .env.example .env # Edit .env with your GitHub App credentials # Start the container npm run docker:up
-
Or build and run manually:
npm run docker:build npm run docker:run
- Environment file: Copy
.env.exampleto.envand fill in your values- Set
PORT=8080if you want to use a different port (default is 3000)
- Set
- Private key: Place your GitHub App private key as
private-key.pemin the project root - GitHub App: Configure your app to point webhooks to your container (e.g.,
https://your-domain.com:8080/api/github/webhooks)
| Command | Description |
|---|---|
npm run docker:build |
Build the Docker image |
npm run docker:run |
Run container with .env file |
npm run docker:up |
Start with Docker Compose |
npm run docker:down |
Stop Docker Compose |
.envfile with your GitHub App configurationprivate-key.pemfile (your GitHub App's private key)- Docker and Docker Compose installed
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Create an issue in this repository
- Check the logs for detailed error information
- Verify your LLM API configuration and quotas