-
Notifications
You must be signed in to change notification settings - Fork 951
[FEAT]: Add Support for GitHub Enterprise Rulesets #3110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ravio1i
wants to merge
40
commits into
integrations:main
Choose a base branch
from
siemens:feat/enterprise-rulesets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
234fe52
feat: add functionality and tests for GitHub Enterprise rulesets
Ravio1i 77cd37c
docs: GitHub enterprise ruleset data source and resource
Ravio1i 05c84b9
refactor: simplify logging messages for enterprise ruleset operations…
Ravio1i e2df41c
feat: add description to GitHub enterprise ruleset resource and updat…
Ravio1i c70042e
chore: improve error handling for setting attributes in GitHub enterp…
Ravio1i b3452a7
refactor: streamline test check composition in GitHub enterprise rule…
Ravio1i 7d0dbd3
fix: update conflicts handling for repository_name in GitHub enterpri…
Ravio1i 455bb8c
feat: add repository target rules and update handling in GitHub enter…
Ravio1i 18d5e7c
feat: add organization_id condition support to GitHub enterprise ruleset
Ravio1i d562cf5
feat: add merge queue and required deployments support to GitHub ente…
Ravio1i f12b29d
feat: remove merge queue and required deployments from GitHub enterpr…
Ravio1i 217cac4
docs: add examples for GitHub Enterprise rulesets including branch, t…
Ravio1i e53cc75
feat: add customization validation for enterprise ruleset configuration
Ravio1i 26951fe
docs: enhance enterprise ruleset examples with repository target supp…
Ravio1i 82ed3b0
feat: add import functionality for GitHub enterprise ruleset and upda…
Ravio1i 92fe658
chore: upgrade go-github dependency to v82 and update context usage i…
Ravio1i c8a796b
test: update test cases to use ProviderFactories instead of Providers…
Ravio1i 6df9bfc
feat: enhance enterprise ruleset schema with repository property cond…
Ravio1i 9ff0a34
feat: add repository_property support in conditions validation and ex…
Ravio1i 9b8b4ac
feat: add example branch ruleset with repository property conditions
Ravio1i e221889
fix(enterprise_ruleset): add description to GitHub enterprise ruleset…
Ravio1i 13d7528
refactor(enterprise_ruleset): streamline ruleset target types and imp…
Ravio1i 5d21774
refactor(ruleset): simplify validation logic and enhance conditions r…
Ravio1i 34a6319
test(enterprise_ruleset): add test for conflicting repository conditi…
Ravio1i 4c6b17e
refactor(enterprise_ruleset): update validation functions to use Vali…
Ravio1i b9db331
refactor(enterprise_ruleset): simplify resource creation by using poi…
Ravio1i 4adc676
docs(enterprise_ruleset): clarify comment for repository target rules…
Ravio1i e00f582
test(enterprise_ruleset): Replace deprecated Check/ComposeTestCheckFu…
Ravio1i d4b2a1e
refactor(enterprise_ruleset): update ruleset ID handling in resource …
Ravio1i 9954e42
refactor(enterprise_ruleset): improve ruleset ID handling and enforce…
Ravio1i 5b2c697
refactor(ruleset): standardize ruleset handling across repository, or…
Ravio1i eddaeca
test(enterprise_ruleset): restructure acceptance tests into subtests …
Ravio1i 877809e
chore: remove unncessary check
Ravio1i 78f7df1
chore: remove unused imports from data source for GitHub enterprise r…
Ravio1i f44d794
fix: increase maximum length for ruleset name validation to 256 chara…
Ravio1i f8a3a92
refactor: rename customization function for enterprise ruleset valida…
Ravio1i 97e5b2c
chore: update descriptions for actor ID and bypass mode in enterprise…
Ravio1i ab5a5f7
docs: update bypass_actors section in enterprise ruleset documentatio…
Ravio1i 838432b
docs: clarify actor types and IDs in bypass_mode section of enterpris…
Ravio1i f23df92
fix: update go-github dependency to v84 and improve source handling i…
Ravio1i File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # GitHub Enterprise Ruleset Examples | ||
|
|
||
| This directory demonstrates how to configure GitHub Enterprise rulesets using the Terraform GitHub provider. | ||
|
|
||
| ## Overview | ||
|
|
||
| Enterprise rulesets allow you to enforce policies across all organizations in your GitHub Enterprise. The examples showcase all four target types: | ||
|
|
||
| - **Branch Target** (`branch_target.tf`) - Branch protection rules with PR requirements, status checks, and commit patterns | ||
| - **Tag Target** (`tag_target.tf`) - Tag protection rules with naming patterns and immutability controls | ||
| - **Push Target** (`push_target.tf`) - File restrictions, size limits, and content policies (beta feature) | ||
| - **Repository Target** (`rulesets.tf`) - Repository management rules for creation, deletion, and naming conventions | ||
|
|
||
| ## Requirements | ||
|
|
||
| - GitHub Enterprise Cloud account | ||
| - Personal access token with enterprise admin permissions | ||
| - Terraform >= 0.14 | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. Set your environment variables: | ||
|
|
||
| ```bash | ||
| export TF_VAR_github_token="your_github_token" | ||
| export TF_VAR_enterprise_slug="your-enterprise-slug" | ||
| ``` | ||
|
|
||
| 2. Customize the examples by replacing `"your-enterprise"` with your actual enterprise slug | ||
|
|
||
| 3. Apply the configuration: | ||
|
|
||
| ```bash | ||
| terraform init | ||
| terraform plan | ||
| terraform apply | ||
| ``` | ||
|
|
||
| ## Target Types | ||
|
|
||
| Each target type supports different rules: | ||
|
|
||
| - **Branch/Tag**: creation, deletion, update, signatures, linear history, PR requirements, status checks | ||
| - **Push**: file restrictions, size limits, file extensions, commit patterns | ||
| - **Repository**: creation, deletion, transfer, naming patterns, visibility controls | ||
|
|
||
| See the individual `.tf` files for detailed examples and available rules. | ||
|
|
||
| ## Important Notes | ||
|
|
||
| - All enterprise rulesets require organization and repository targeting via `conditions` | ||
| - The `push` target is currently in beta and subject to change | ||
| - Branch and tag targets require `ref_name` conditions | ||
| - Repository and push targets do not use `ref_name` conditions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| # Example: Branch target ruleset with comprehensive branch protection rules | ||
| # This ruleset applies to branches across the enterprise | ||
|
|
||
| resource "github_enterprise_ruleset" "branch_protection" { | ||
| enterprise_slug = "your-enterprise" | ||
| name = "branch-protection-ruleset" | ||
| target = "branch" | ||
| enforcement = "active" | ||
|
|
||
| # Optional: Allow certain users/teams to bypass the ruleset | ||
| bypass_actors { | ||
| actor_id = 1 | ||
| actor_type = "OrganizationAdmin" | ||
| bypass_mode = "always" | ||
| } | ||
|
|
||
| bypass_actors { | ||
| actor_type = "DeployKey" | ||
| bypass_mode = "always" | ||
| } | ||
|
|
||
| # Conditions define which organizations, repositories, and refs this ruleset applies to | ||
| conditions { | ||
| # Target all organizations in the enterprise | ||
| organization_name { | ||
| include = ["~ALL"] | ||
| exclude = [] | ||
| } | ||
|
|
||
| # Target all repositories | ||
| repository_name { | ||
| include = ["~ALL"] | ||
| exclude = ["test-*"] # Exclude test repositories | ||
| } | ||
|
|
||
| # Target all branches (required for branch target) | ||
| ref_name { | ||
| include = ["~DEFAULT_BRANCH", "main", "master", "release/*"] | ||
| exclude = ["experimental/*"] | ||
| } | ||
| } | ||
|
|
||
| # Rules that apply to matching branches | ||
| rules { | ||
| # Prevent branch creation without bypass permission | ||
| creation = true | ||
|
|
||
| # Prevent branch updates without bypass permission | ||
| update = false | ||
|
|
||
| # Prevent branch deletion without bypass permission | ||
| deletion = true | ||
|
|
||
| # Require linear history (no merge commits) | ||
| required_linear_history = true | ||
|
|
||
| # Require signed commits | ||
| required_signatures = true | ||
|
|
||
| # Prevent force pushes | ||
| non_fast_forward = true | ||
|
|
||
| # Pull request requirements | ||
| pull_request { | ||
| dismiss_stale_reviews_on_push = true | ||
| require_code_owner_review = true | ||
| require_last_push_approval = true | ||
| required_approving_review_count = 2 | ||
| required_review_thread_resolution = true | ||
| allowed_merge_methods = ["squash", "merge"] | ||
| } | ||
|
|
||
| # Status check requirements | ||
| required_status_checks { | ||
| strict_required_status_checks_policy = true | ||
| do_not_enforce_on_create = false | ||
|
|
||
| required_check { | ||
| context = "ci/build" | ||
| integration_id = 0 | ||
| } | ||
|
|
||
| required_check { | ||
| context = "ci/test" | ||
| integration_id = 0 | ||
| } | ||
| } | ||
|
|
||
| # Commit message pattern requirements | ||
| commit_message_pattern { | ||
| name = "Conventional Commits" | ||
| operator = "regex" | ||
| pattern = "^(feat|fix|docs|style|refactor|test|chore)(\\(.+\\))?: .{1,50}" | ||
| negate = false | ||
| } | ||
|
|
||
| # Commit author email pattern | ||
| commit_author_email_pattern { | ||
| name = "Corporate Email Only" | ||
| operator = "regex" | ||
| pattern = "@your-company\\.com$" | ||
| negate = false | ||
| } | ||
|
|
||
| # Committer email pattern | ||
| committer_email_pattern { | ||
| name = "Corporate Email Only" | ||
| operator = "regex" | ||
| pattern = "@your-company\\.com$" | ||
| negate = false | ||
| } | ||
|
|
||
| # Branch name pattern (only for branch target) | ||
| branch_name_pattern { | ||
| name = "Valid Branch Names" | ||
| operator = "regex" | ||
| pattern = "^(main|master|develop|feature/|bugfix/|hotfix/|release/)" | ||
| negate = false | ||
| } | ||
|
|
||
| # Code scanning requirements | ||
| required_code_scanning { | ||
| required_code_scanning_tool { | ||
| tool = "CodeQL" | ||
| alerts_threshold = "errors" | ||
| security_alerts_threshold = "high_or_higher" | ||
| } | ||
| } | ||
|
|
||
| # Copilot code review (if enabled) | ||
| copilot_code_review { | ||
| review_on_push = true | ||
| review_draft_pull_requests = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "github_enterprise_ruleset" "branch_by_property" { | ||
| enterprise_slug = "your-enterprise" | ||
| name = "production-repos-branch-protection" | ||
| target = "branch" | ||
| enforcement = "active" | ||
|
|
||
| conditions { | ||
| organization_name { | ||
| include = ["~ALL"] | ||
| exclude = [] | ||
| } | ||
|
|
||
| # Target repositories based on custom properties | ||
| repository_property { | ||
| include { | ||
| name = "environment" | ||
| property_values = ["production", "staging"] | ||
| source = "custom" | ||
| } | ||
|
|
||
| exclude { | ||
| name = "lifecycle" | ||
| property_values = ["deprecated", "archived"] | ||
| } | ||
| } | ||
|
|
||
| ref_name { | ||
| include = ["~DEFAULT_BRANCH", "refs/heads/release/*"] | ||
| exclude = [] | ||
| } | ||
| } | ||
|
|
||
| rules { | ||
| deletion = true | ||
| non_fast_forward = true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| terraform { | ||
| required_providers { | ||
| github = { | ||
| source = "integrations/github" | ||
| version = "~> 6.0" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Example: Push target ruleset for file and content restrictions | ||
| # This ruleset applies to all pushes across the enterprise | ||
|
|
||
| resource "github_enterprise_ruleset" "push_restrictions" { | ||
| enterprise_slug = "your-enterprise" | ||
| name = "push-restrictions-ruleset" | ||
| target = "push" | ||
| enforcement = "active" | ||
|
|
||
| # Allow deploy keys and organization admins to bypass | ||
| bypass_actors { | ||
| actor_type = "DeployKey" | ||
| bypass_mode = "always" | ||
| } | ||
|
|
||
| bypass_actors { | ||
| actor_id = 1 | ||
| actor_type = "OrganizationAdmin" | ||
| bypass_mode = "always" | ||
| } | ||
|
|
||
| # Conditions define which organizations and repositories this ruleset applies to | ||
| # Note: ref_name is NOT used for push target | ||
| conditions { | ||
| # Target all organizations | ||
| organization_name { | ||
| include = ["~ALL"] | ||
| exclude = [] | ||
| } | ||
|
|
||
| # Target all repositories | ||
| repository_name { | ||
| include = ["~ALL"] | ||
| exclude = ["sandbox-*"] | ||
| } | ||
| } | ||
|
|
||
| # Rules that apply to all pushes | ||
| rules { | ||
| # Restrict specific file paths from being pushed | ||
| file_path_restriction { | ||
| restricted_file_paths = [ | ||
| "secrets.txt", | ||
| "*.key", | ||
| "*.pem", | ||
| ".env", | ||
| "credentials/*" | ||
| ] | ||
| } | ||
|
|
||
| # Limit maximum file size to prevent large files | ||
| max_file_size { | ||
| max_file_size = 100 # Max 100 MB | ||
| } | ||
|
|
||
| # Limit maximum file path length | ||
| max_file_path_length { | ||
| max_file_path_length = 255 | ||
| } | ||
|
|
||
| # Restrict specific file extensions | ||
| file_extension_restriction { | ||
| restricted_file_extensions = [ | ||
| "*.exe", | ||
| "*.dll", | ||
| "*.so", | ||
| "*.dylib", | ||
| "*.zip", | ||
| "*.tar.gz" | ||
| ] | ||
| } | ||
|
|
||
| # Commit message pattern | ||
| commit_message_pattern { | ||
| name = "Valid Commit Message" | ||
| operator = "regex" | ||
| pattern = "^(feat|fix|docs|style|refactor|test|chore)(\\(.+\\))?: .+" | ||
| negate = false | ||
| } | ||
|
|
||
| # Commit author email pattern | ||
| commit_author_email_pattern { | ||
| name = "Corporate Email" | ||
| operator = "ends_with" | ||
| pattern = "@your-company.com" | ||
| negate = false | ||
| } | ||
|
|
||
| # Committer email pattern | ||
| committer_email_pattern { | ||
| name = "Corporate Email" | ||
| operator = "ends_with" | ||
| pattern = "@your-company.com" | ||
| negate = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Example: Security-focused push ruleset | ||
| resource "github_enterprise_ruleset" "security_push_restrictions" { | ||
| enterprise_slug = "your-enterprise" | ||
| name = "security-push-restrictions" | ||
| target = "push" | ||
| enforcement = "active" | ||
|
|
||
| conditions { | ||
| organization_name { | ||
| include = ["~ALL"] | ||
| exclude = [] | ||
| } | ||
|
|
||
| repository_name { | ||
| include = ["*-prod", "*-production"] | ||
| exclude = [] | ||
| } | ||
| } | ||
|
|
||
| rules { | ||
| # Block common secret file patterns | ||
| file_path_restriction { | ||
| restricted_file_paths = [ | ||
| "*.pem", | ||
| "*.key", | ||
| "*.cert", | ||
| "*.p12", | ||
| "*.pfx", | ||
| ".env", | ||
| ".env.*", | ||
| "secrets.yml", | ||
| "credentials.json" | ||
| ] | ||
| } | ||
|
|
||
| # Strict file size limits for production | ||
| max_file_size { | ||
| max_file_size = 50 # Max 50 MB | ||
| } | ||
|
|
||
| # Block executable and archive files | ||
| file_extension_restriction { | ||
| restricted_file_extensions = [ | ||
| "*.exe", | ||
| "*.dll", | ||
| "*.so", | ||
| "*.dylib", | ||
| "*.bin", | ||
| "*.dmg" | ||
| ] | ||
| } | ||
|
|
||
| # Require signed commits | ||
| required_signatures = true | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.