{"version":"https:\/\/jsonfeed.org\/version\/1","title":"Enter the Cloud Dojo","home_page_url":"https:\/\/ghsioux.github.io\/","feed_url":"https:\/\/ghsioux.github.io\/feed.json","description":"some zen stories for dev(sec)?ops pilgrims","icon":"https:\/\/ghsioux.github.io\/apple-touch-icon.png","favicon":"https:\/\/ghsioux.github.io\/favicon.ico","expired":false,"author":{"name":"ghsioux","url":null,"avatar":null},"items":[{"id":"https:\/\/ghsioux.github.io\/2025\/07\/15\/getting-started-with-copilot-coding-agent","title":"Getting Started with GitHub Copilot Coding Agent","summary":"A curated guide to mastering GitHub Copilot Coding Agent, from creating PRs to delegating issues like a true code ninja","content_text":"Greetings, code ninjas! \ud83e\udd77After helping a customer unlock the power of Copilot Coding Agent this morning, I realized this knowledge should be shared with the entire dojo. Consider this your essential scroll of wisdom for getting started with your new AI coding companion.1 - The Two Paths of the Coding AgentLike choosing between the way of the sword or the bow, Copilot Coding Agent offers two primary approaches to enhance your coding journey:Path 1: Direct PR CreationAsk Copilot to create a Pull Request directly. This is the swift strike approach - perfect when you know exactly what needs to be done.  \ud83d\udcd6 Full documentation on PR creationPath 2: Issue DelegationCreate an issue and assign it to Copilot. This is the strategic approach - ideal for more complex tasks that benefit from structured planning. Copilot can even help you create well-structured issues before delegating them.  \ud83d\udcd6 Full documentation on issue delegation2 - Essential Scrolls of KnowledgeBefore embarking on your journey, study these core teachings:  \ud83c\udfaf About Copilot Coding Agent - Learn how Copilot works autonomously to fix bugs, implement features, improve tests, update docs, and address technical debt;  \ud83d\udcda Complete Documentation - The comprehensive guide covering everything from setup to advanced usage:          Enabling Copilot coding agent for your repository      Best practices for optimal results      Tracking sessions to monitor progress      Reviewing PRs created by Copilot      Extending with MCP (Model Context Protocol) for advanced scenarios      Customizing the environment with additional tools      Customizing the firewall to control domain access      Troubleshooting guide for common issues      3 - The Art of Issue CraftingWhen following Path 2 (issue delegation), remember: a well-structured issue is like a perfectly balanced kata. Your AI companion performs best with clear, detailed context and specifications.Leveraging issue templates is a great idea to ensure consistent structure and let Copilot help create issues for you with the right content.As you master the art of issue creation, know that GitHub Issues itself is rapidly evolving with powerful new features:  Issue Types - Bring structure to your issues with customizable types;  Sub-Issues - Break down complex tasks into manageable sub-issues;  Issue Dependencies - Manage relationships between issues for better workflow orchestration.While, as of today, Copilot doesn\u2019t leverage these new issue capabilities directly, we can imagine a future where it could intelligently break down complex requests into sub-issues, respect dependencies, and orchestrate sophisticated multi-phase workflows.4 - The Way of Custom InstructionsJust as a dojo has its own training methods and philosophies, you can teach Copilot Coding Agent to follow your team\u2019s specific practices and coding standards in your repository. This is achieved through repository custom instructions - a powerful feature that ensures your AI companion adheres to your project\u2019s unique requirements.You can have a look at the instructions folder of the awesome-copilot repository for inspiration.For VS Code users, you can automatically generate a .github\/copilot-instructions.md file tailored to your project (learn more here).5 - The Path ForwardAs you begin your journey with Copilot Coding Agent, remember that mastery comes through practice. Start with simple tasks, observe how your AI companion approaches problems, and gradually increase complexity.For those seeking to push beyond current boundaries, keep an eye on GitHub Next where the future of AI-assisted development is being forged.May your code be bug-free and your deployments swift!Gassh\u014d \ud83d\ude4fAdditional Readings from the GitHub Blog  Note: GitHub Copilot Coding Agent is rapidly evolving! Some content in these posts reflects the development phase and may be outdated. Always check the official documentation for the most current information.  July 15, 2025 - From chaos to clarity: Using GitHub Copilot agents to improve developer workflows - Learn how to set up Copilot coding agent for success.  July 1, 2025 - From idea to PR: A guide to GitHub Copilot\u2019s agentic workflows - A practical guide demonstrating how to use Copilot\u2019s coding agent.  June 6, 2025 - Assigning and completing issues with coding agent in GitHub Copilot - A detailed walkthrough of the issue delegation workflow.  June 5, 2025 - How to create issues and pull requests in record time - Learn the anatomy of well-structured issues and how Copilot amplifies your workflow.","content_html":"<p>Greetings, code ninjas! \ud83e\udd77<\/p><p>After helping a customer unlock the power of <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/concepts\/about-copilot-coding-agent#overview-of-copilot-coding-agent\">Copilot Coding Agent<\/a> this morning, I realized this knowledge should be shared with the entire dojo. Consider this your essential scroll of wisdom for getting started with your new AI coding companion.<\/p><h2 id=\"1---the-two-paths-of-the-coding-agent\">1 - The Two Paths of the Coding Agent<\/h2><p>Like choosing between the way of the sword or the bow, Copilot Coding Agent offers two primary approaches to enhance your coding journey:<\/p><h3 id=\"path-1-direct-pr-creation\">Path 1: Direct PR Creation<\/h3><p>Ask Copilot to create a Pull Request directly. This is the swift strike approach - perfect when you know exactly what needs to be done.<\/p><ul>  <li>\ud83d\udcd6 <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/asking-copilot-to-create-a-pull-request\">Full documentation on PR creation<\/a><\/li><\/ul><h3 id=\"path-2-issue-delegation\">Path 2: Issue Delegation<\/h3><p>Create an issue and assign it to Copilot. This is the strategic approach - ideal for more complex tasks that benefit from structured planning. <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/github-flow\/using-github-copilot-to-create-issues\">Copilot can even help you create well-structured issues<\/a> before delegating them.<\/p><ul>  <li>\ud83d\udcd6 <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/using-copilot-to-work-on-an-issue\">Full documentation on issue delegation<\/a><\/li><\/ul><h2 id=\"2---essential-scrolls-of-knowledge\">2 - Essential Scrolls of Knowledge<\/h2><p>Before embarking on your journey, study these core teachings:<\/p><ul>  <li>\ud83c\udfaf <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/concepts\/about-copilot-coding-agent\">About Copilot Coding Agent<\/a><\/strong> - Learn how Copilot works autonomously to fix bugs, implement features, improve tests, update docs, and address technical debt;<\/li>  <li>\ud83d\udcda <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\">Complete Documentation<\/a><\/strong> - The comprehensive guide covering everything from setup to advanced usage:    <ul>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/enabling-copilot-coding-agent\">Enabling Copilot coding agent<\/a> for your repository<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/best-practices-for-using-copilot-to-work-on-tasks\">Best practices<\/a> for optimal results<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/tracking-copilots-sessions\">Tracking sessions<\/a> to monitor progress<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/reviewing-a-pull-request-created-by-copilot\">Reviewing PRs<\/a> created by Copilot<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/extending-copilot-coding-agent-with-mcp\">Extending with MCP<\/a> (Model Context Protocol) for advanced scenarios<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/customizing-the-development-environment-for-copilot-coding-agent\">Customizing the environment<\/a> with additional tools<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/customizing-or-disabling-the-firewall-for-copilot-coding-agent\">Customizing the firewall<\/a> to control domain access<\/li>      <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/troubleshooting-copilot-coding-agent\">Troubleshooting guide<\/a> for common issues<\/li>    <\/ul>  <\/li><\/ul><h2 id=\"3---the-art-of-issue-crafting\">3 - The Art of Issue Crafting<\/h2><p>When following Path 2 (issue delegation), remember: <a href=\"https:\/\/github.blog\/developer-skills\/github\/how-to-create-issues-and-pull-requests-in-record-time-on-github\/#h-the-anatomy-of-a-great-github-issue\">a well-structured issue<\/a> is like a perfectly balanced kata. Your AI companion performs best with clear, detailed context and specifications.<\/p><p>Leveraging <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/communities\/using-templates-to-encourage-useful-issues-and-pull-requests\/configuring-issue-templates-for-your-repository\">issue templates<\/a> is a great idea to ensure consistent structure and let <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/github-flow\/using-github-copilot-to-create-issues\"><strong>Copilot help create issues<\/strong><\/a> for you with the right content.<\/p><p>As you master the art of issue creation, know that GitHub Issues itself is rapidly evolving with powerful new features:<\/p><ul>  <li><a href=\"https:\/\/github.blog\/changelog\/2025-04-09-evolving-github-issues-and-projects\/#%f0%9f%8f%97%ef%b8%8f-bring-structure-to-your-issues-with-issue-types\">Issue Types<\/a> - Bring structure to your issues with customizable types;<\/li>  <li><a href=\"https:\/\/github.blog\/changelog\/2025-04-09-evolving-github-issues-and-projects\/#%f0%9f%94%a8-break-it-down-with-sub-issues\">Sub-Issues<\/a> - Break down complex tasks into manageable sub-issues;<\/li>  <li><a href=\"https:\/\/github.com\/orgs\/community\/discussions\/165749\">Issue Dependencies<\/a> - Manage relationships between issues for better workflow orchestration.<\/li><\/ul><p>While, as of today, Copilot doesn\u2019t leverage these new issue capabilities directly, we can imagine a future where it could intelligently break down complex requests into sub-issues, respect dependencies, and orchestrate sophisticated multi-phase workflows.<\/p><h2 id=\"4---the-way-of-custom-instructions\">4 - The Way of Custom Instructions<\/h2><p>Just as a dojo has its own training methods and philosophies, you can teach Copilot Coding Agent to follow your team\u2019s specific practices and coding standards in your repository. This is achieved through <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\/best-practices-for-using-copilot-to-work-on-tasks#adding-custom-instructions-to-your-repository\"><strong>repository custom instructions<\/strong><\/a> - a powerful feature that ensures your AI companion adheres to your project\u2019s unique requirements.<\/p><p>You can have a look at the <code class=\"language-plaintext highlighter-rouge\">instructions<\/code> folder of the <a href=\"https:\/\/github.com\/github\/awesome-copilot\/\">awesome-copilot repository<\/a> for inspiration.<\/p><p>For VS Code users, you can automatically generate a <code class=\"language-plaintext highlighter-rouge\">.github\/copilot-instructions.md<\/code> file tailored to your project (<a href=\"https:\/\/code.visualstudio.com\/docs\/copilot\/copilot-customization#_generate-an-instructions-file-for-your-workspace\">learn more here<\/a>).<\/p><h2 id=\"5---the-path-forward\">5 - The Path Forward<\/h2><p>As you begin your journey with Copilot Coding Agent, remember that mastery comes through practice. Start with simple tasks, observe how your AI companion approaches problems, and gradually increase complexity.<\/p><p>For those seeking to push beyond current boundaries, keep an eye on <a href=\"https:\/\/githubnext.com\/\">GitHub Next<\/a> where the future of AI-assisted development is being forged.<\/p><p>May your code be bug-free and your deployments swift!<\/p><p>Gassh\u014d \ud83d\ude4f<\/p><h4 id=\"additional-readings-from-the-github-blog\">Additional Readings from the GitHub Blog<\/h4><blockquote>  <p><strong>Note:<\/strong> GitHub Copilot Coding Agent is rapidly evolving! Some content in these posts reflects the development phase and may be outdated. Always check the <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/copilot\/how-tos\/agents\/copilot-coding-agent\">official documentation<\/a> for the most current information.<\/p><\/blockquote><ul>  <li><strong>July 15, 2025<\/strong> - <strong><a href=\"https:\/\/github.blog\/ai-and-ml\/github-copilot\/from-chaos-to-clarity-using-github-copilot-agents-to-improve-developer-workflows\/\">From chaos to clarity: Using GitHub Copilot agents to improve developer workflows<\/a><\/strong> - Learn how to set up Copilot coding agent for success.<\/li>  <li><strong>July 1, 2025<\/strong> - <strong><a href=\"https:\/\/github.blog\/ai-and-ml\/github-copilot\/from-idea-to-pr-a-guide-to-github-copilots-agentic-workflows\/\">From idea to PR: A guide to GitHub Copilot\u2019s agentic workflows<\/a><\/strong> - A practical guide demonstrating how to use Copilot\u2019s coding agent.<\/li>  <li><strong>June 6, 2025<\/strong> - <strong><a href=\"https:\/\/github.blog\/ai-and-ml\/github-copilot\/assigning-and-completing-issues-with-coding-agent-in-github-copilot\/\">Assigning and completing issues with coding agent in GitHub Copilot<\/a><\/strong> - A detailed walkthrough of the issue delegation workflow.<\/li>  <li><strong>June 5, 2025<\/strong> - <strong><a href=\"https:\/\/github.blog\/developer-skills\/github\/how-to-create-issues-and-pull-requests-in-record-time-on-github\/\">How to create issues and pull requests in record time<\/a><\/strong> - Learn the anatomy of well-structured issues and how Copilot amplifies your workflow.<\/li><\/ul>","url":"https:\/\/ghsioux.github.io\/2025\/07\/15\/getting-started-with-copilot-coding-agent","tags":["copilot","coding-agent","ai","automation","pull-request","issues"],"date_published":"2025-07-15T00:00:00+02:00","date_modified":"2025-07-15T00:00:00+02:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2025\/01\/09\/7-cool-things-with-rulesets","title":"7 Cool Things You Can Do with GitHub Rulesets","summary":"Explore GitHub rulesets and learn 7 cool things to improve your workflows, code quality, and security.","content_text":"As a GitHub enthusiast, I strive to make my repositories as pristine, efficient, and secure as a shinobi\u2019s blade \ud83e\udd77\u2694\ufe0f. Enter GitHub rulesets - a potent tool for automating and enforcing best practices across repositories and organizations.While GitHub already offers some nice examples (like ensuring tags follow the semantic versioning scheme) and ruleset recipes, I wanted to take things a bit further. In this post, we\u2019ll explore 7 powerful and practical ways to supercharge your repositories using GitHub rulesets.What makes this special? These use cases come straight from real-world customer challenges and scenarios I\u2019ve tackled.  \u26a1\ufe0f For each example, you\u2019ll find the corresponding ruleset JSON in the associated section and in this repository, ready for import into your own environment. Let\u2019s get started!1. Prevent Unauthorized CI\/CD ChangesProtecting your CI\/CD specifications from unauthorized changes is critical for maintaining a secure and reliable pipeline. This push ruleset prevents direct pushes to the .github\/workflows\/ directory using a path restriction, ensuring that only repository administrators can modify GitHub Actions workflows. This adds an additional layer of protection to your CI\/CD processes.   \ud83d\udcdc Ruleset JSON{  \"id\": 2949246,  \"name\": \"forbid-cicd-changes\",  \"target\": \"push\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": null,  \"rules\": [    {      \"type\": \"file_path_restriction\",      \"parameters\": {        \"restricted_file_paths\": [          \".github\/workflows\/*\"        ]      }    }  ],  \"bypass_actors\": [    {      \"actor_id\": 5,      \"actor_type\": \"RepositoryRole\",      \"bypass_mode\": \"always\"    }  ]}Other Use-Cases  Lock deployment scripts: Protect files like scripts\/deploy.sh to prevent unauthorized modifications.  Secure infrastructure-as-code files: Restrict changes to critical files such as terraform\/*.tf.  Protect configuration files: Limit updates to sensitive configurations, e.g., config\/*.yml.  Control dependency updates: Restrict updates to files like package.json or requirements.txt for tighter dependency management.2. Enforce Shorter File Paths for Legacy System CompatibilityLegacy systems often have strict file path length constraints, and exceeding these can cause deployment failures or runtime errors. This push ruleset ensures all file paths remain within a defined limit, preventing longer paths from being committed. It\u2019s an essential safeguard for repositories interacting with older or constrained systems.   \ud83d\udcdc Ruleset JSON{  \"id\": 2950733,  \"name\": \"legacy-system-filepath\",  \"target\": \"push\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": null,  \"rules\": [    {      \"type\": \"max_file_path_length\",      \"parameters\": {        \"max_file_path_length\": 255      }    }  ],  \"bypass_actors\": []}Other Use-Cases  Deployment reliability: Avoid issues during ZIP file generation or deployment processes caused by excessively long paths.  Repository organization: Maintain clean, manageable, and well-structured repositories by limiting overly nested file paths.3. Block Binary Files from Being Pushed into the RepositoryPreventing binary files from being pushed into your repository avoids unnecessary bloat, ensures faster cloning, and maintains better compatibility with Git versioning tools. This push ruleset restricts common binary file extensions, such as .exe, .bin, .dll, and more.   \ud83d\udcdc Ruleset JSON{  \"id\": 3003094,  \"name\": \"forbid-binary-files\",  \"target\": \"push\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": null,  \"rules\": [    {      \"type\": \"file_extension_restriction\",      \"parameters\": {        \"restricted_file_extensions\": [          \"*.exe\", \"*.bin\", \"*.dll\", \"*.so\", \"*.dmg\", \"*.msi\", \"*.app\",          \"*.zip\", \"*.tar\", \"*.gz\", \"*.rar\", \"*.7z\", \"*.xz\", \"*.bz2\",          \"*.iso\", \"*.vmdk\", \"*.qcow2\", \"*.img\",          \"*.dat\", \"*.db\", \"*.sqlite\", \"*.bak\", \"*.ldf\", \"*.mdf\",          \"*.ttf\", \"*.otf\", \"*.woff\", \"*.woff2\", \"*.eot\",          \"*.dwg\", \"*.dxf\", \"*.stl\", \"*.3ds\", \"*.obj\",          \"*.doc\", \"*.docx\", \"*.xls\", \"*.xlsx\", \"*.ppt\", \"*.pptx\",           \"*.pdf\", \"*.swp\", \"*.tmp\", \"*.bak\"        ]      }    }  ],  \"bypass_actors\": []}Other Use-Cases  Media file management: For file types like .jpg, .png, .mp4, or .mp3, consider creating a specific ruleset or leveraging Git LFS for efficient storage.  Optimize code review processes: Restrict binary files to ensure that code analysis and review tools function without interference, focusing exclusively on source code.  Prevent malware spread: Block potentially harmful files (e.g., .exe, .dll, .vbs, .js, .bat) from being pushed to the repository, reducing the risk of malware distribution within the codebase and ensuring a safer environment for contributors.4. Restrict Commits to Authors with Company Email AddressesEnsuring that commits come from authorized sources is crucial for compliance, accountability, and security. By restricting commits to authors with company email addresses, you can maintain organizational standards and prevent unauthorized contributions. This push ruleset validates the commit author\u2019s email pattern before allowing the commit to proceed.  \ud83d\udcdc Ruleset JSON{  \"id\": 3003187,  \"name\": \"commit-with-company-email\",  \"target\": \"branch\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": null,  \"rules\": [    {      \"type\": \"commit_author_email_pattern\",      \"parameters\": {        \"operator\": \"regex\",        \"pattern\": \"^[a-zA-Z0-9._%+-]+@company-domain\\\\.com$\",        \"negate\": false,        \"name\": \"\"      }    }  ],  \"bypass_actors\": []}Other Use-Cases  Audit and compliance: Maintain clear traceability of contributions to ensure that only internal team members are making changes, which is especially useful for security audits and compliance checks.  Enforce code ownership and responsibility: Helps track and maintain clear ownership, ensuring accountability for code contributions.5. Enforce Branch Naming PatternsMaintaining a clear and consistent branch naming structure is vital for effective collaboration and repository organization. Enforcing branch naming conventions, such as feature\/*, bugfix\/*, or release\/*, ensures that branches align with your team\u2019s development workflows. This branch ruleset helps streamline collaboration, making it easier to manage and identify different types of work, whether it\u2019s new features, bug fixes, or preparation for releases.  \ud83d\udcdc Ruleset JSON{  \"id\": 3139547,  \"name\": \"enforce-branch-naming-convention\",  \"target\": \"branch\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": {    \"ref_name\": {      \"exclude\": [        \"refs\/heads\/releases\/**\/*\",        \"refs\/heads\/feature\/**\/*\",        \"refs\/heads\/hotfix\/**\/*\"      ],      \"include\": []    }  },  \"rules\": [    {      \"type\": \"creation\"    }  ],  \"bypass_actors\": []}Additional Use Cases  Track specific work areas: Use naming conventions like ui\/*, backend\/*, or api\/* to categorize branches based on the type of work being done. This helps teams easily identify which parts of the application are being worked on and fosters better cross-functional collaboration.  Support multiple environments: Enforce patterns such as dev\/*, qa\/*, prod\/* for branches associated with different environments, ensuring each stage of the deployment pipeline is clearly defined and tracked.  Improved automated pipeline integration: Name branches like release\/* or feature\/* to trigger specific actions in CI\/CD pipelines, such as deployment to staging or triggering automated tests.6. Protecting The Production BranchOne of the most common and important rulesets in GitHub Enterprise accounts is protecting the production branch (e.g. main). Ensuring its integrity is essential for stable deployments and maintaining a reliable codebase. This branch ruleset enforces strict requirements for merging feature branches, guaranteeing that only thoroughly reviewed, high-quality, and secure code makes it to production.This ruleset requires the use of a pull request, which enforces the following safeguards:  Code review: At least 3 approvals are required, including from Code Owners.  Build and test: A GitHub Actions job must successfully execute a build and run tests - this is what we call a required status check.  Security scanning: A CodeQL scan must succeed, with no high or critical security alerts (this requires GitHub Advanced Security).A bypass list has been added to this ruleset, enabling repository owners to bypass it in critical situations, providing flexibility when needed.   \ud83d\udcdc Ruleset JSON{  \"id\": 106399,  \"name\": \"production-branch-protection\",  \"target\": \"branch\",  \"source_type\": \"Repository\",  \"source\": \"ghsioux\/cool-rulesets\",  \"enforcement\": \"active\",  \"conditions\": {    \"ref_name\": {      \"exclude\": [],      \"include\": [        \"~DEFAULT_BRANCH\"       ]    }  },  \"rules\": [    {      \"type\": \"pull_request\",      \"parameters\": {        \"required_approving_review_count\": 3,        \"dismiss_stale_reviews_on_push\": false,        \"require_code_owner_review\": true,        \"require_last_push_approval\": true,        \"required_review_thread_resolution\": true      }    },    {      \"type\": \"required_status_checks\",      \"parameters\": {        \"strict_required_status_checks_policy\": true,        \"do_not_enforce_on_create\": true,        \"required_status_checks\": [          {            \"context\": \"\ud83d\udea7 - Build &amp; Test\",            \"integration_id\": 15368          }        ]      }    },    {      \"type\": \"code_scanning\",      \"parameters\": {        \"code_scanning_tools\": [          {            \"tool\": \"CodeQL\",            \"security_alerts_threshold\": \"high_or_higher\",            \"alerts_threshold\": \"errors\"          }        ]      }    }  ],  \"bypass_actors\": [    {      \"actor_id\": 5,      \"actor_type\": \"RepositoryRole\",      \"bypass_mode\": \"always\"    }  ]}Other Use-Cases  Enforce quality gates: Add more required status checks, e.g. to ensure specific code coverage thresholds.  Control merge methods: Restrict merge methods (e.g., squash-only) for a consistent Git history.  Require deployment validation: Ensure changes are successfully deployed and tested in staging environment before merging to production.7. Ensure Code Adheres to Linting Standards Before MergingMaintaining consistent code quality across an organization requires enforcement of linting and formatting standards. This organization-level ruleset leverages repository custom properties and required workflows to ensure that branches in critical JavaScript\/TypeScript repositories adhere to an organization-provided linting workflow before changes can be merged into the default branch.Unlike repository-specific rulesets, this organization-wide approach scales effortlessly, applying uniform rules across all repositories meeting the defined criteria. Also, note that organization admins can bypass this ruleset if needed.  \ud83d\udcdc Ruleset JSON{  \"id\": 3135923,  \"name\": \"enforce-org-linting-standard\",  \"target\": \"branch\",  \"source_type\": \"Organization\",  \"source\": \"ghsioux-example-org\",  \"enforcement\": \"active\",  \"conditions\": {    \"ref_name\": {      \"exclude\": [],      \"include\": [        \"~DEFAULT_BRANCH\"      ]    },    \"repository_property\": {      \"exclude\": [],      \"include\": [        {          \"name\": \"language\",          \"source\": \"system\",          \"property_values\": [            \"JavaScript\",            \"TypeScript\"          ]        },        {          \"name\": \"criticality\",          \"source\": \"custom\",          \"property_values\": [            \"high\",            \"medium\"          ]        }      ]    }  },  \"rules\": [    {      \"type\": \"workflows\",      \"parameters\": {        \"do_not_enforce_on_create\": true,        \"workflows\": [          {            \"repository_id\": 586945170,            \"path\": \".github\/workflows\/lint.yaml\",            \"ref\": \"refs\/heads\/main\"          }        ]      }    }  ],  \"bypass_actors\": [    {      \"actor_id\": 1,      \"actor_type\": \"OrganizationAdmin\",      \"bypass_mode\": \"always\"    }  ]}Other Use-CasesYou can extend the concept of organization rulesets to implement compliance and consistency across repositories in your organization, such as by enforcing test automation, security scanning, and even the previous rulesets, ensuring that all projects follow the same processes.\ud83c\udf00 Bonus \ud83c\udf00Congratulations on making it to the end! That\u2019s the spirit of a true shinobi. To start the new year on a high note, here are some bonus tips just for you.Bonus 1: Enterprise RulesetsUntil now, we\u2019ve focused on repository and organization-level rulesets. With a recent update, you can now also create enterprise-level rulesets. If you\u2019re an enterprise owner on GitHub Enterprise, this is a powerful game-changer that streamlines governance and ensures consistency at scale across your organizations.Bonus 2: Enterprise Repository PoliciesBuilding on the same update, you can now define repository policies at the enterprise level. This gives you the ability to enforce consistent rules across repositories throughout your entire enterprise, improving centralized management and governance across organizations.Here are a few examples (click to expand):    \ud83d\udcf8 Protect Critical Repositories from Being Deleted        This policy ensures that only organization admins can delete repositories labeled with the custom property \"criticality\": \"high\". This safeguard prevents both accidental and malicious deletions. It is enforced across all organizations within the enterprise, helping to protect repositories that are essential for your organization's operations and security.        \ud83d\udcf8 Restrict Public Repository Creation         This policy restricts the creation of public repositories within your enterprise. It ensures that repositories can only be created as private or internal to promote innersourcing. This is an important safeguard to protect sensitive data and intellectual property from being exposed to the public. Note that this is the default behavior with Enterprise Managed Users.        \ud83d\udcf8 Enforce Repository Naming Conventions for IaC-specific Organizations        This policy targets organizations with names starting with iac-* and enforces a naming convention for their repositories. The repository names must begin with the environment (e.g., `prod-*`, `test-*`, `staging-*`).    Wrapping Up and Looking AheadWe\u2019ve explored how GitHub rulesets help streamline workflows, enforce policies, and ensure consistency across repositories and organizations. From blocking binary files to enforcing commit author patterns, these tools foster better collaboration and security.Like a Zen master refining their craft through meditation, the consistent application of these rules cultivates balance, focus, and discipline in your processes. Keep your practices sharp and your mind clear, and you\u2019ll master the art of streamlined, secure development.Like a Zen master refining their craft through meditation, the consistent application of these rules cultivates balance, focus, and discipline in your workflows. Keep your practices sharp and your mind clear, and you\u2019ll master the art of streamlined, secure development.Gassh\u014d \ud83d\ude4f","content_html":"<p>As a GitHub enthusiast, I strive to make my repositories as pristine, efficient, and secure as a shinobi\u2019s blade \ud83e\udd77\u2694\ufe0f. Enter GitHub <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/about-rulesets\">rulesets<\/a> - a potent tool for automating and enforcing best practices across repositories and organizations.<\/p><p>While GitHub already offers some <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/creating-rulesets-for-a-repository#useful-regular-expression-patterns\">nice examples<\/a> (like ensuring tags follow the <a href=\"https:\/\/semver.org\/\">semantic versioning<\/a> scheme) and <a href=\"https:\/\/github.com\/github\/ruleset-recipes\">ruleset recipes<\/a>, I wanted to take things a bit further. In this post, we\u2019ll explore 7 powerful and practical ways to supercharge your repositories using GitHub rulesets.<\/p><p>What makes this special? These use cases come straight from real-world customer challenges and scenarios I\u2019ve tackled.<\/p><blockquote>  <p>\u26a1\ufe0f For each example, you\u2019ll find the corresponding ruleset JSON in the associated section and in <a href=\"https:\/\/github.com\/ghsioux\/cool-rulesets\/\">this repository<\/a>, ready for <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/managing-rulesets-for-a-repository#importing-a-ruleset\">import<\/a> into your own environment. Let\u2019s get started!<\/p><\/blockquote><h3 id=\"1-prevent-unauthorized-cicd-changes\">1. Prevent Unauthorized CI\/CD Changes<\/h3><p>Protecting your CI\/CD specifications from unauthorized changes is critical for maintaining a secure and reliable pipeline. This push ruleset prevents direct pushes to the <code class=\"language-plaintext highlighter-rouge\">.github\/workflows\/<\/code> directory using <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#restrict-file-paths\">a path restriction<\/a>, ensuring that only repository administrators can modify GitHub Actions workflows. This adds an additional layer of protection to your CI\/CD processes.<\/p><details class=\"details-container\">  <summary class=\"details-summary\"> \ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">2949246<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"forbid-cicd-changes\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"push\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"file_path_restriction\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"restricted_file_paths\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">          <\/span><span class=\"s2\">\".github\/workflows\/*\"<\/span><span class=\"w\">        <\/span><span class=\"p\">]<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">5<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"RepositoryRole\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"bypass_mode\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"always\"<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases\">Other Use-Cases<\/h5><ul>  <li><strong>Lock deployment scripts<\/strong>: Protect files like <code class=\"language-plaintext highlighter-rouge\">scripts\/deploy.sh<\/code> to prevent unauthorized modifications.<\/li>  <li><strong>Secure infrastructure-as-code files<\/strong>: Restrict changes to critical files such as <code class=\"language-plaintext highlighter-rouge\">terraform\/*.tf<\/code>.<\/li>  <li><strong>Protect configuration files<\/strong>: Limit updates to sensitive configurations, e.g., <code class=\"language-plaintext highlighter-rouge\">config\/*.yml<\/code>.<\/li>  <li><strong>Control dependency updates<\/strong>: Restrict updates to files like <code class=\"language-plaintext highlighter-rouge\">package.json<\/code> or <code class=\"language-plaintext highlighter-rouge\">requirements.txt<\/code> for tighter dependency management.<\/li><\/ul><h3 id=\"2-enforce-shorter-file-paths-for-legacy-system-compatibility\">2. Enforce Shorter File Paths for Legacy System Compatibility<\/h3><p>Legacy systems often have strict file path length constraints, and exceeding these can cause deployment failures or runtime errors. This push ruleset ensures all file <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#restrict-file-path-length\">paths remain within a defined limit<\/a>, preventing longer paths from being committed. It\u2019s an essential safeguard for repositories interacting with older or constrained systems.<\/p><details class=\"details-container\">  <summary class=\"details-summary\"> \ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">2950733<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"legacy-system-filepath\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"push\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"max_file_path_length\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"max_file_path_length\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">255<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases-1\">Other Use-Cases<\/h5><ul>  <li><strong>Deployment reliability<\/strong>: Avoid issues during ZIP file generation or deployment processes caused by excessively long paths.<\/li>  <li><strong>Repository organization<\/strong>: Maintain clean, manageable, and well-structured repositories by limiting overly nested file paths.<\/li><\/ul><h3 id=\"3-block-binary-files-from-being-pushed-into-the-repository\">3. Block Binary Files from Being Pushed into the Repository<\/h3><p>Preventing binary files from being pushed into your repository avoids unnecessary bloat, ensures faster cloning, and maintains better compatibility with Git versioning tools. This push ruleset <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#restrict-file-extensions\">restricts common binary file extensions<\/a>, such as <code class=\"language-plaintext highlighter-rouge\">.exe<\/code>, <code class=\"language-plaintext highlighter-rouge\">.bin<\/code>, <code class=\"language-plaintext highlighter-rouge\">.dll<\/code>, and more.<\/p><details class=\"details-container\">  <summary class=\"details-summary\"> \ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">3003094<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"forbid-binary-files\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"push\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"file_extension_restriction\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"restricted_file_extensions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.exe\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.bin\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.dll\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.so\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.dmg\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.msi\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.app\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.zip\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.tar\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.gz\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.rar\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.7z\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.xz\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.bz2\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.iso\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.vmdk\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.qcow2\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.img\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.dat\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.db\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.sqlite\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.bak\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.ldf\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.mdf\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.ttf\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.otf\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.woff\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.woff2\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.eot\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.dwg\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.dxf\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.stl\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.3ds\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.obj\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"s2\">\"*.doc\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.docx\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.xls\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.xlsx\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.ppt\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.pptx\"<\/span><span class=\"p\">,<\/span><span class=\"w\">           <\/span><span class=\"s2\">\"*.pdf\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.swp\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.tmp\"<\/span><span class=\"p\">,<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"*.bak\"<\/span><span class=\"w\">        <\/span><span class=\"p\">]<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases-2\">Other Use-Cases<\/h5><ul>  <li><strong>Media file management<\/strong>: For file types like <code class=\"language-plaintext highlighter-rouge\">.jpg<\/code>, <code class=\"language-plaintext highlighter-rouge\">.png<\/code>, <code class=\"language-plaintext highlighter-rouge\">.mp4<\/code>, or <code class=\"language-plaintext highlighter-rouge\">.mp3<\/code>, consider creating a specific ruleset or leveraging <a href=\"https:\/\/git-lfs.github.com\/\">Git LFS<\/a> for efficient storage.<\/li>  <li><strong>Optimize code review processes<\/strong>: Restrict binary files to ensure that code analysis and review tools function without interference, focusing exclusively on source code.<\/li>  <li><strong>Prevent malware spread<\/strong>: Block potentially harmful files (e.g., <code class=\"language-plaintext highlighter-rouge\">.exe<\/code>, <code class=\"language-plaintext highlighter-rouge\">.dll<\/code>, <code class=\"language-plaintext highlighter-rouge\">.vbs<\/code>, <code class=\"language-plaintext highlighter-rouge\">.js<\/code>, <code class=\"language-plaintext highlighter-rouge\">.bat<\/code>) from being pushed to the repository, reducing the risk of malware distribution within the codebase and ensuring a safer environment for contributors.<\/li><\/ul><h3 id=\"4-restrict-commits-to-authors-with-company-email-addresses\">4. Restrict Commits to Authors with Company Email Addresses<\/h3><p>Ensuring that commits come from authorized sources is crucial for compliance, accountability, and security. By restricting commits to authors with company email addresses, you can maintain organizational standards and prevent unauthorized contributions. This push ruleset <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#metadata-restrictions\">validates the commit author\u2019s email pattern<\/a> before allowing the commit to proceed.<\/p><details class=\"details-container\">  <summary class=\"details-summary\">\ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">3003187<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"commit-with-company-email\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"branch\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">null<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"commit_author_email_pattern\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"operator\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"regex\"<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"pattern\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"^[a-zA-Z0-9._%+-]+@company-domain<\/span><span class=\"se\">\\\\<\/span><span class=\"s2\">.com$\"<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"negate\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">false<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"\"<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases-3\">Other Use-Cases<\/h5><ul>  <li><strong>Audit and compliance<\/strong>: Maintain clear traceability of contributions to ensure that only internal team members are making changes, which is especially useful for security audits and compliance checks.<\/li>  <li><strong>Enforce code ownership and responsibility<\/strong>: Helps track and maintain clear ownership, ensuring accountability for code contributions.<\/li><\/ul><h3 id=\"5-enforce-branch-naming-patterns\">5. Enforce Branch Naming Patterns<\/h3><p>Maintaining a clear and consistent branch naming structure is vital for effective collaboration and repository organization. Enforcing branch naming conventions, such as <code class=\"language-plaintext highlighter-rouge\">feature\/*<\/code>, <code class=\"language-plaintext highlighter-rouge\">bugfix\/*<\/code>, or <code class=\"language-plaintext highlighter-rouge\">release\/*<\/code>, ensures that branches align with your team\u2019s development workflows. This branch ruleset helps streamline collaboration, making it easier to manage and identify different types of work, whether it\u2019s new features, bug fixes, or preparation for releases.<\/p><details class=\"details-container\">  <summary class=\"details-summary\">\ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">3139547<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"enforce-branch-naming-convention\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"branch\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">    <\/span><span class=\"nl\">\"ref_name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"exclude\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">        <\/span><span class=\"s2\">\"refs\/heads\/releases\/**\/*\"<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"s2\">\"refs\/heads\/feature\/**\/*\"<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"s2\">\"refs\/heads\/hotfix\/**\/*\"<\/span><span class=\"w\">      <\/span><span class=\"p\">],<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"include\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[]<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">},<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"creation\"<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"additional-use-cases\">Additional Use Cases<\/h5><ul>  <li><strong>Track specific work areas<\/strong>: Use naming conventions like <code class=\"language-plaintext highlighter-rouge\">ui\/*<\/code>, <code class=\"language-plaintext highlighter-rouge\">backend\/*<\/code>, or <code class=\"language-plaintext highlighter-rouge\">api\/*<\/code> to categorize branches based on the type of work being done. This helps teams easily identify which parts of the application are being worked on and fosters better cross-functional collaboration.<\/li>  <li><strong>Support multiple environments<\/strong>: Enforce patterns such as <code class=\"language-plaintext highlighter-rouge\">dev\/*<\/code>, <code class=\"language-plaintext highlighter-rouge\">qa\/*<\/code>, <code class=\"language-plaintext highlighter-rouge\">prod\/*<\/code> for branches associated with different environments, ensuring each stage of the deployment pipeline is clearly defined and tracked.<\/li>  <li><strong>Improved automated pipeline integration<\/strong>: Name branches like <code class=\"language-plaintext highlighter-rouge\">release\/*<\/code> or <code class=\"language-plaintext highlighter-rouge\">feature\/*<\/code> to trigger specific actions in CI\/CD pipelines, such as deployment to staging or triggering automated tests.<\/li><\/ul><h3 id=\"6-protecting-the-production-branch\">6. Protecting The Production Branch<\/h3><p>One of the most common and important rulesets in GitHub Enterprise accounts is protecting the production branch (e.g. <code class=\"language-plaintext highlighter-rouge\">main<\/code>). Ensuring its integrity is essential for stable deployments and maintaining a reliable codebase. This branch ruleset enforces strict requirements for merging feature branches, guaranteeing that only thoroughly reviewed, high-quality, and secure code makes it to production.<\/p><p>This ruleset <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#require-a-pull-request-before-merging\">requires the use of a pull request<\/a>, which enforces the following safeguards:<\/p><ul>  <li><strong>Code review<\/strong>: At least 3 approvals are required, including from <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/managing-your-repositorys-settings-and-features\/customizing-your-repository\/about-code-owners\">Code Owners<\/a>.<\/li>  <li><strong>Build and test<\/strong>: A GitHub Actions <a href=\"https:\/\/github.com\/ghsioux\/cool-rulesets\/blob\/main\/.github\/workflows\/build-and-test.yml#L14\">job<\/a> must successfully execute a build and run tests - this is what we call a <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#require-status-checks-to-pass-before-merging\">required status check<\/a>.<\/li>  <li><strong>Security scanning<\/strong>: A CodeQL scan must succeed, with no high or critical security alerts (this requires <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/get-started\/learning-about-github\/about-github-advanced-security\">GitHub Advanced Security<\/a>).<\/li><\/ul><p>A bypass list has been added to this ruleset, enabling repository owners to bypass it in critical situations, providing flexibility when needed.<\/p><details class=\"details-container\">  <summary class=\"details-summary\"> \ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">106399<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"production-branch-protection\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"branch\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Repository\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux\/cool-rulesets\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">    <\/span><span class=\"nl\">\"ref_name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"exclude\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[],<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"include\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">        <\/span><span class=\"s2\">\"~DEFAULT_BRANCH\"<\/span><span class=\"w\">       <\/span><span class=\"p\">]<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">},<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"pull_request\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"required_approving_review_count\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">3<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"dismiss_stale_reviews_on_push\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">false<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"require_code_owner_review\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"require_last_push_approval\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"required_review_thread_resolution\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">},<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"required_status_checks\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"strict_required_status_checks_policy\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"do_not_enforce_on_create\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"required_status_checks\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">          <\/span><span class=\"p\">{<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"context\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"\ud83d\udea7 - Build &amp; Test\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"integration_id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">15368<\/span><span class=\"w\">          <\/span><span class=\"p\">}<\/span><span class=\"w\">        <\/span><span class=\"p\">]<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">},<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"code_scanning\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"code_scanning_tools\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">          <\/span><span class=\"p\">{<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"tool\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"CodeQL\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"security_alerts_threshold\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"high_or_higher\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"alerts_threshold\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"errors\"<\/span><span class=\"w\">          <\/span><span class=\"p\">}<\/span><span class=\"w\">        <\/span><span class=\"p\">]<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">5<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"RepositoryRole\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"bypass_mode\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"always\"<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases-4\">Other Use-Cases<\/h5><ul>  <li><strong>Enforce quality gates<\/strong>: Add more required status checks, e.g. to ensure specific code coverage thresholds.<\/li>  <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#additional-settings\"><strong>Control merge methods<\/strong><\/a>: Restrict merge methods (e.g., squash-only) for a consistent Git history.<\/li>  <li><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#require-deployments-to-succeed-before-merging\"><strong>Require deployment validation<\/strong><\/a>: Ensure changes are successfully deployed and tested in staging <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/actions\/writing-workflows\/choosing-what-your-workflow-does\/using-environments-for-deployment\">environment<\/a> before merging to production.<\/li><\/ul><h3 id=\"7-ensure-code-adheres-to-linting-standards-before-merging\">7. Ensure Code Adheres to Linting Standards Before Merging<\/h3><p>Maintaining consistent code quality across an organization requires enforcement of linting and formatting standards. This <strong>organization-level<\/strong> ruleset leverages <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/organizations\/managing-organization-settings\/managing-custom-properties-for-repositories-in-your-organization\">repository custom properties<\/a> and <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/configuring-branches-and-merges-in-your-repository\/managing-rulesets\/available-rules-for-rulesets#require-workflows-to-pass-before-merging\">required workflows<\/a> to ensure that branches in critical JavaScript\/TypeScript repositories adhere to an organization-provided linting workflow before changes can be merged into the default branch.<\/p><p>Unlike repository-specific rulesets, this organization-wide approach scales effortlessly, applying uniform rules across all repositories meeting the defined criteria. Also, note that organization admins can <strong>bypass<\/strong> this ruleset if needed.<\/p><details class=\"details-container\">  <summary class=\"details-summary\">\ud83d\udcdc Ruleset JSON<\/summary><figure class=\"highlight\"><pre><code class=\"language-json\" data-lang=\"json\"><span class=\"p\">{<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">3135923<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"enforce-org-linting-standard\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"target\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"branch\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"Organization\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"ghsioux-example-org\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"enforcement\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"active\"<\/span><span class=\"p\">,<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"conditions\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">    <\/span><span class=\"nl\">\"ref_name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"exclude\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[],<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"include\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">        <\/span><span class=\"s2\">\"~DEFAULT_BRANCH\"<\/span><span class=\"w\">      <\/span><span class=\"p\">]<\/span><span class=\"w\">    <\/span><span class=\"p\">},<\/span><span class=\"w\">    <\/span><span class=\"nl\">\"repository_property\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"exclude\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[],<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"include\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">        <\/span><span class=\"p\">{<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"language\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"system\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"property_values\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">            <\/span><span class=\"s2\">\"JavaScript\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"s2\">\"TypeScript\"<\/span><span class=\"w\">          <\/span><span class=\"p\">]<\/span><span class=\"w\">        <\/span><span class=\"p\">},<\/span><span class=\"w\">        <\/span><span class=\"p\">{<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"name\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"criticality\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"source\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"custom\"<\/span><span class=\"p\">,<\/span><span class=\"w\">          <\/span><span class=\"nl\">\"property_values\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">            <\/span><span class=\"s2\">\"high\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"s2\">\"medium\"<\/span><span class=\"w\">          <\/span><span class=\"p\">]<\/span><span class=\"w\">        <\/span><span class=\"p\">}<\/span><span class=\"w\">      <\/span><span class=\"p\">]<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">},<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"rules\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"workflows\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"parameters\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">{<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"do_not_enforce_on_create\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"kc\">true<\/span><span class=\"p\">,<\/span><span class=\"w\">        <\/span><span class=\"nl\">\"workflows\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">          <\/span><span class=\"p\">{<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"repository_id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">586945170<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"path\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\".github\/workflows\/lint.yaml\"<\/span><span class=\"p\">,<\/span><span class=\"w\">            <\/span><span class=\"nl\">\"ref\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"refs\/heads\/main\"<\/span><span class=\"w\">          <\/span><span class=\"p\">}<\/span><span class=\"w\">        <\/span><span class=\"p\">]<\/span><span class=\"w\">      <\/span><span class=\"p\">}<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">],<\/span><span class=\"w\">  <\/span><span class=\"nl\">\"bypass_actors\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"p\">[<\/span><span class=\"w\">    <\/span><span class=\"p\">{<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_id\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"mi\">1<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"actor_type\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"OrganizationAdmin\"<\/span><span class=\"p\">,<\/span><span class=\"w\">      <\/span><span class=\"nl\">\"bypass_mode\"<\/span><span class=\"p\">:<\/span><span class=\"w\"> <\/span><span class=\"s2\">\"always\"<\/span><span class=\"w\">    <\/span><span class=\"p\">}<\/span><span class=\"w\">  <\/span><span class=\"p\">]<\/span><span class=\"w\"><\/span><span class=\"p\">}<\/span><\/code><\/pre><\/figure><\/details><h5 id=\"other-use-cases-5\">Other Use-Cases<\/h5><p>You can extend the concept of organization rulesets to implement compliance and consistency across repositories in your organization, such as by enforcing test automation, security scanning, and even the previous rulesets, ensuring that all projects follow the same processes.<\/p><h3 id=\"-bonus-\">\ud83c\udf00 Bonus \ud83c\udf00<\/h3><p>Congratulations on making it to the end! That\u2019s the spirit of a true shinobi. To start the new year on a high note, here are some bonus tips just for you.<\/p><h4 id=\"bonus-1-enterprise-rulesets\">Bonus 1: Enterprise Rulesets<\/h4><p>Until now, we\u2019ve focused on repository and organization-level rulesets. With <a href=\"https:\/\/github.blog\/changelog\/2024-12-04-enterprise-repository-properties-policies-and-rulesets-public-preview\/\">a recent update<\/a>, you can now also create <strong>enterprise-level rulesets<\/strong>. If you\u2019re an <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-accounts-and-repositories\/managing-users-in-your-enterprise\/roles-in-an-enterprise#enterprise-owners\">enterprise owner<\/a> on GitHub Enterprise, this is a powerful game-changer that streamlines governance and ensures consistency at scale across your organizations.<\/p><h4 id=\"bonus-2-enterprise-repository-policies\">Bonus 2: Enterprise Repository Policies<\/h4><p>Building on the same update, you can now define <strong>repository policies<\/strong> at the enterprise level. This gives you the ability to enforce consistent rules across repositories throughout your entire enterprise, improving centralized management and governance across organizations.<\/p><p>Here are a few examples (click to expand):<\/p><details class=\"details-container\">    <summary class=\"details-summary\">\ud83d\udcf8 Protect Critical Repositories from Being Deleted<\/summary>        This policy ensures that only organization admins can delete repositories labeled with the custom property <code>\"criticality\": \"high\"<\/code>. This safeguard prevents both accidental and malicious deletions. It is enforced across all organizations within the enterprise, helping to protect repositories that are essential for your organization's operations and security.    <img src=\"\/assets\/images\/2025-01-09-7-cool-things-with-rulesets\/prevent-critical-repos-deletion.png\" alt=\"prevent critical repos deletion in enterprise\" \/><\/details><details class=\"details-container\">    <summary class=\"details-summary\">\ud83d\udcf8 Restrict Public Repository Creation <\/summary>        This policy restricts the creation of public repositories within your enterprise. It ensures that repositories can only be created as private or internal to promote innersourcing. This is an important safeguard to protect sensitive data and intellectual property from being exposed to the public. Note that this is the default behavior with <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/understanding-iam-for-enterprises\/about-enterprise-managed-users\">Enterprise Managed Users<\/a>.    <img src=\"\/assets\/images\/2025-01-09-7-cool-things-with-rulesets\/prevent-public-repo.png\" alt=\"prevent public repos in enterprise\" \/><\/details><details class=\"details-container\">    <summary class=\"details-summary\">\ud83d\udcf8 Enforce Repository Naming Conventions for IaC-specific Organizations<\/summary>        This policy targets organizations with names starting with <code>iac-*<\/code> and enforces a naming convention for their repositories. The repository names must begin with the environment (e.g., <code>`prod-*`<\/code>, <code>`test-*`<\/code>, <code>`staging-*`<\/code>).    <img src=\"\/assets\/images\/2025-01-09-7-cool-things-with-rulesets\/enforce-iac-repos-naming-convention.png\" alt=\"enforce iac repos naming convention\" \/><\/details><h2 id=\"wrapping-up-and-looking-ahead\">Wrapping Up and Looking Ahead<\/h2><p>We\u2019ve explored how GitHub rulesets help streamline workflows, enforce policies, and ensure consistency across repositories and organizations. From blocking binary files to enforcing commit author patterns, these tools foster better collaboration and security.<\/p><p>Like a Zen master refining their craft through meditation, the consistent application of these rules cultivates balance, focus, and discipline in your processes. Keep your practices sharp and your mind clear, and you\u2019ll master the art of streamlined, secure development.<\/p><p>Like a Zen master refining their craft through meditation, the consistent application of these rules cultivates balance, focus, and discipline in your workflows. Keep your practices sharp and your mind clear, and you\u2019ll master the art of streamlined, secure development.<\/p><p>Gassh\u014d \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2025\/01\/09\/7-cool-things-with-rulesets","tags":["rulesets","policies","compliance","best-practices"],"date_published":"2025-01-09T00:00:00+01:00","date_modified":"2025-01-09T00:00:00+01:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2024\/12\/10\/securing-workflow-immutable-actions","title":"Securing GitHub Actions workflows with Immutable Actions","summary":"A deep dive into the power of immutable actions, wildcard versioning, and build provenance using artifact attestations in GitHub Actions.","content_text":"Long time no see!I\u2019ve been sharpening my skills in the DevSecOps peaks \u26f0\ufe0f\ud83c\udfd4\ufe0f\u26f0\ufe0f. Now, I\u2019m back stronger, ready for new quests\u2014hope you\u2019ve been practicing too.Recently, a customer posed an intriguing challenge: Could Immutable Actions disrupt the way workflows reference actions? This led me deep into the lore of GitHub Actions. The verdict? No worries. Why? Immutable actions wildcard versioning and resolution make it seamless.Before we dive into this enigma, let\u2019s set the stage: What are Immutable Actions? Why are they vital? And how do artifact attestations fit into the picture? Alright, ninja \ud83e\udd77, let\u2019s resume our journey.  \u26a0\ufe0f Note: At the time of writing, Immutable Actions are in limited public preview and subject to change.1 - The Genesis: Artifact AttestationsArtifact attestations in GitHub [1] [2] enhance supply chain security by cryptographically linking artifacts such as binaries to their source code and build process. They ensure both integrity and provenance, reducing the risk of tampered or malicious software:      Integrity: By using cryptographic signatures, artifact attestations ensure that the artifact remains untampered with since its creation. GitHub utilizes Sigstore for these cryptographic signatures.        Origin: Provenance, or the origin of the artifact, is verified through detailed metadata contained in the attestations. This includes for instance the specific commit, the GitHub Actions workflow, and the build environment, allowing full traceability back to the original source. GitHub uses the Provenance feature from OpenSSF\u2019s SLSA (Supply Chain Levels for Software Artifacts) framework to provide this.  For developers and teams, this means greater confidence in the security of dependencies and reduced risk from compromised build environments. The following table compares the security implications of artifacts with and without cryptographic signatures, and with and without provenance metadata:            \u00a0      With Cryptographic Signature      Without Cryptographic Signature                  With Provenance Metadata      \ud83d\udfe2 Secure- Full traceability.- Artifact integrity assured.- Minimal risk (if implemented correctly).      \ud83d\udfe1 Limited Security- Traceability available.- Artifacts may be tampered post-build.- Risks of distribution attacks (e.g., artifact substitution).              Without Provenance Metadata      \ud83d\udfe1 Limited Security- Artifact integrity assured.- No traceability.- Loss of reproducibility.- Builds from unverified sources.      \ud83d\udd34 Insecure- No traceability or integrity assurance.- High risk of malicious artifacts and insecure builds.      As a last note, remember that attestations are only effective if verified, making it crucial to validate signed artifacts, particularly for binaries, packages, and manifests.2 - The Next Step: Immutable ActionsNow that we know what are artifact attestations, let\u2019s take these concepts a step further and apply them to GitHub Actions. Just like build artifacts, it\u2019s essential to ensure that the actions used in workflows are trustworthy and secure. The good news is that we can achieve this through Immutable Actions.Immutable Actions are a new feature in GitHub that ensures the actions used in CI\/CD pipelines are secured and untampered. Let\u2019s break down how Immutable Actions work with three essential features:      Secure Publishing Flow  Immutable Actions are published through a secure process using an Actions token as part of a workflow run. This ensures that the action is firmly tied to its source repository. Furthermore, artifact attestations are generated to verify the publishing process, ensuring that actions are legitimate.        Package and Tag Immutability  Once an action is published, it is served as a package from GHCR and its version becomes immutable. This means that tags and branches can\u2019t be overwritten or changed to point to different artifacts. This feature guarantees that the action version remains consistent over time, protecting against tampering and unexpected changes.        Locking Down Actions Resolution  With Immutable Actions, GitHub enforces strict semantic versioning with automatic wildcard resolution (\u2726\u2726 see next section). This ensures that workflows use actions that have a stable and verifiable version. For instance, the action\u2019s reference cannot change to a different commit unless the version number reflects it. This prevents mutable references (like branches and tags) from altering the behavior of workflows unexpectedly.  Let\u2019s explore how Immutable Actions compare to the mutable ones and how they mitigate common security risks:            Aspect      Before Immutable Actions      With Immutable Actions                  Source &amp; Behavior      Actions fetched as code from GitHub using mutable git tags, making them less traceable and prone to unexpected changes.      Actions served as packages from ghcr.io, resolved with immutable package versions, ensuring better traceability and consistency.              (Im)mutability      Vulnerable to tag mutations, allowing potentially malicious code changes.      Secure resolution with immutable tags and verified publishing flow, preventing tampering.              Versioning      Wildcard versions (e.g. v1) manually maintained, leading to inconsistencies.      Reliable resolution of wildcard versions to the latest matching package (e.g. v1 -&gt; 1.3.2), eliminating versioning issues (\u2726\u2726 see next section).      3 - A note on versioning and resolutionBefore Immutable Actions, actions in workflows were referenced using mutable tags or branches, e.g.:uses: my-org\/my-action@v1       # taguses: my-org\/my-action@v1.3.2   # taguses: my-org\/my-action@main     # branchWhile referencing by commit SHA (my-org\/my-action@f4b1...73aa) was possible - and the most secure way since not mutable -  it was not an ideal solution from a user experience perspective due to its lack of flexibility.Immutable Actions introduce wildcard versioning to balance stability and flexibility in GitHub workflows. This features allows tag-like references such as v1.3 in workflows to automatically resolve to the latest immutable action package matching the semantic version 1.3.z. As a result, immutable actions in workflows can now be referenced either via their strict package version (e.g. my-org\/my-action@1.3.2, note the absence of v prefix), or via tag-like references potentially with wildcard versioning (e.g my-org\/my-action@v1.3).The following diagram demonstrates how GitHub resolves wildcard references to the latest matching package version:While wildcard versioning and resolution provides flexibility, it challenges the core principle of immutability. Immutable Actions ensure an action\u2019s content and behavior remain consistent, making dynamic changes from wildcard references potentially problematic. For example, if a workflow references v1, it might unintentionally introduce behavior changes with a new minor or patch release, like moving from 1.2 to 1.3. For maximum stability and immutability, it\u2019s recommended to pin actions to a specific version, such as 1.3.2.4 - Practical ExampleEnough theory, let\u2019s now see how to use Immutable Actions in practice. We\u2019ll use this demo repository which has Immutable Actions enabled to showcase how they work. It contains a typical structure for a simple custom action written in JavaScript:  index.js: the action code (it just prints a message to the standard output);  action.yml: the action\u2019s metadata file;  package.json: the action\u2019s package file.In addition, we have the publish-immutable-actions.yml workflow file, triggered when a new released is created to publish the immutable action:name: \"Publish Immutable Action Version\"on:  release:    types: [created]jobs:  publish:    runs-on: ubuntu-latest    permissions:      contents: read      id-token: write      packages: write    steps:      - name: Checking out        uses: actions\/checkout@v4      - name: Publish        id: publish        uses: actions\/publish-immutable-action@0.0.1        with:          github-token: ${{ secrets.GITHUB_TOKEN }}All the magic happens in the publish-immutable-action action.I created and pushed the tag v1.0.0, created a release from this tag and the immutable action has been published accordingly (you can see the attestation has been published too in the job\u2019s log). The corresponding package in GHCR has the label Immutable.I can verify the attestation of the immutable action using the GitHub CLI:# General verification$ gh attestation verify oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0 --bundle-from-oci --owner ghsiouxLoaded digest sha256:59ec50c64e24213772a37b17715946a133de7b1bef33885a49bf691ea03f5ae5 for oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0Loaded 1 attestation from oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0\u2713 Verification succeeded!sha256:59ec50c64e24213772a37b17715946a133de7b1bef33885a49bf691ea03f5ae5 was attested by:REPO                           PREDICATE_TYPE                  WORKFLOWghsioux\/immutable-action-demo  https:\/\/slsa.dev\/provenance\/v1  .github\/workflows\/publish-immutable-actions.yml@refs\/tags\/v1.0.0# Retrieve the associated commit$ gh attestation verify oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0 --bundle-from-oci --owner ghsioux --format json | jq '.[0].verificationResult.statement.predicate.buildDefinition.resolvedDependencies[0].digest.gitCommit'\"653ed94bd9425e1e50c8de8002f16bbe22e84f38\"I\u2019ve then updated the action code to print a new message and published a new version 1.0.1 of the immutable action following the same process.Let\u2019s now test the action with the following workflow:name: \"Test Immutable Action\"on:  workflow_dispatch:jobs:  publish:    runs-on: ubuntu-latest    steps:      - name: Test immutable action (strict SemVer) # Using a specific immutable package version        uses: ghsioux\/immutable-action-demo@1.0.0         # Resolves directly to the immutable action package version 1.0.0,        # ensuring the exact behavior of the action as defined at that version.      - name: Test tag resolution to package version (full tag) # Resolves a tag to the corresponding package version        uses: ghsioux\/immutable-action-demo@v1.0.0        # The tag v1.0.0 resolves to the immutable action package version 1.0.0.        # This verifies that full tags correctly map to their corresponding immutable packages.      - name: Test tag resolution to package version (wildcard versioning patch version)        uses: ghsioux\/immutable-action-demo@v1.0        # The tag v1.0 resolves to the latest immutable action package matching version 1.0.x.        # This tests the patch-level wildcard resolution in Immutable Actions.      - name: Test tag resolution to package version (wildcard versioning minor version)        uses: ghsioux\/immutable-action-demo@v1        # The tag v1 resolves to the latest immutable action package matching version 1.x.y.        # This tests the minor-level wildcard resolution in Immutable Actions.In the workflow logs, we can see the following sequence of printed messages:Hello immutable shinobi!Hello immutable shinobi!Goodbye immutable shinobi!Goodbye immutable shinobi!Proving the action has been correctly resolved from tag to package version, supporting also wildcard versioning (v1 and v1.0 tags both resolving to action package version 1.0.1).That\u2019s nice. Now let\u2019s test some corner cases. What if I create a tag v1.0.2 without publishing a corresponding immutable action and try to use it in a workflow? As expected, that simply does not work because there is no immutable action matching the version 1.0.2:Now let\u2019s tackle immutability. I\u2019ve initially created a new tag v1.0.3 from commit 231b99f  and published the corresponding immutable action 1.0.3. I then updated the code of the action (commit be580c03) and made the remote tag v1.0.3 to point to this new commit. I removed the original v1.0.3 release, created it again, and guess what? Trying to create a new immutable action with that same tag failed with the error:5 - ConclusionIn this journey, we\u2019ve explored how Immutable Actions and artifact attestations fortify GitHub Actions workflows. By cryptographically signing actions and verifying their provenance, we can enhance the security of CI\/CD pipelines, bolstering the overall supply chain\u2019s integrity.But this is just the beginning. Immutable Actions lay the groundwork for a more robust future in DevSecOps. By adopting these practices, you not only protect your workflows but also contribute to a more secure ecosystem for everyone.In the dojo, we learn the value of collaboration. A big shoutout to the amazing team that helped unravel the inner workings of Immutable Actions: @tinaheidinger, @thyeggman, @konradpabjan, @conorsloan, @jcambass and @steve-glass.Stay vigilant, and keep your workflows secure, shinobi! \ud83e\udd77Gassh\u014d \ud83d\ude4f","content_html":"<p><strong>Long time no see!<\/strong><\/p><p>I\u2019ve been sharpening my skills in the DevSecOps peaks \u26f0\ufe0f\ud83c\udfd4\ufe0f\u26f0\ufe0f. Now, I\u2019m back stronger, ready for new quests\u2014hope you\u2019ve been practicing too.<\/p><p>Recently, a customer posed an intriguing challenge: <strong>Could Immutable Actions disrupt the way workflows reference actions?<\/strong> This led me deep into the lore of GitHub Actions. The verdict? <strong>No worries<\/strong>. Why? Immutable actions wildcard versioning and resolution make it seamless.<\/p><p>Before we dive into this enigma, let\u2019s set the stage: What are Immutable Actions? Why are they vital? And how do artifact attestations fit into the picture? Alright, ninja \ud83e\udd77, let\u2019s resume our journey.<\/p><blockquote>  <p>\u26a0\ufe0f <strong>Note:<\/strong> At the time of writing, Immutable Actions are in <a href=\"https:\/\/github.com\/features\/preview\/immutable-actions\">limited public preview<\/a> and subject to change.<\/p><\/blockquote><h2 id=\"1---the-genesis-artifact-attestations\">1 - The Genesis: Artifact Attestations<\/h2><p><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/actions\/security-for-github-actions\/using-artifact-attestations\/using-artifact-attestations-to-establish-provenance-for-builds\">Artifact attestations in GitHub<\/a> [<a href=\"https:\/\/github.blog\/security\/supply-chain-security\/introducing-npm-package-provenance\/\">1<\/a>] [<a href=\"https:\/\/github.blog\/security\/supply-chain-security\/configure-github-artifact-attestations-for-secure-cloud-native-delivery\/\">2<\/a>] enhance <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/code-security\/supply-chain-security\/understanding-your-software-supply-chain\/about-supply-chain-security\">supply chain security<\/a> by cryptographically linking <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/actions\/writing-workflows\/choosing-what-your-workflow-does\/storing-and-sharing-data-from-a-workflow#about-workflow-artifacts\">artifacts<\/a> such as binaries to their source code and build process. They ensure both integrity and provenance, reducing the risk of tampered or malicious software:<\/p><ul>  <li>    <p><strong>Integrity:<\/strong> By using cryptographic signatures, artifact attestations ensure that the artifact remains untampered with since its creation. GitHub utilizes Sigstore for these cryptographic signatures.<\/p>  <\/li>  <li>    <p><strong>Origin:<\/strong> Provenance, or the origin of the artifact, is verified through detailed metadata contained in the attestations. This includes for instance the specific commit, the GitHub Actions workflow, and the build environment, allowing full traceability back to the original source. GitHub uses the <a href=\"https:\/\/slsa.dev\/spec\/v1.0\/provenance\">Provenance feature<\/a> from <a href=\"https:\/\/slsa.dev\/\">OpenSSF\u2019s SLSA<\/a> (Supply Chain Levels for Software Artifacts) framework to provide this.<\/p>  <\/li><\/ul><p>For developers and teams, this means greater confidence in the security of dependencies and reduced risk from compromised build environments. The following table compares the security implications of artifacts with and without cryptographic signatures, and with and without provenance metadata:<\/p><table>  <thead>    <tr>      <th>\u00a0<\/th>      <th><strong>With Cryptographic Signature<\/strong><\/th>      <th><strong>Without Cryptographic Signature<\/strong><\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td><strong>With Provenance Metadata<\/strong><\/td>      <td>\ud83d\udfe2 <strong>Secure<\/strong><br \/>- Full traceability.<br \/>- Artifact integrity assured.<br \/>- Minimal risk (if implemented correctly).<\/td>      <td>\ud83d\udfe1 <strong>Limited Security<\/strong><br \/>- Traceability available.<br \/>- Artifacts may be tampered post-build.<br \/>- Risks of distribution attacks (e.g., artifact substitution).<\/td>    <\/tr>    <tr>      <td><strong>Without Provenance Metadata<\/strong><\/td>      <td>\ud83d\udfe1 <strong>Limited Security<\/strong><br \/>- Artifact integrity assured.<br \/>- No traceability.<br \/>- Loss of reproducibility.<br \/>- Builds from unverified sources.<\/td>      <td>\ud83d\udd34 <strong>Insecure<\/strong><br \/>- No traceability or integrity assurance.<br \/>- High risk of malicious artifacts and insecure builds.<\/td>    <\/tr>  <\/tbody><\/table><p>As a last note, remember that attestations are only effective if <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/actions\/security-for-github-actions\/using-artifact-attestations\/using-artifact-attestations-to-establish-provenance-for-builds#verifying-artifact-attestations-with-the-github-cli\">verified<\/a>, making it crucial to validate signed artifacts, particularly for binaries, packages, and manifests.<\/p><h2 id=\"2---the-next-step-immutable-actions\">2 - The Next Step: Immutable Actions<\/h2><p>Now that we know what are artifact attestations, let\u2019s take these concepts a step further and apply them to <strong>GitHub Actions<\/strong>. Just like build artifacts, it\u2019s essential to ensure that the actions used in workflows are trustworthy and secure. The good news is that we can achieve this through <strong>Immutable Actions<\/strong>.<\/p><p>Immutable Actions are a new feature in GitHub that ensures the actions used in CI\/CD pipelines are secured and untampered. Let\u2019s break down how Immutable Actions work with three essential features:<\/p><ul>  <li>    <p><strong>Secure Publishing Flow<\/strong><br \/>  Immutable Actions are published through a secure process using an Actions token as part of a workflow run. This ensures that the action is firmly tied to its source repository. Furthermore, <strong>artifact attestations<\/strong> are generated to verify the publishing process, ensuring that actions are legitimate.<\/p>  <\/li>  <li>    <p><strong>Package and Tag Immutability<\/strong><br \/>  Once an action is published, it is served as a package from <a href=\"https:\/\/docs.github.com\/en\/packages\/working-with-a-github-packages-registry\/working-with-the-container-registry\">GHCR<\/a> and its version becomes immutable. This means that tags and branches can\u2019t be overwritten or changed to point to different artifacts. This feature guarantees that the action version remains consistent over time, protecting against tampering and unexpected changes.<\/p>  <\/li>  <li>    <p><strong>Locking Down Actions Resolution<\/strong><br \/>  With Immutable Actions, GitHub enforces strict <a href=\"https:\/\/semver.org\/\">semantic versioning<\/a> with automatic wildcard resolution (\u2726\u2726 see next section). This ensures that workflows use actions that have a stable and verifiable version. For instance, the action\u2019s reference cannot change to a different commit unless the version number reflects it. This prevents mutable references (like branches and tags) from altering the behavior of workflows unexpectedly.<\/p>  <\/li><\/ul><p>Let\u2019s explore how Immutable Actions compare to the mutable ones and how they mitigate common security risks:<\/p><table>  <thead>    <tr>      <th>Aspect<\/th>      <th>Before Immutable Actions<\/th>      <th>With Immutable Actions<\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td><strong>Source &amp; Behavior<\/strong><\/td>      <td>Actions fetched <strong>as code<\/strong> from GitHub using mutable git tags, making them less traceable and prone to unexpected changes.<\/td>      <td>Actions served <strong>as packages<\/strong> from <code class=\"language-plaintext highlighter-rouge\">ghcr.io<\/code>, resolved with immutable package versions, ensuring better traceability and consistency.<\/td>    <\/tr>    <tr>      <td><strong>(Im)mutability<\/strong><\/td>      <td>Vulnerable to tag mutations, allowing potentially malicious code changes.<\/td>      <td>Secure resolution with immutable tags and verified publishing flow, preventing tampering.<\/td>    <\/tr>    <tr>      <td><strong>Versioning<\/strong><\/td>      <td>Wildcard versions (e.g. <code class=\"language-plaintext highlighter-rouge\">v1<\/code>) manually maintained, leading to inconsistencies.<\/td>      <td>Reliable resolution of wildcard versions to the latest matching package (e.g. <code class=\"language-plaintext highlighter-rouge\">v1 -&gt; 1.3.2<\/code>), eliminating versioning issues (\u2726\u2726 see next section).<\/td>    <\/tr>  <\/tbody><\/table><h2 id=\"3---a-note-on-versioning-and-resolution\">3 - A note on versioning and resolution<\/h2><p>Before Immutable Actions, actions in workflows were referenced using mutable tags or branches, e.g.:<\/p><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>uses: my-org\/my-action@v1       # taguses: my-org\/my-action@v1.3.2   # taguses: my-org\/my-action@main     # branch<\/code><\/pre><\/div><\/div><p>While referencing by commit SHA (<code class=\"language-plaintext highlighter-rouge\">my-org\/my-action@f4b1...73aa<\/code>) was possible - and the most secure way since not mutable -  it was not an ideal solution from a user experience perspective due to its lack of flexibility.<\/p><p>Immutable Actions introduce wildcard versioning to balance stability and flexibility in GitHub workflows. This features allows tag-like references such as <code class=\"language-plaintext highlighter-rouge\">v1.3<\/code> in workflows to automatically resolve to the latest immutable action package matching the semantic version <code class=\"language-plaintext highlighter-rouge\">1.3.z<\/code>. As a result, immutable actions in workflows can now be referenced either via their strict package version (e.g. <code class=\"language-plaintext highlighter-rouge\">my-org\/my-action@1.3.2<\/code>, note the absence of <code class=\"language-plaintext highlighter-rouge\">v<\/code> prefix), <strong>or<\/strong> via tag-like references potentially with wildcard versioning (e.g <code class=\"language-plaintext highlighter-rouge\">my-org\/my-action@v1.3<\/code>).<\/p><p>The following diagram demonstrates how GitHub resolves wildcard references to the latest matching package version:<\/p><p><img src=\"\/assets\/images\/2024-12-10-securing-workflow-immutable-actions\/wildcard-resolution.png\" alt=\"Wildcard resolution example\" title=\"Wildcard resolution example\" \/><\/p><p>While wildcard versioning and resolution provides flexibility, it challenges the core principle of immutability. Immutable Actions ensure an action\u2019s content and behavior remain consistent, making dynamic changes from wildcard references potentially problematic. For example, if a workflow references <code class=\"language-plaintext highlighter-rouge\">v1<\/code>, it might unintentionally introduce behavior changes with a new minor or patch release, like moving from <code class=\"language-plaintext highlighter-rouge\">1.2<\/code> to <code class=\"language-plaintext highlighter-rouge\">1.3<\/code>. For maximum stability and immutability, it\u2019s recommended to pin actions to a specific version, such as <code class=\"language-plaintext highlighter-rouge\">1.3.2<\/code>.<\/p><h2 id=\"4---practical-example\">4 - Practical Example<\/h2><p>Enough theory, let\u2019s now see how to use Immutable Actions in practice. We\u2019ll use <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\">this demo repository<\/a> which has Immutable Actions enabled to showcase how they work. It contains a typical structure for a simple custom action written in JavaScript:<\/p><ul>  <li><code class=\"language-plaintext highlighter-rouge\">index.js<\/code>: the action code (it just prints a message to the standard output);<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">action.yml<\/code>: the action\u2019s metadata file;<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">package.json<\/code>: the action\u2019s package file.<\/li><\/ul><p>In addition, we have <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/blob\/main\/.github\/workflows\/publish-immutable-actions.yml\">the <code class=\"language-plaintext highlighter-rouge\">publish-immutable-actions.yml<\/code> workflow file<\/a>, triggered when a new released is created to publish the immutable action:<\/p><div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s2\">\"<\/span><span class=\"s\">Publish<\/span><span class=\"nv\"> <\/span><span class=\"s\">Immutable<\/span><span class=\"nv\"> <\/span><span class=\"s\">Action<\/span><span class=\"nv\"> <\/span><span class=\"s\">Version\"<\/span><span class=\"na\">on<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">release<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">types<\/span><span class=\"pi\">:<\/span> <span class=\"pi\">[<\/span><span class=\"nv\">created<\/span><span class=\"pi\">]<\/span><span class=\"na\">jobs<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">publish<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">runs-on<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ubuntu-latest<\/span>    <span class=\"na\">permissions<\/span><span class=\"pi\">:<\/span>      <span class=\"na\">contents<\/span><span class=\"pi\">:<\/span> <span class=\"s\">read<\/span>      <span class=\"na\">id-token<\/span><span class=\"pi\">:<\/span> <span class=\"s\">write<\/span>      <span class=\"na\">packages<\/span><span class=\"pi\">:<\/span> <span class=\"s\">write<\/span>    <span class=\"na\">steps<\/span><span class=\"pi\">:<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Checking out<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">actions\/checkout@v4<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Publish<\/span>        <span class=\"na\">id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">publish<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">actions\/publish-immutable-action@0.0.1<\/span>        <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>          <span class=\"na\">github-token<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.GITHUB_TOKEN }}<\/span><\/code><\/pre><\/div><\/div><p>All the magic happens in <a href=\"https:\/\/github.com\/actions\/publish-immutable-action\">the <code class=\"language-plaintext highlighter-rouge\">publish-immutable-action<\/code> action<\/a>.<\/p><p>I created and pushed <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/releases\/tag\/v1.0.0\">the tag <code class=\"language-plaintext highlighter-rouge\">v1.0.0<\/code><\/a>, created <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/releases\/tag\/v1.0.0\">a release<\/a> from this tag and the immutable action <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12175417462\/job\/33959091043\">has been published accordingly<\/a> (you can see the attestation has been published too in the job\u2019s log). <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/pkgs\/container\/immutable-action-demo\/317337038?tag=1.0.0\">The corresponding package<\/a> in GHCR has the label <code class=\"language-plaintext highlighter-rouge\">Immutable<\/code>.<\/p><p><img src=\"\/assets\/images\/2024-12-10-securing-workflow-immutable-actions\/immutable-action-package.png\" alt=\"Immutable action package version 1.0.0\" title=\"Immutable action package version 1.0.0\" \/><\/p><p>I can verify the attestation of the immutable action using <a href=\"https:\/\/cli.github.com\/\">the GitHub CLI<\/a>:<\/p><div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"c\"># General verification<\/span><span class=\"nv\">$ <\/span>gh attestation verify oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0 <span class=\"nt\">--bundle-from-oci<\/span> <span class=\"nt\">--owner<\/span> ghsiouxLoaded digest sha256:59ec50c64e24213772a37b17715946a133de7b1bef33885a49bf691ea03f5ae5 <span class=\"k\">for <\/span>oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0Loaded 1 attestation from oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0\u2713 Verification succeeded!sha256:59ec50c64e24213772a37b17715946a133de7b1bef33885a49bf691ea03f5ae5 was attested by:REPO                           PREDICATE_TYPE                  WORKFLOWghsioux\/immutable-action-demo  https:\/\/slsa.dev\/provenance\/v1  .github\/workflows\/publish-immutable-actions.yml@refs\/tags\/v1.0.0<span class=\"c\"># Retrieve the associated commit<\/span><span class=\"nv\">$ <\/span>gh attestation verify oci:\/\/ghcr.io\/ghsioux\/immutable-action-demo:1.0.0 <span class=\"nt\">--bundle-from-oci<\/span> <span class=\"nt\">--owner<\/span> ghsioux <span class=\"nt\">--format<\/span> json | jq <span class=\"s1\">'.[0].verificationResult.statement.predicate.buildDefinition.resolvedDependencies[0].digest.gitCommit'<\/span><span class=\"s2\">\"653ed94bd9425e1e50c8de8002f16bbe22e84f38\"<\/span><\/code><\/pre><\/div><\/div><p>I\u2019ve then <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/commit\/f4b1295e2051fd43a5085dd9514f5ae823ce73aa\">updated the action code<\/a> to print a new message and <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12175547252\">published a new version <code class=\"language-plaintext highlighter-rouge\">1.0.1<\/code><\/a> of the immutable action following the same process.<\/p><p>Let\u2019s now test the action with <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/blob\/main\/.github\/workflows\/test-immutable-action.yml\">the following workflow<\/a>:<\/p><div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s2\">\"<\/span><span class=\"s\">Test<\/span><span class=\"nv\"> <\/span><span class=\"s\">Immutable<\/span><span class=\"nv\"> <\/span><span class=\"s\">Action\"<\/span><span class=\"na\">on<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">workflow_dispatch<\/span><span class=\"pi\">:<\/span><span class=\"na\">jobs<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">publish<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">runs-on<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ubuntu-latest<\/span>    <span class=\"na\">steps<\/span><span class=\"pi\">:<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Test immutable action (strict SemVer)<\/span> <span class=\"c1\"># Using a specific immutable package version<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ghsioux\/immutable-action-demo@1.0.0<\/span>         <span class=\"c1\"># Resolves directly to the immutable action package version 1.0.0,<\/span>        <span class=\"c1\"># ensuring the exact behavior of the action as defined at that version.<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Test tag resolution to package version (full tag)<\/span> <span class=\"c1\"># Resolves a tag to the corresponding package version<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ghsioux\/immutable-action-demo@v1.0.0<\/span>        <span class=\"c1\"># The tag v1.0.0 resolves to the immutable action package version 1.0.0.<\/span>        <span class=\"c1\"># This verifies that full tags correctly map to their corresponding immutable packages.<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Test tag resolution to package version (wildcard versioning patch version)<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ghsioux\/immutable-action-demo@v1.0<\/span>        <span class=\"c1\"># The tag v1.0 resolves to the latest immutable action package matching version 1.0.x.<\/span>        <span class=\"c1\"># This tests the patch-level wildcard resolution in Immutable Actions.<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Test tag resolution to package version (wildcard versioning minor version)<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ghsioux\/immutable-action-demo@v1<\/span>        <span class=\"c1\"># The tag v1 resolves to the latest immutable action package matching version 1.x.y.<\/span>        <span class=\"c1\"># This tests the minor-level wildcard resolution in Immutable Actions.<\/span><\/code><\/pre><\/div><\/div><p>In <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12175629284\/job\/33959726210\">the workflow logs<\/a>, we can see the following sequence of printed messages:<\/p><div class=\"language-bash highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>Hello immutable shinobi!Hello immutable shinobi!Goodbye immutable shinobi!Goodbye immutable shinobi!<\/code><\/pre><\/div><\/div><p>Proving the action has been correctly resolved from tag to package version, supporting also wildcard versioning (<code class=\"language-plaintext highlighter-rouge\">v1<\/code> and <code class=\"language-plaintext highlighter-rouge\">v1.0<\/code> tags both resolving to action package version <code class=\"language-plaintext highlighter-rouge\">1.0.1<\/code>).<\/p><p>That\u2019s nice. Now let\u2019s test some corner cases. What if I create <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/releases\/tag\/v1.0.2\">a tag <code class=\"language-plaintext highlighter-rouge\">v1.0.2<\/code><\/a> without publishing a corresponding immutable action and try to use it <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/blob\/231b99f91e2507a977f663da70404836f7064be3\/.github\/workflows\/test-immutable-action-tag-without-release.yml\">in a workflow<\/a>? As expected, that simply <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12176024772\/job\/33960889984\">does not work<\/a> because there is no immutable action matching the version <code class=\"language-plaintext highlighter-rouge\">1.0.2<\/code>:<\/p><p><img src=\"\/assets\/images\/2024-12-10-securing-workflow-immutable-actions\/resolution-error.png\" alt=\"Action resolution error\" title=\"Action resolution error\" \/><\/p><p>Now let\u2019s tackle immutability. I\u2019ve initially created a new tag <code class=\"language-plaintext highlighter-rouge\">v1.0.3<\/code> from <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/commit\/231b99f91e2507a977f663da70404836f7064be3\">commit 231b99f<\/a>  and <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12176234738\">published<\/a> the corresponding <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/pkgs\/container\/immutable-action-demo\/317366598?tag=1.0.3\">immutable action <code class=\"language-plaintext highlighter-rouge\">1.0.3<\/code><\/a>. I then updated the code of the action (<a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/commit\/be580c03ebd9ba926f6bdfe516b6635ea9f240c3\">commit be580c03<\/a>) and made the remote tag <code class=\"language-plaintext highlighter-rouge\">v1.0.3<\/code> to point to this new commit. I removed the original <code class=\"language-plaintext highlighter-rouge\">v1.0.3<\/code> release, created it again, and guess what? Trying to create a new immutable action with that same tag <a href=\"https:\/\/github.com\/ghsioux\/immutable-action-demo\/actions\/runs\/12176310609\/job\/33961788301\">failed<\/a> with the error:<\/p><p><img src=\"\/assets\/images\/2024-12-10-securing-workflow-immutable-actions\/publish-error.png\" alt=\"Action publish error\" title=\"Action publish error\" \/><\/p><h2 id=\"5---conclusion\">5 - Conclusion<\/h2><p>In this journey, we\u2019ve explored how Immutable Actions and artifact attestations fortify GitHub Actions workflows. By cryptographically signing actions and verifying their provenance, we can enhance the security of CI\/CD pipelines, bolstering the overall supply chain\u2019s integrity.<\/p><p>But this is just the beginning. Immutable Actions lay the groundwork for a more robust future in DevSecOps. By adopting these practices, you not only protect your workflows but also contribute to a more secure ecosystem for everyone.<\/p><p>In the dojo, we learn the value of collaboration. A big shoutout to the amazing team that helped unravel the inner workings of Immutable Actions: <a href=\"https:\/\/github.com\/tinaheidinger\">@tinaheidinger<\/a>, <a href=\"https:\/\/github.com\/thyeggman\">@thyeggman<\/a>, <a href=\"https:\/\/github.com\/konradpabjan\">@konradpabjan<\/a>, <a href=\"https:\/\/github.com\/conorsloan\">@conorsloan<\/a>, <a href=\"https:\/\/github.com\/jcambass\">@jcambass<\/a> and <a href=\"https:\/\/github.com\/steve-glass\">@steve-glass<\/a>.<\/p><p>Stay vigilant, and keep your workflows secure, shinobi! \ud83e\udd77<\/p><p>Gassh\u014d \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2024\/12\/10\/securing-workflow-immutable-actions","tags":["actions","immutable-actions","artifact-attestations","security","supply-chain-security"],"date_published":"2024-12-10T00:00:00+01:00","date_modified":"2024-12-10T00:00:00+01:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2024\/01\/23\/emu-mappings-manipulation","title":"Customizing GitHub EMU Provisioning Mappings in Azure","summary":"A quick dive into customizing user provisioning mappings in GitHub Enterprise Managed Users (EMU), with a focus on username length limitations.","content_text":"As an EMU (Enterprise Managed Users) administrator, you may have encountered challenges when provisioning users, especially when dealing with username length limitations. GitHub imposes a strict 39-character limit on usernames for EMU, which can clash with long naming conventions in your IdP (Identity Provider).In this post, I\u2019ll show you how to customize provisioning mappings in Azure Entra ID to handle such scenarios, focusing on the username limit and how we can use expression mappings to create compliant usernames.1 - EMU and User ProvisioningGitHub Enterprise Managed Users (EMU) is a feature that allows organizations to manage user accounts and access within GitHub, all through an Identity Provider (IdP). This allows your organization to provision, update, and decommission GitHub users automatically based on changes in your IdP, like Azure AD, Okta, or PingFederate.User provisioning involves syncing user data (like usernames, email addresses, and roles) from your IdP to GitHub. This is automated to ensure that when users join, change roles, or leave your organization, their GitHub accounts are created, updated, or deleted accordingly. Under the hood, this is standardized through the SCIM (System for Cross-domain Identity Management) specification.A core aspect of this process is provisioning mappings, which define how attributes from your IdP map to GitHub\u2019s required SCIM properties. For example, Azure\u2019s userPrincipalName (UPN) field may need to map to GitHub\u2019s userName SCIM attribute. When default mappings fall short\u2014like exceeding the username character limit\u2014custom mappings come to the rescue.2 - Handling Username Length LimitationWhen using Azure Entra ID as the identity provider for EMU, the default mapping for the GitHub usernames will be the following:Here\u2019s the crux of the issue: GitHub usernames must include your EMU shortcode suffix, leaving less room for the main portion of the username. For instance, a user\u2019s userPrincipalName like firstname-lastname-external might exceed the 39-character cap when the shortcode is added.As a reminder, the shortcode is chosen when you create an enterprise with managed users on GitHub.com to represent your enterprise. For example, if the shortcode is octo, a provisioned user might have a GitHub username like mona-cat_octo where mona-cat is derived from the identity provider during provisioning.Azure Entra ID provides a straightforward solution using the Left() function, which trims strings to a specific length:Left(text, number_of_characters)With:  text: The string you want to shorten (in this case, userPrincipalName).  number_of_characters: The number of characters to extract.For example, if your shortcode plus the _ is 5 characters (e.g. _octo), you can allow up to 34 characters for the UPN:Left([userPrincipalName], 34)This ensures the entire username, including the shortcode, stays within GitHub\u2019s limit. You can configure this as an expression mapping in Azure Entra ID to automate the transformation.3 - Broadening the ScopeWhile truncating usernames is a common use-case, there are other scenarios where provisioning mappings may need customization. For example, you might want to:      Use a custom field for the usernames: Companies might have specific fields in their IdP - such as employeeID - that better suit their GitHub\u2019s username strategy. By mapping these fields, you can ensure usernames are compliant without manual intervention.        Normalize email addresses: Normalize the emails attribute to ensure a consistent domain suffix for all users. For instance, if your organization uses multiple domains, you might standardize email addresses so that all users appear with the same domain in GitHub (e.g., john.doe@sub.example.com becomes john.doe@example.com).        Customize display names: Use the name.givenName and name.familyName attributes to create a more standardized or localized display name format for users in GitHub. For example, if your organization prefers full names in a \u201cLastName, FirstName\u201d format, you could map and combine these attributes accordingly.  4 - Wrapping Up and Next StepsWe\u2019ve seen how to tackle GitHub\u2019s username length limitations by customizing provisioning mappings in Azure Entra ID. By leveraging expression mappings like Left, you can ensure usernames stay compliant while maintaining automation and consistency. This approach can also be extended to normalize other attributes like email addresses or display names, adapting the provisioning process to fit your organizational needs.What if you\u2019re not using Entra ID? No worries\u2014GitHub supports various identity providers, including Okta and PingFederate, which offer similar customization options for SCIM attribute mappings. Additionally, for other IdPs, you can leverage GitHub\u2019s Open SCIM Configuration and its SCIM API to build fully tailored integrations. These tools provide the flexibility to manage provisioning while adhering to GitHub\u2019s constraints, no matter your setup.That\u2019s it for today, ninjas \u2014 time to resume practice in the Cloud Dojo.Gassh\u014d \ud83d\ude4f","content_html":"<p>As an EMU (<a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/understanding-iam-for-enterprises\/about-enterprise-managed-users\">Enterprise Managed Users<\/a>) administrator, you may have encountered challenges when provisioning users, especially when dealing with <strong>username length limitations<\/strong>. GitHub imposes a strict <strong>39-character limit<\/strong> on usernames for EMU, which can clash with long naming conventions in your IdP (Identity Provider).<\/p><p>In this post, I\u2019ll show you how to customize provisioning mappings in Azure Entra ID to handle such scenarios, focusing on the username limit and how we can use <strong>expression mappings<\/strong> to create compliant usernames.<\/p><h2 id=\"1---emu-and-user-provisioning\">1 - EMU and User Provisioning<\/h2><p>GitHub Enterprise Managed Users (EMU) is a feature that allows organizations to manage user accounts and access within GitHub, all through an Identity Provider (IdP). This allows your organization to provision, update, and decommission GitHub users automatically based on changes in your IdP, like Azure AD, Okta, or PingFederate.<\/p><p>User provisioning involves syncing user data (like usernames, email addresses, and roles) from your IdP to GitHub. This is automated to ensure that when users join, change roles, or leave your organization, their GitHub accounts are created, updated, or deleted accordingly. Under the hood, this is standardized through the <a href=\"https:\/\/scim.cloud\/\">SCIM (System for Cross-domain Identity Management)<\/a> specification.<\/p><p>A core aspect of this process is provisioning mappings, which define how attributes from your IdP map to <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/rest\/enterprise-admin\/scim?apiVersion=2022-11-28#supported-scim-user-attributes\">GitHub\u2019s required SCIM properties<\/a>. For example, Azure\u2019s <code class=\"language-plaintext highlighter-rouge\">userPrincipalName<\/code> (UPN) field may need to map to GitHub\u2019s <code class=\"language-plaintext highlighter-rouge\">userName<\/code> SCIM attribute. When default mappings fall short\u2014like exceeding the username character limit\u2014custom mappings come to the rescue.<\/p><h2 id=\"2---handling-username-length-limitation\">2 - Handling Username Length Limitation<\/h2><p>When using Azure Entra ID as the identity provider for EMU, the default mapping for the GitHub usernames will be the following:<\/p><p><img src=\"\/assets\/images\/2024-01-23-emu-mappings-manipulation\/defaultmapping.png\" alt=\"default userName mapping\" title=\"default userName mapping\" \/><\/p><p>Here\u2019s the crux of the issue: GitHub usernames must include your <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/iam-configuration-reference\/username-considerations-for-external-authentication#shortcodes-on-githubcom\">EMU shortcode<\/a> suffix, leaving less room for the main portion of the username. For instance, a user\u2019s <code class=\"language-plaintext highlighter-rouge\">userPrincipalName<\/code> like <code class=\"language-plaintext highlighter-rouge\">firstname-lastname-external<\/code> might exceed the 39-character cap when the shortcode is added.<\/p><p>As a reminder, the shortcode is chosen when you create an enterprise with managed users on GitHub.com to represent your enterprise. For example, if the shortcode is <code class=\"language-plaintext highlighter-rouge\">octo<\/code>, a provisioned user might have a GitHub username like <code class=\"language-plaintext highlighter-rouge\">mona-cat_octo<\/code> where <code class=\"language-plaintext highlighter-rouge\">mona-cat<\/code> is derived from the identity provider during provisioning.<\/p><p>Azure Entra ID provides a straightforward solution using the <a href=\"https:\/\/learn.microsoft.com\/en-us\/entra\/identity\/app-provisioning\/functions-for-customizing-application-data#left\"><code class=\"language-plaintext highlighter-rouge\">Left()<\/code> function<\/a>, which trims strings to a specific length:<\/p><div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">Left<\/span><span class=\"o\">(<\/span><span class=\"n\">text<\/span><span class=\"o\">,<\/span> <span class=\"n\">number_of_characters<\/span><span class=\"o\">)<\/span><\/code><\/pre><\/div><\/div><p>With:<\/p><ul>  <li><code class=\"language-plaintext highlighter-rouge\">text<\/code>: The string you want to shorten (in this case, <code class=\"language-plaintext highlighter-rouge\">userPrincipalName<\/code>).<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">number_of_characters<\/code>: The number of characters to extract.<\/li><\/ul><p>For example, if your shortcode plus the <code class=\"language-plaintext highlighter-rouge\">_<\/code> is 5 characters (e.g. <code class=\"language-plaintext highlighter-rouge\">_octo<\/code>), you can allow up to 34 characters for the UPN:<\/p><div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">Left<\/span><span class=\"o\">([<\/span><span class=\"n\">userPrincipalName<\/span><span class=\"o\">],<\/span> <span class=\"mi\">34<\/span><span class=\"o\">)<\/span><\/code><\/pre><\/div><\/div><p>This ensures the entire username, including the shortcode, stays within GitHub\u2019s limit. You can configure this as an expression mapping in Azure Entra ID to automate the transformation.<\/p><p><img src=\"\/assets\/images\/2024-01-23-emu-mappings-manipulation\/leftmapping.png\" alt=\"custom userName mapping with Left() expression\" title=\"custom userName mapping with Left() expression\" \/><\/p><h2 id=\"3---broadening-the-scope\">3 - Broadening the Scope<\/h2><p>While truncating usernames is a common use-case, there are other scenarios where provisioning mappings may need customization. For example, you might want to:<\/p><ul>  <li>    <p><strong>Use a custom field for the usernames<\/strong>: Companies might have specific fields in their IdP - such as <code class=\"language-plaintext highlighter-rouge\">employeeID<\/code> - that better suit their GitHub\u2019s username strategy. By mapping these fields, you can ensure usernames are compliant without manual intervention.<\/p>  <\/li>  <li>    <p><strong>Normalize email addresses<\/strong>: Normalize the emails attribute to ensure a consistent domain suffix for all users. For instance, if your organization uses multiple domains, you might standardize email addresses so that all users appear with the same domain in GitHub (e.g., <code class=\"language-plaintext highlighter-rouge\">john.doe@sub.example.com<\/code> becomes <code class=\"language-plaintext highlighter-rouge\">john.doe@example.com<\/code>).<\/p>  <\/li>  <li>    <p><strong>Customize display names<\/strong>: Use the <code class=\"language-plaintext highlighter-rouge\">name.givenName<\/code> and <code class=\"language-plaintext highlighter-rouge\">name.familyName<\/code> attributes to create a more standardized or localized display name format for users in GitHub. For example, if your organization prefers full names in a \u201cLastName, FirstName\u201d format, you could map and combine these attributes accordingly.<\/p>  <\/li><\/ul><h2 id=\"4---wrapping-up-and-next-steps\">4 - Wrapping Up and Next Steps<\/h2><p>We\u2019ve seen how to tackle GitHub\u2019s username length limitations by customizing provisioning mappings in Azure Entra ID. By leveraging expression mappings like <code class=\"language-plaintext highlighter-rouge\">Left<\/code>, you can ensure usernames stay compliant while maintaining automation and consistency. This approach can also be extended to normalize other attributes like email addresses or display names, adapting the provisioning process to fit your organizational needs.<\/p><p>What if you\u2019re not using Entra ID? No worries\u2014GitHub supports various identity providers, including <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/provisioning-user-accounts-with-scim\/configuring-scim-provisioning-with-okta\">Okta<\/a><\/strong> and <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/provisioning-user-accounts-with-scim\/configuring-authentication-and-provisioning-with-pingfederate\">PingFederate<\/a><\/strong>, which offer similar customization options for SCIM attribute mappings. Additionally, for other IdPs, you can leverage GitHub\u2019s <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/admin\/managing-iam\/provisioning-user-accounts-with-scim\/configuring-scim-provisioning-for-users#configuring-provisioning-for-other-identity-management-systems\">Open SCIM Configuration<\/a><\/strong> and its <strong><a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/rest\/enterprise-admin\/scim?apiVersion=2022-11-28\">SCIM API<\/a><\/strong> to build fully tailored integrations. These tools provide the flexibility to manage provisioning while adhering to GitHub\u2019s constraints, no matter your setup.<\/p><p>That\u2019s it for today, ninjas \u2014 time to resume practice in the Cloud Dojo.<\/p><p>Gassh\u014d \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2024\/01\/23\/emu-mappings-manipulation","tags":["enterprise-managed-user","emu","scim","provisioning","azure","entra-id"],"date_published":"2024-01-23T00:00:00+01:00","date_modified":"2024-01-23T00:00:00+01:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2023\/04\/05\/multi-clouds-deployment","title":"Using GitHub Actions for multi-clouds deployment with OIDC and rollback support","summary":"A story about (not-only) versioned & passwordless multi-clouds deployment","content_text":"That\u2019s it ninjas, spring has arrived, birds are singing and beautiful clouds adorn the sky. It make me remember about these old stories, where some mountain monks could touch multiple of them at once.Today, we\u2019re going to do the same thing, but with different clouds. Let\u2019s use our GitHub Actions katas to deploy an application to Azure, AWS and GCP ! \u2601\ufe0f\u2601\ufe0f\u2601\ufe0f1 - General ViewWe\u2019ll deploy the Spring Petclinic sample application as a container application in the cloud, and this is the fork repository where we\u2019ll work on. The \u201c\ud83d\ude80 Multi-cloud deployment\u201d is the main workflow from where the deployment starts. The overall process is as follows:  Build the application using Maven to generate a JAR file (link to code);  Build and push a container image ready to run this JAR file (link to code);  Run the container image on each cloud provider (link to code).This dojo session will mainly focus on the last step and some of its specificities. If you\u2019ve followed its link, you\u2019ll have noticed that three reusable workflows - one per cloud provider - are called to this end. This is because I will likely use them in future projects, as deploying container applications to the cloud is a common task. Also, this is a nice way to keep the main workflow as simple as possible.Overall, the deployment will have the following properties:            Properties      How                  Automated      The deployment will be performed with GitHub Actions.              Versioned      The workflow will be triggered when a new release is published, or manually on specific tags. But not with every tags \ud83e\udd77\ud83d\udc47              Protected      The protection is threefold: Who can deploy? Only repository admins;  What can be deployed? Only tags matching the regular expression v* (and associated releases since releases are based on tags);  Where to deploy? Only on three specific, protected GitHub environments (named aws, azure and gcp for the cloud providers they\u2019ll respectively target).              Passwordless      Authentication to the cloud providers is done using the OpenID Connect standard, hence no need to manage any password.              Geo-distributed      The application will be deployed on three different geographical locations: ap-southeast-1 for AWS, east us for Azure and europe-west1 for GCP.      2 - Shaping the cloudsEach of the cloud providers has its own way(s) to deploy container applications, and provides the associated GitHub Actions to do it. Here is a quick recap of the ones I\u2019ve used:            Cloud provider      Container Service      GitHub Actions                  Amazon Web Services      Elastic Container Service      aws-actions\/amazon-ecs-render-task-definition aws-actions\/amazon-ecs-deploy-task-definition               Microsoft Azure      Azure Container Instances      Azure\/aci-deploy              Google Cloud Platform      Cloud Run      google-github-actions\/deploy-cloudrun      Before using these actions in our workflows, we have to set up the cloud infrastructures first. With the aim of keeping this scroll as short as possible, I\u2019ve detailed this process in the doc\/infra-setup folder and all the CLI commands are provided. You can also have a look at the quickstart to get an overall picture.  \ud83d\udca1 Bonus! If you want to try it, but don\u2019t want to install the CLI tools on your own machine, there is a codespaces setup ready to be used for that \u2728Once it\u2019s done, we\u2019ll use these actions in our reusable workflows to deploy the container application:  For Amazon (link to step):        - name: Prepare the Amazon ECS task definition to use our container image       id: task-def      uses: aws-actions\/amazon-ecs-render-task-definition@v1      with:        task-definition: ${{ inputs.ecs-task-definition }}        container-name: ${{ inputs.container-name }}        image: ${{ inputs.container-image }}    - name: Deploy the Amazon ECS task definition (i.e. deploy the container app)      id: deploy_task      uses: aws-actions\/amazon-ecs-deploy-task-definition@v1      with:        task-definition: ${{ steps.task-def.outputs.task-definition }}        service: ${{ inputs.ecs-service }}        cluster: ${{ inputs.ecs-cluster }}        wait-for-service-stability: true        For Azure (link to step):        - name: 'Deploy to Azure Container Instances'      uses: 'azure\/aci-deploy@v1'      with:        resource-group: ${{ inputs.resource-group }}        dns-name-label: ${{ inputs.deployment-url-prefix }}        image: ${{ inputs.container-image }}        name: ${{ inputs.deployment-name }}        location: ${{ inputs.location }}        ports: ${{ inputs.ports }}        For GCP (link to step):        - id: 'deploy'      name: 'Deploy the image to Google Cloud Run'      uses: 'google-github-actions\/deploy-cloudrun@v1'      with:        service: ${{ inputs.cloudrun-service }}        image: ${{ inputs.push-to-gar == true &amp;&amp; inputs.gar-target-image || inputs.container-image }}        region: ${{ inputs.region }}        flags: ${{ inputs.flags }}      You can observe that these workflows are called with different regions [1] [2] [3] for each cloud provider, hence making the deployment geo-distributed. This is a good practice to ensure high availability and to reduce the risk of downtime. And this is by the way just one of the benefits of the multi-cloud approach.3 - OIDC in ActionsSo the clouds are ready and we know exactly how we\u2019ll deploy our application. That\u2019s neat, but we still have to authenticate beforehand in order to proceed. When it comes to authenticate to cloud providers in GitHub Actions, two good practices pop up:  Avoid using passwords as they are hard to rotate and can be leaked;  Use service accounts instead of personal accounts, as they provide better security and control over permissions and access to cloud resources.And guess what? This is exactly what we gonna do here: we\u2019ll use a service account for each cloud provider, and we\u2019ll configure them to authenticate using the OpenID Connect standard.Similarly to what we did for the cloud infrastructures, I\u2019ve detailed this process in the doc\/oidc-setup folder and the following table summarizes what has been used to this end:            Cloud provider      Service account construct      OIDC implementation      GitHub Action                  Amazon Web Services      IAM role      OIDC identity provider      aws-actions\/configure-aws-credentials              Microsoft Azure      Service principal      Workload identity federation      Azure\/login              Google Cloud Platform      Service account      Workload identity federation      google-github-actions\/auth      Once everything is set up, we can authenticate to the cloud providers using OIDC in our reusable workflows:  For AWS (link to step):        - name: Configure AWS credentials using OIDC      uses: aws-actions\/configure-aws-credentials@v2      with:        role-to-assume: ${{ secrets.oidc-role-to-assume }}        role-session-name: workflowrolesession        aws-region: ${{ inputs.aws-region }}        For Azure (link to step):        - name: 'Login to Azure using OIDC'      uses: azure\/login@v1      with:        client-id: ${{ secrets.az_client_id }}        tenant-id: ${{ secrets.az_tenant_id }}        subscription-id: ${{ secrets.az_subscription_id }}        For GCP (link to step):        - id: 'auth'      name: 'Authenticate to Google Cloud using OIDC'      uses: 'google-github-actions\/auth@v1'      with:        workload_identity_provider: ${{ secrets.workload_identity_provider }}        service_account: ${{ secrets.service_account }}        token_format: 'access_token'      You might have noticed that we are still using Actions secrets to pass the OIDC information to the cloud providers. This is just to add an extra layer of security: for instance, if that information was leaked and the OIDC trust relationship was too permissive, an attacker would perhaps be able to access the cloud resources from its own repository.Here this should not be the case - but we never know! - since during the setup I\u2019ve restricted the trust relationship to the following OIDC identities:  for AWS, only the identity repo:ghsioux\/multi-cloud-deployment-demo:environment:aws (that is, the GitHub environment aws of the repository ghsioux\/multi-cloud-deployment-demo) is trusted;  similarly, for Azure, only the identity repo:ghsioux\/multi-cloud-deployment-demo:environment:azure is trusted;  and for GCP, only the identity repo:ghsioux\/multi-cloud-deployment-demo:environment:gcp is trusted.During the authentication process, the identity checks are performed by the cloud providers based on the token passed by the GitHub OIDC provider.Allright! We have implemented some mecanisms to make the deployment geo-distributed and passwordless, now let\u2019s make it protected and versioned.4 - Controlling the version to deployThe ones with eyes like the hawk will have observed that there is actually an additional step in the main worflow, that I\u2019ve not listed in the general view above.To get a bit more context, let\u2019s have a look at the very beginning of the workflow:name: \"\ud83d\ude80 Multi-cloud PetClinic deployment demo\"on:  workflow_dispatch:  release:    types: [published]The workflow will be triggered manually or when a release is published. I\u2019m working alone on this project, but let\u2019s imagine a more complex scenario where multiple people collaborate. As a repository administrator, I would possibly want to restrict i) who can trigger\/re-run the workflow (e.g. only admin), and ii) which tags (and thus associated releases) are allowed to be deployed (e.g. only production tag).That\u2019s why I\u2019ve added a few checks in the first job of the workflow to ensure that:  prereq_checks:    name: Ensure this workflow has been triggered by and admin on a protected release tag (v*)    runs-on: ubuntu-latest    env:      TRIGGERING_ACTOR: ${{ github.triggering_actor }}    steps:      - name: Fail if the workflow has been triggered manually with a non-release tag (i.e. not using the 'v*' regex)        run: |          if [[ \"$GITHUB_REF\" != refs\/tags\/v* ]]; then            echo \"Only 'v*' tags and associated releases can be deployed, exiting.\"            exit 1          else            echo \"The workflow has been triggered on a release tag, continuing.\"          fi      - name: Fail if the workflow has been triggered by a non-admin user        uses: actions\/github-script@v6        with:          script: |            const TRIGGERING_ACTOR = process.env.TRIGGERING_ACTOR            github.rest.repos.getCollaboratorPermissionLevel({              owner: context.repo.owner,              repo: context.repo.repo,              username: TRIGGERING_ACTOR              }).then(response =&gt; {                if (response.data.permission == 'admin') {                  core.info('The github actor has admin permission on this repository. Continuing.')                } else {                  core.info('Only repository admins can trigger this workflow. Exiting.')                  process.exit(1)                }              })As you can see, only member with the admin permission can trigger the workflow, and only tags matching the regexp v* are allowed to be deployed. In parallel, I\u2019ve set up a tag protection rules to restrict v* tags creation to privileged members only. This tag protection rule will also apply when creating a release (i.e. a non-privileged member won\u2019t be authorized to create a release with a tag matching v*).If you combine this with the use of the 3 dedicated GitHub environments, which are themselves bound to the branches matching v*  (i.e. our protected tags) and protected to require a manual approval before deployment, the overall level of security is fairly satisfying.5 - The pieces together a.k.a. time to triggerCongrats, you made it so far, and now comes the time to enjoy and trigger \ud83d\udd2bLet\u2019s say that the developers have been working hard on the application to add new features, and they are ready to deploy the new version to production.A member with the admin permission on the repository will create a new release with a tag matching the v* regexp:This will trigger the main workflow, and after the checks have passed, the image is built and pushed to the GitHub container registry. Then the three reusable workflows are called, and since they are working on protected environments, a manual approval is required (e.g. by the SRE team):Once the approval is granted, the workflows will continue and the new version of the application will be deployed to our three cloud providers:Is that all? Could be, but you know, sometimes accidents happen. Let\u2019s imagine that\u2019s the case, and that the new version of the application is not working as expected. Mayday, mayday, we need to rollback! Nothing more simple, the administrator will just trigger the workflow again, but this time manually, and on the tag matching the previous release:Phew, we\u2019re going back to business! \ud83c\udf896 - Next stepsThat was a lot of fun, and I hope you enjoyed it as much as I did. As usual, this is not for production use, and there is room for improvement. I\u2019m sure you have some ideas on how to make this even better!We could for instance:  define stricter role permissions and RBAC for our service accounts;  implement some load-balancing mechanisms (e.g. DNS round-robin, Traefik) to make the application available on a single URL;  extend the workflow to implement blue\/green deployments, A\/B testing or canary release approach.But the sun is shining, and the flowers are blooming, so let\u2019s leave it here for now.Gassh\u014d \ud83d\ude4f","content_html":"<p>That\u2019s it ninjas, spring has arrived, birds are singing and beautiful clouds adorn the sky. It make me remember about these old stories, where some mountain monks could touch multiple of them at once.<\/p><p>Today, we\u2019re going to do the same thing, but with different clouds. Let\u2019s use our GitHub Actions katas to deploy an application to Azure, AWS and GCP ! \u2601\ufe0f\u2601\ufe0f\u2601\ufe0f<\/p><h2 id=\"1---general-view\">1 - General View<\/h2><p>We\u2019ll deploy the <a href=\"https:\/\/github.com\/spring-projects\/spring-petclinic\">Spring Petclinic sample application<\/a> as a container application in the cloud, and this is the <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\">fork repository<\/a> where we\u2019ll work on. The <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml\">\u201c\ud83d\ude80 Multi-cloud deployment\u201d<\/a> is the main workflow from where the deployment starts. The overall process is as follows:<\/p><ol>  <li>Build the application using Maven to generate a JAR file <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L45-L72\">(link to code)<\/a>;<\/li>  <li>Build and push a container image ready to run this JAR file <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L74-L111\">(link to code)<\/a>;<\/li>  <li>Run the container image on each cloud provider <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L113-L177\">(link to code)<\/a>.<\/li><\/ol><p>This dojo session will mainly focus on the last step and some of its specificities. If you\u2019ve followed its link, you\u2019ll have noticed that three <a href=\"https:\/\/docs.github.com\/en\/actions\/using-workflows\/reusing-workflows\">reusable workflows<\/a> - one per cloud provider - are called to this end. This is because I will likely use them in future projects, as deploying container applications to the cloud is a common task. Also, this is a nice way to keep the main workflow as simple as possible.<\/p><p>Overall, the deployment will have the following properties:<\/p><table>  <thead>    <tr>      <th>Properties<\/th>      <th>How<\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td><strong>Automated<\/strong><\/td>      <td>The deployment will be performed with GitHub Actions.<\/td>    <\/tr>    <tr>      <td><strong>Versioned<\/strong><\/td>      <td>The workflow will be triggered when <a href=\"https:\/\/docs.github.com\/en\/repositories\/releasing-projects-on-github\/managing-releases-in-a-repository#creating-a-release\">a new release is published<\/a>, or manually on <a href=\"https:\/\/docs.github.com\/en\/rest\/git\/tags?apiVersion=2022-11-28#about-git-tags\">specific tags<\/a>. But not with every tags \ud83e\udd77\ud83d\udc47<\/td>    <\/tr>    <tr>      <td><strong>Protected<\/strong><\/td>      <td>The protection is threefold: <br \/><ul class=\"table-list\"><li><strong>Who can deploy?<\/strong> Only repository admins; <\/li><li> <strong>What can be deployed?<\/strong> Only tags matching the regular expression <code class=\"language-plaintext highlighter-rouge\">v*<\/code> (and associated releases since releases are based on tags); <\/li><li> <strong>Where to deploy?<\/strong> Only on three specific, protected GitHub environments (named <code class=\"language-plaintext highlighter-rouge\">aws<\/code>, <code class=\"language-plaintext highlighter-rouge\">azure<\/code> and <code class=\"language-plaintext highlighter-rouge\">gcp<\/code> for the cloud providers they\u2019ll respectively target).<\/li><\/ul><\/td>    <\/tr>    <tr>      <td><strong>Passwordless<\/strong><\/td>      <td>Authentication to the cloud providers is done using <a href=\"https:\/\/openid.net\/connect\/\">the OpenID Connect standard<\/a>, hence no need to manage any password.<\/td>    <\/tr>    <tr>      <td><strong>Geo-distributed<\/strong><\/td>      <td>The application will be deployed on three different geographical locations: <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/using-regions-availability-zones.html#concepts-regions\"><code class=\"language-plaintext highlighter-rouge\">ap-southeast-1<\/code> for AWS<\/a>, <a href=\"https:\/\/azure.microsoft.com\/en-us\/explore\/global-infrastructure\/geographies\/#geographies\"><code class=\"language-plaintext highlighter-rouge\">east us<\/code> for Azure<\/a> and <a href=\"https:\/\/cloud.google.com\/compute\/docs\/regions-zones#available\"><code class=\"language-plaintext highlighter-rouge\">europe-west1<\/code> for GCP<\/a>.<\/td>    <\/tr>  <\/tbody><\/table><h2 id=\"2---shaping-the-clouds\">2 - Shaping the clouds<\/h2><p>Each of the cloud providers has its own way(s) to deploy container applications, and provides the associated GitHub Actions to do it. Here is a quick recap of the ones I\u2019ve used:<\/p><table>  <thead>    <tr>      <th>Cloud provider<\/th>      <th>Container Service<\/th>      <th>GitHub Actions<\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td>Amazon Web Services<\/td>      <td><a href=\"https:\/\/aws.amazon.com\/ecs\/\">Elastic Container Service<\/a><\/td>      <td><ul class=\"table-list\"><li><a href=\"https:\/\/github.com\/marketplace\/actions\/amazon-ecs-render-task-definition-action-for-github-actions\">aws-actions\/amazon-ecs-render-task-definition<\/a> <\/li><li><a href=\"https:\/\/github.com\/marketplace\/actions\/amazon-ecs-deploy-task-definition-action-for-github-actions\">aws-actions\/amazon-ecs-deploy-task-definition<\/a> <\/li><\/ul><\/td>    <\/tr>    <tr>      <td>Microsoft Azure<\/td>      <td><a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/container-instances\/\">Azure Container Instances<\/a><\/td>      <td><a href=\"https:\/\/github.com\/marketplace\/actions\/deploy-to-azure-container-instances\">Azure\/aci-deploy<\/a><\/td>    <\/tr>    <tr>      <td>Google Cloud Platform<\/td>      <td><a href=\"https:\/\/cloud.google.com\/run\">Cloud Run<\/a><\/td>      <td><a href=\"https:\/\/github.com\/marketplace\/actions\/deploy-to-cloud-run\">google-github-actions\/deploy-cloudrun<\/a><\/td>    <\/tr>  <\/tbody><\/table><p>Before using these actions in our workflows, we have to set up the cloud infrastructures first. With the aim of keeping this scroll as short as possible, I\u2019ve detailed this process in the <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/tree\/main\/docs\/infra-setup\"><code class=\"language-plaintext highlighter-rouge\">doc\/infra-setup<\/code> folder<\/a> and all the CLI commands are provided. You can also have a look at <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/README.md\">the quickstart<\/a> to get an overall picture.<\/p><blockquote>  <p>\ud83d\udca1 <strong>Bonus!<\/strong> If you want to try it, but don\u2019t want to install the CLI tools on your own machine, there is <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.devcontainer\/devcontainer.json\">a codespaces setup<\/a> ready to be used for that \u2728<\/p><\/blockquote><p>Once it\u2019s done, we\u2019ll use these actions in our reusable workflows to deploy the container application:<\/p><ul>  <li>For Amazon (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-aws-ecs.yml#L68-L83\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Prepare the Amazon ECS task definition to use our container image<\/span>       <span class=\"na\">id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">task-def<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">aws-actions\/amazon-ecs-render-task-definition@v1<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">task-definition<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.ecs-task-definition }}<\/span>        <span class=\"na\">container-name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.container-name }}<\/span>        <span class=\"na\">image<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.container-image }}<\/span>    <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Deploy the Amazon ECS task definition (i.e. deploy the container app)<\/span>      <span class=\"na\">id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">deploy_task<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">aws-actions\/amazon-ecs-deploy-task-definition@v1<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">task-definition<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ steps.task-def.outputs.task-definition }}<\/span>        <span class=\"na\">service<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.ecs-service }}<\/span>        <span class=\"na\">cluster<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.ecs-cluster }}<\/span>        <span class=\"na\">wait-for-service-stability<\/span><span class=\"pi\">:<\/span> <span class=\"no\">true<\/span><\/code><\/pre><\/div>    <\/div>  <\/li>  <li>For Azure (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-azure-aci.yml#L63-L71\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">Deploy<\/span><span class=\"nv\"> <\/span><span class=\"s\">to<\/span><span class=\"nv\"> <\/span><span class=\"s\">Azure<\/span><span class=\"nv\"> <\/span><span class=\"s\">Container<\/span><span class=\"nv\"> <\/span><span class=\"s\">Instances'<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">azure\/aci-deploy@v1'<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">resource-group<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.resource-group }}<\/span>        <span class=\"na\">dns-name-label<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.deployment-url-prefix }}<\/span>        <span class=\"na\">image<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.container-image }}<\/span>        <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.deployment-name }}<\/span>        <span class=\"na\">location<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.location }}<\/span>        <span class=\"na\">ports<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.ports }}<\/span><\/code><\/pre><\/div>    <\/div>  <\/li>  <li>For GCP (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-gcp-cloudrun.yml#L85-L92\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">id<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">deploy'<\/span>      <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">Deploy<\/span><span class=\"nv\"> <\/span><span class=\"s\">the<\/span><span class=\"nv\"> <\/span><span class=\"s\">image<\/span><span class=\"nv\"> <\/span><span class=\"s\">to<\/span><span class=\"nv\"> <\/span><span class=\"s\">Google<\/span><span class=\"nv\"> <\/span><span class=\"s\">Cloud<\/span><span class=\"nv\"> <\/span><span class=\"s\">Run'<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">google-github-actions\/deploy-cloudrun@v1'<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">service<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.cloudrun-service }}<\/span>        <span class=\"na\">image<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.push-to-gar == <\/span><span class=\"no\">true<\/span><span class=\"s\"> &amp;&amp; inputs.gar-target-image || inputs.container-image }}<\/span>        <span class=\"na\">region<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.region }}<\/span>        <span class=\"na\">flags<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.flags }}<\/span><\/code><\/pre><\/div>    <\/div>  <\/li><\/ul><p>You can observe that these workflows are called with different regions <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L130\">[1]<\/a> <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L152\">[2]<\/a> <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L173\">[3]<\/a> for each cloud provider, hence making the deployment <strong>geo-distributed<\/strong>. This is a good practice to ensure high availability and to reduce the risk of downtime. And this is by the way just one of the benefits of the multi-cloud approach.<\/p><h2 id=\"3---oidc-in-actions\">3 - OIDC in Actions<\/h2><p>So the clouds are ready and we know exactly how we\u2019ll deploy our application. That\u2019s neat, but we still have to authenticate beforehand in order to proceed. When it comes to authenticate to cloud providers in GitHub Actions, two good practices pop up:<\/p><ul>  <li><strong>Avoid using passwords<\/strong> as they are hard to rotate and can be leaked;<\/li>  <li><strong>Use service accounts<\/strong> instead of personal accounts, as they provide better security and control over permissions and access to cloud resources.<\/li><\/ul><p>And guess what? This is exactly what we gonna do here: we\u2019ll use a service account for each cloud provider, and we\u2019ll configure them to authenticate using the OpenID Connect standard.<\/p><p>Similarly to what we did for the cloud infrastructures, I\u2019ve detailed this process in the <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/tree\/main\/docs\/oidc-setup\"><code class=\"language-plaintext highlighter-rouge\">doc\/oidc-setup<\/code> folder<\/a> and the following table summarizes what has been used to this end:<\/p><table>  <thead>    <tr>      <th>Cloud provider<\/th>      <th>Service account construct<\/th>      <th>OIDC implementation<\/th>      <th>GitHub Action<\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td>Amazon Web Services<\/td>      <td><a href=\"https:\/\/docs.aws.amazon.com\/IAM\/latest\/UserGuide\/id_roles.html\">IAM role<\/a><\/td>      <td><a href=\"https:\/\/docs.aws.amazon.com\/IAM\/latest\/UserGuide\/id_roles_providers_create_oidc.html\">OIDC identity provider<\/a><\/td>      <td><a href=\"https:\/\/github.com\/marketplace\/actions\/configure-aws-credentials-for-github-actions\">aws-actions\/configure-aws-credentials<\/a><\/td>    <\/tr>    <tr>      <td>Microsoft Azure<\/td>      <td><a href=\"https:\/\/learn.microsoft.com\/en-us\/powershell\/azure\/create-azure-service-principal-azureps?view=azps-9.5.0\">Service principal<\/a><\/td>      <td><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/active-directory\/workload-identities\/workload-identity-federation?source=recommendations\">Workload identity federation<\/a><\/td>      <td><a href=\"https:\/\/github.com\/marketplace\/actions\/azure-login\">Azure\/login<\/a><\/td>    <\/tr>    <tr>      <td>Google Cloud Platform<\/td>      <td><a href=\"https:\/\/cloud.google.com\/iam\/docs\/service-account-overview\">Service account<\/a><\/td>      <td><a href=\"https:\/\/cloud.google.com\/iam\/docs\/workload-identity-federation\">Workload identity federation<\/a><\/td>      <td><a href=\"https:\/\/github.com\/marketplace\/actions\/authenticate-to-google-cloud\">google-github-actions\/auth<\/a><\/td>    <\/tr>  <\/tbody><\/table><p>Once everything is set up, we can authenticate to the cloud providers using OIDC in our reusable workflows:<\/p><ul>  <li>For AWS (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-aws-ecs.yml#L61-L66\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Configure AWS credentials using OIDC<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">aws-actions\/configure-aws-credentials@v2<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">role-to-assume<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.oidc-role-to-assume }}<\/span>        <span class=\"na\">role-session-name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">workflowrolesession<\/span>        <span class=\"na\">aws-region<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ inputs.aws-region }}<\/span><\/code><\/pre><\/div>    <\/div>  <\/li>  <li>For Azure (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-azure-aci.yml#L56-L61\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">Login<\/span><span class=\"nv\"> <\/span><span class=\"s\">to<\/span><span class=\"nv\"> <\/span><span class=\"s\">Azure<\/span><span class=\"nv\"> <\/span><span class=\"s\">using<\/span><span class=\"nv\"> <\/span><span class=\"s\">OIDC'<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">azure\/login@v1<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">client-id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.az_client_id }}<\/span>        <span class=\"na\">tenant-id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.az_tenant_id }}<\/span>        <span class=\"na\">subscription-id<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.az_subscription_id }}<\/span><\/code><\/pre><\/div>    <\/div>  <\/li>  <li>For GCP (<a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/deploy-to-gcp-cloudrun.yml#L63-L69\">link to step<\/a>):    <div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>    <span class=\"pi\">-<\/span> <span class=\"na\">id<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">auth'<\/span>      <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">Authenticate<\/span><span class=\"nv\"> <\/span><span class=\"s\">to<\/span><span class=\"nv\"> <\/span><span class=\"s\">Google<\/span><span class=\"nv\"> <\/span><span class=\"s\">Cloud<\/span><span class=\"nv\"> <\/span><span class=\"s\">using<\/span><span class=\"nv\"> <\/span><span class=\"s\">OIDC'<\/span>      <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">google-github-actions\/auth@v1'<\/span>      <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>        <span class=\"na\">workload_identity_provider<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.workload_identity_provider }}<\/span>        <span class=\"na\">service_account<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ secrets.service_account }}<\/span>        <span class=\"na\">token_format<\/span><span class=\"pi\">:<\/span> <span class=\"s1\">'<\/span><span class=\"s\">access_token'<\/span><\/code><\/pre><\/div>    <\/div>  <\/li><\/ul><p>You might have noticed that we are still using Actions secrets to pass the OIDC information to the cloud providers. This is just to add an extra layer of security: for instance, if that information was leaked and the OIDC trust relationship was too permissive, an attacker would perhaps be able to access the cloud resources from its own repository.<\/p><p>Here this should not be the case - but we never know! - since during the setup I\u2019ve restricted the trust relationship to the following OIDC identities:<\/p><ul>  <li>for AWS, only the identity <code class=\"language-plaintext highlighter-rouge\">repo:ghsioux\/multi-cloud-deployment-demo:environment:aws<\/code> (that is, the GitHub environment <code class=\"language-plaintext highlighter-rouge\">aws<\/code> of the repository <code class=\"language-plaintext highlighter-rouge\">ghsioux\/multi-cloud-deployment-demo<\/code>) is trusted;<\/li>  <li>similarly, for Azure, only the identity <code class=\"language-plaintext highlighter-rouge\">repo:ghsioux\/multi-cloud-deployment-demo:environment:azure<\/code> is trusted;<\/li>  <li>and for GCP, only the identity <code class=\"language-plaintext highlighter-rouge\">repo:ghsioux\/multi-cloud-deployment-demo:environment:gcp<\/code> is trusted.<\/li><\/ul><p>During the authentication process, the identity checks are performed by the cloud providers based on <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/security-hardening-your-deployments\/about-security-hardening-with-openid-connect#understanding-the-oidc-token\">the token passed by the GitHub OIDC provider<\/a>.<\/p><p>Allright! We have implemented some mecanisms to make the deployment <strong>geo-distributed<\/strong> and <strong>passwordless<\/strong>, now let\u2019s make it <strong>protected<\/strong> and <strong>versioned<\/strong>.<\/p><h2 id=\"4---controlling-the-version-to-deploy\">4 - Controlling the version to deploy<\/h2><p>The ones with eyes like the hawk will have observed that there is actually <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L11-L43\">an additional step<\/a> in the main worflow, that I\u2019ve not listed in the <a href=\"#1---general-view\">general view<\/a> above.<\/p><p>To get a bit more context, let\u2019s have a look at the very beginning of <a href=\"https:\/\/github.com\/ghsioux\/multi-cloud-deployment-demo\/blob\/main\/.github\/workflows\/multi-cloud-deployment.yml#L2-L7\">the workflow<\/a>:<\/p><div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s2\">\"<\/span><span class=\"s\">\ud83d\ude80<\/span><span class=\"nv\"> <\/span><span class=\"s\">Multi-cloud<\/span><span class=\"nv\"> <\/span><span class=\"s\">PetClinic<\/span><span class=\"nv\"> <\/span><span class=\"s\">deployment<\/span><span class=\"nv\"> <\/span><span class=\"s\">demo\"<\/span><span class=\"na\">on<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">workflow_dispatch<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">release<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">types<\/span><span class=\"pi\">:<\/span> <span class=\"pi\">[<\/span><span class=\"nv\">published<\/span><span class=\"pi\">]<\/span><\/code><\/pre><\/div><\/div><p>The workflow will be triggered manually or when a release is published. I\u2019m working alone on this project, but let\u2019s imagine a more complex scenario where multiple people collaborate. As a repository administrator, I would possibly want to restrict <strong>i)<\/strong> who can trigger\/re-run the workflow (e.g. only admin), and <strong>ii<\/strong>) which tags (and thus associated releases) are allowed to be deployed (e.g. only production tag).<\/p><p>That\u2019s why I\u2019ve added a few checks in the first job of the workflow to ensure that:<\/p><div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>  <span class=\"na\">prereq_checks<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Ensure this workflow has been triggered by and admin on a protected release tag (v*)<\/span>    <span class=\"na\">runs-on<\/span><span class=\"pi\">:<\/span> <span class=\"s\">ubuntu-latest<\/span>    <span class=\"na\">env<\/span><span class=\"pi\">:<\/span>      <span class=\"na\">TRIGGERING_ACTOR<\/span><span class=\"pi\">:<\/span> <span class=\"s\">${{ github.triggering_actor }}<\/span>    <span class=\"na\">steps<\/span><span class=\"pi\">:<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Fail if the workflow has been triggered manually with a non-release tag (i.e. not using the 'v*' regex)<\/span>        <span class=\"na\">run<\/span><span class=\"pi\">:<\/span> <span class=\"pi\">|<\/span>          <span class=\"s\">if [[ \"$GITHUB_REF\" != refs\/tags\/v* ]]; then<\/span>            <span class=\"s\">echo \"Only 'v*' tags and associated releases can be deployed, exiting.\"<\/span>            <span class=\"s\">exit 1<\/span>          <span class=\"s\">else<\/span>            <span class=\"s\">echo \"The workflow has been triggered on a release tag, continuing.\"<\/span>          <span class=\"s\">fi<\/span>      <span class=\"pi\">-<\/span> <span class=\"na\">name<\/span><span class=\"pi\">:<\/span> <span class=\"s\">Fail if the workflow has been triggered by a non-admin user<\/span>        <span class=\"na\">uses<\/span><span class=\"pi\">:<\/span> <span class=\"s\">actions\/github-script@v6<\/span>        <span class=\"na\">with<\/span><span class=\"pi\">:<\/span>          <span class=\"na\">script<\/span><span class=\"pi\">:<\/span> <span class=\"pi\">|<\/span>            <span class=\"s\">const TRIGGERING_ACTOR = process.env.TRIGGERING_ACTOR<\/span>            <span class=\"s\">github.rest.repos.getCollaboratorPermissionLevel({<\/span>              <span class=\"s\">owner: context.repo.owner,<\/span>              <span class=\"s\">repo: context.repo.repo,<\/span>              <span class=\"s\">username: TRIGGERING_ACTOR<\/span>              <span class=\"s\">}).then(response =&gt; {<\/span>                <span class=\"s\">if (response.data.permission == 'admin') {<\/span>                  <span class=\"s\">core.info('The github actor has admin permission on this repository. Continuing.')<\/span>                <span class=\"s\">} else {<\/span>                  <span class=\"s\">core.info('Only repository admins can trigger this workflow. Exiting.')<\/span>                  <span class=\"s\">process.exit(1)<\/span>                <span class=\"s\">}<\/span>              <span class=\"s\">})<\/span><\/code><\/pre><\/div><\/div><p>As you can see, only member with the <code class=\"language-plaintext highlighter-rouge\">admin<\/code> permission can trigger the workflow, and only tags matching the regexp <code class=\"language-plaintext highlighter-rouge\">v*<\/code> are allowed to be deployed. In parallel, I\u2019ve set up a <a href=\"https:\/\/docs.github.com\/en\/enterprise-cloud@latest\/repositories\/managing-your-repositorys-settings-and-features\/managing-repository-settings\/configuring-tag-protection-rules\">tag protection rules<\/a> to restrict <code class=\"language-plaintext highlighter-rouge\">v*<\/code> tags creation to privileged members only. This tag protection rule will also apply when creating a release (i.e. a non-privileged member won\u2019t be authorized to create a release with a tag matching <code class=\"language-plaintext highlighter-rouge\">v*<\/code>).<\/p><p>If you combine this with the use of the 3 dedicated GitHub environments, which are themselves <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/targeting-different-environments\/using-environments-for-deployment#deployment-branches\">bound to the branches<\/a> matching <code class=\"language-plaintext highlighter-rouge\">v*<\/code>  (i.e. our protected tags) and protected to require <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/targeting-different-environments\/using-environments-for-deployment#required-reviewers\">a manual approval<\/a> before deployment, the overall level of security is fairly satisfying.<\/p><h2 id=\"5---the-pieces-together-aka-time-to-trigger\">5 - The pieces together a.k.a. time to trigger<\/h2><p>Congrats, you made it so far, and now comes the time to enjoy and trigger \ud83d\udd2b<\/p><p>Let\u2019s say that the developers have been working hard on the application to add new features, and they are ready to deploy the new version to production.<\/p><p>A member with the <code class=\"language-plaintext highlighter-rouge\">admin<\/code> permission on the repository will create a new release with a tag matching the <code class=\"language-plaintext highlighter-rouge\">v*<\/code> regexp:<img src=\"\/assets\/images\/2023-04-05-multicloud-deployment\/release.png\" alt=\"release_creation\" title=\"Release creation\" \/><\/p><p>This will trigger the main workflow, and after the checks have passed, the image is built and pushed to the GitHub container registry. Then the three reusable workflows are called, and since they are working on protected environments, a manual approval is required (e.g. by the SRE team):<img src=\"\/assets\/images\/2023-04-05-multicloud-deployment\/deployment_approval.png\" alt=\"deployments_approval\" title=\"Deployments approval\" \/><\/p><p>Once the approval is granted, the workflows will continue and the new version of the application will be deployed to our three cloud providers:<img src=\"\/assets\/images\/2023-04-05-multicloud-deployment\/deployment_succeeded.png\" alt=\"deployment_succeeded\" title=\"Deployment succeeded\" \/><\/p><p>Is that all? Could be, but you know, sometimes accidents happen. Let\u2019s imagine that\u2019s the case, and that the new version of the application is not working as expected. Mayday, mayday, we need to rollback! Nothing more simple, the administrator will just trigger the workflow again, but this time manually, and on the tag matching the previous release:<img src=\"\/assets\/images\/2023-04-05-multicloud-deployment\/rollback.png\" alt=\"rollback\" title=\"Rollback triggering\" \/><\/p><p>Phew, we\u2019re going back to business! \ud83c\udf89<\/p><h2 id=\"6---next-steps\">6 - Next steps<\/h2><p>That was a lot of fun, and I hope you enjoyed it as much as I did. As usual, this is not for production use, and there is room for improvement. I\u2019m sure you have some ideas on how to make this even better!<\/p><p>We could for instance:<\/p><ul>  <li>define stricter role permissions and RBAC for our service accounts;<\/li>  <li>implement some load-balancing mechanisms (e.g. DNS round-robin, <a href=\"https:\/\/doc.traefik.io\/traefik\/\">Traefik<\/a>) to make the application available on a single URL;<\/li>  <li>extend the workflow to implement blue\/green deployments, A\/B testing or canary release approach.<\/li><\/ul><p>But the sun is shining, and the flowers are blooming, so let\u2019s leave it here for now.<\/p><p>Gassh\u014d \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2023\/04\/05\/multi-clouds-deployment","tags":["actions","oidc","container-app","azure","aws","gcp","release","reusable-workflows","rollback"],"date_published":"2023-04-05T00:00:00+02:00","date_modified":"2023-04-05T00:00:00+02:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2023\/02\/03\/securing-branches-and-deployments","title":"Securing code and its deployment with GitHub branch protection rules","summary":"A story about environment and branch protection","content_text":"  \u26a0\ufe0f Update: Protection rules have now been replaced with more powerful rulesets that offer enhanced control and flexibility over the repository\u2019s workflows and branch protections.Hey shinobis, welcome back to the dojo! Do you remember the previous blog post about deploying GitHub Enterprise Server on Azure the GitOps way? In this post, let\u2019s go a bit further and see some specific steps that secured the pull-request (PR) process and the resulting infrastructure deployment.1 - The PR Process and its shurikensIn the repository, a PR  feature_branch -&gt; main is opened to implement a new feature for the Terraform-coded GHES infrastructure. We\u2019ve seen previously that some GitHub Actions workflows run on that PR to unit test\/analyze the code and generate the according Terraform plan. If the PR is merged, the Terraform plan is applied to the target cloud environment - here Azure - and the GHES infrastructure is deployed with the new feature.I work alone on this repository, and that\u2019s for experimentations only, so overall this process is fine. In many cases however, multiple developers and teams collaborate on the same codebase, and that codebase might be deployed to production environments. In such situations, there are some flying shurikens we need to handle well \u2726\u2726\u2726.What if:  the new code is pushed directly to the main branch without being reviewed &amp; approved?  the new code is not tested for potential bugs or analyzed for potential vulnerabilities (e.g. an Azure resource with too permissive permissions)?  the new code is deployed on a production environment without any notification \/ approval \/ preparation (e.g. from the SRE team)?Some cyberninjas say that the risk 0 is just an illusion. But still, let\u2019s see how we can mitigate these risks using a mix of branch and environment protection rules.2 - Protecting the branchBranch protection rules are a great way to maintain the good health of a branch while collaborating. They can be used for instance to ensure that any new code has been reviewed before being merged, or that specific CI jobs have passed during the PR process.In my repo, the main branch is the one from where the Terraform code is applied in Azure. I\u2019ve therefore set up the following rules for that branch:  a PR is required in order to update the code (i.e. no direct push allowed);  the code of the PR must be approved by at least one code owner;  some jobs of the PR-triggered Actions workflows must pass successfully (they are what we call required status checks);  the commits in the PR must be signed and verified.Each of these rules must be respected before the PR can be merged. All together, they form a nice barrier against the two first shurikens we saw above.The first and second rules ensure that the code is reviewed by the relevant team\/people depending on what\u2019s being changed. Here, it could be for example the IaC team having a look at the new Terraform code and the according plan. Such rules normally ensure that the branch is always in a verified and working state.The third rule ensures that the \u201cUnit test\u201d, \u201cTerraform plan\u201d and \u201cCode Scanning\u201d jobs have run successfully. This allows to i) automatically test and analyze the new code before merging, and ii)  generate the Terraform plan and make it available as a PR comment for review purposes. I\u2019ll likely talk more about the code scanning part in a future blog post.We can see these required status checks in different locations, including the PR \u201cConversation\u201d and \u201cChecks\u201d tab:Finally, the last rule adds some extra-security by requiring valid cryptographic signatures on every commits. Such mechanism makes it more difficult to impersonate someone else and push code on its behalf. By the way, have you heard about GitHub vigilant mode?3 - Deployments rhymes with environmentsAllright, the PR has successfully passed all the main branch protection rules so it is merged. Now the new Terraform code is ready to be deployed, and we have to be sure it will go smoothly. Let\u2019s leverage GitHub Environments to this end.Environments are logical deployment targets for a repository. They are used in Actions workflows to customize code deployments through the use of scoped variables and secrets. An environment can be protected by some rules, and be associated with a specific branch so only the code of this branch will be allowed to be deployed.Here is the production environment I\u2019ve created for my repo:This environment is scoped to the main branch and will target a given Azure tenant through its AZURE_CLIENT_ID secret - used by the \u201cTerraform Apply\u201d job to OIDC-authenticate in Azure. In a more realistic context, we could imagine a second environment named staging with its own AZURE_CLIENT_ID secret to target another Azure tenant. I\u2019ve also added a protection rule specifying that the user @ghsioux (\ud83e\udd77) must manually approve the deployment beforehand.Like this, when the PR is merged and the main branch updated, the \u201cTerraform Apply\u201d job is triggered and I have to approve the deployment first:Once approved, waiting a few minutes for the job to complete, we can see the deployment is active and the GHES URL available:You get it, with environments and their associated protection rules, the last shuriken isn\u2019t a threat anymore.4 - Shurikens to comeToday we have seen how to protect our code from some shurikens, but there are still more to come. For instance, what if sensitive data (e.g. an Azure access key) was pushed to the repo? Or new compliance rules should be enforced on all the repositories of a big organization? We could investigate the use of secret scanning and required workflows for this.Another improvement could be to switch from the deploy -&gt; merge model to the branch deploy model for an even safer main branch.But that\u2019s another story for another time.Gassh\u014d! \ud83d\ude4f","content_html":"<blockquote>  <p>\u26a0\ufe0f <strong>Update:<\/strong> Protection rules have now been replaced with more powerful <a href=\"\/2025\/01\/07\/7-cool-things-with-rulesets\">rulesets<\/a> that offer enhanced control and flexibility over the repository\u2019s workflows and branch protections.<\/p><\/blockquote><p>Hey shinobis, welcome back to the dojo! Do you remember the previous blog post about <a href=\"https:\/\/ghsioux.github.io\/2023\/01\/10\/ghes-azure-gitops\">deploying GitHub Enterprise Server on Azure the GitOps way<\/a>? In this post, let\u2019s go a bit further and see some specific steps that secured the pull-request (PR) process and the resulting infrastructure deployment.<\/p><h2 id=\"1---the-pr-process-and-its-shurikens\">1 - The PR Process and its shurikens<\/h2><p>In the <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\">repository<\/a>, <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/pull\/2\">a PR  <code class=\"language-plaintext highlighter-rouge\">feature_branch -&gt; main<\/code><\/a> is opened to implement a new feature for the Terraform-coded GHES infrastructure. We\u2019ve seen previously that <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/tree\/main\/.github\/workflows\">some GitHub Actions workflows<\/a> run on that PR to unit test\/analyze the code and generate the according Terraform plan. If the PR is merged, the Terraform plan is applied to the target cloud environment - here Azure - and the GHES infrastructure is deployed with the new feature.<\/p><p>I work alone on this repository, and that\u2019s for experimentations only, so overall this process is fine. In many cases however, multiple developers and teams collaborate on the same codebase, and that codebase might be deployed to production environments. In such situations, there are some flying shurikens we need to handle well \u2726\u2726\u2726.<\/p><p>What if:<\/p><ul>  <li>the new code is pushed directly to the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch without being reviewed &amp; approved?<\/li>  <li>the new code is not tested for potential bugs or analyzed for potential vulnerabilities (e.g. an Azure resource with too permissive permissions)?<\/li>  <li>the new code is deployed on a production environment without any notification \/ approval \/ preparation (e.g. from the SRE team)?<\/li><\/ul><p>Some cyberninjas say that the risk 0 is just an illusion. But still, let\u2019s see how we can mitigate these risks using a mix of branch and environment protection rules.<\/p><h2 id=\"2---protecting-the-branch\">2 - Protecting the branch<\/h2><p><a href=\"https:\/\/docs.github.com\/en\/repositories\/configuring-branches-and-merges-in-your-repository\/defining-the-mergeability-of-pull-requests\/about-protected-branches\">Branch protection rules<\/a> are a great way to maintain the good health of a branch while collaborating. They can be used for instance to ensure that <a href=\"https:\/\/docs.github.com\/en\/repositories\/configuring-branches-and-merges-in-your-repository\/defining-the-mergeability-of-pull-requests\/about-protected-branches#require-pull-request-reviews-before-merging\">any new code has been reviewed<\/a> before being merged, or that specific <a href=\"https:\/\/docs.github.com\/en\/repositories\/configuring-branches-and-merges-in-your-repository\/defining-the-mergeability-of-pull-requests\/about-protected-branches#require-status-checks-before-merging\">CI jobs have passed<\/a> during the PR process.<\/p><p>In my repo, the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch is the one from where the Terraform code is applied in Azure. I\u2019ve therefore set up the following rules for that branch:<\/p><ul>  <li>a PR is required in order to update the code (i.e. no direct push allowed);<\/li>  <li>the code of the PR must be approved by at least one <a href=\"https:\/\/docs.github.com\/en\/repositories\/managing-your-repositorys-settings-and-features\/customizing-your-repository\/about-code-owners\">code owner<\/a>;<\/li>  <li>some jobs of the PR-triggered Actions workflows must pass successfully (they are what we call <a href=\"https:\/\/docs.github.com\/en\/repositories\/configuring-branches-and-merges-in-your-repository\/defining-the-mergeability-of-pull-requests\/about-protected-branches#require-status-checks-before-merging\">required status checks<\/a>);<\/li>  <li>the commits in the PR must be <a href=\"https:\/\/docs.github.com\/en\/authentication\/managing-commit-signature-verification\/about-commit-signature-verification\">signed and verified<\/a>.<\/li><\/ul><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/protection_rules.png\" alt=\"branch protection rules\" title=\"Branch protection rules\" \/><\/p><p>Each of these rules must be respected before the PR can be merged. All together, they form a nice barrier against the two first shurikens we saw above.<\/p><p>The first and second rules ensure that the code is reviewed by the relevant team\/people depending on what\u2019s being changed. Here, it could be for example the IaC team having a look at the new Terraform code and the according plan. Such rules normally ensure that the branch is always in a verified and working state.<\/p><p>The third rule ensures that the <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/blob\/main\/.github\/workflows\/tf-unit-tests.yml#L9-L33\">\u201cUnit test\u201d<\/a>, <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/blob\/main\/.github\/workflows\/tf-plan-apply.yml#LL30-L122C15\">\u201cTerraform plan\u201d<\/a> and <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/blob\/main\/.github\/workflows\/tf-unit-tests.yml#LL35-L48C26\">\u201cCode Scanning\u201d<\/a> jobs have run successfully. This allows to <strong>i)<\/strong> automatically test and analyze the new code before merging, and <strong>ii)<\/strong>  generate the Terraform plan and <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/blob\/main\/.github\/workflows\/tf-plan-apply.yml#LL107-L122C15\">make it available<\/a> as <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/pull\/2#issuecomment-1376268820\">a PR comment<\/a> for review purposes. I\u2019ll likely talk more about the code scanning part in a future blog post.<\/p><p>We can see these required status checks in different locations, including the PR \u201cConversation\u201d and \u201cChecks\u201d tab:<\/p><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/checks.png\" alt=\"required status checks\" title=\"Required status checks\" \/><\/p><p>Finally, the last rule adds some extra-security by requiring valid cryptographic signatures on every commits. Such mechanism makes it more difficult to impersonate someone else and push code on its behalf. By the way, have you heard about <a href=\"https:\/\/docs.github.com\/en\/authentication\/managing-commit-signature-verification\/displaying-verification-statuses-for-all-of-your-commits\">GitHub vigilant mode<\/a>?<\/p><h2 id=\"3---deployments-rhymes-with-environments\">3 - Deployments rhymes with environments<\/h2><p>Allright, the PR has successfully passed all the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch protection rules so it is merged. Now the new Terraform code is ready to be deployed, and we have to be sure it will go smoothly. Let\u2019s leverage <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/targeting-different-environments\/using-environments-for-deployment\">GitHub Environments<\/a> to this end.<\/p><p>Environments are logical deployment targets for a repository. They are used in Actions workflows to customize code deployments through the use of scoped <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/targeting-different-environments\/using-environments-for-deployment#environment-secrets\">variables and secrets<\/a>. An environment can be protected by some rules, and be associated with a specific branch so only the code of this branch will be allowed to be deployed.<\/p><p>Here is the <code class=\"language-plaintext highlighter-rouge\">production<\/code> environment I\u2019ve created for my repo:<\/p><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/environment.png\" alt=\"environment_secrets_variables\" title=\"Environment secrets and variables\" \/><\/p><p>This environment is scoped to the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch and will target a given Azure tenant through its <code class=\"language-plaintext highlighter-rouge\">AZURE_CLIENT_ID<\/code> secret - used by the \u201cTerraform Apply\u201d job to <a href=\"https:\/\/docs.github.com\/en\/actions\/deployment\/security-hardening-your-deployments\/configuring-openid-connect-in-azure\">OIDC-authenticate in Azure<\/a>. In a more realistic context, we could imagine a second environment named <code class=\"language-plaintext highlighter-rouge\">staging<\/code> with its own <code class=\"language-plaintext highlighter-rouge\">AZURE_CLIENT_ID<\/code> secret to target another Azure tenant. I\u2019ve also added a protection rule specifying that the user @ghsioux (\ud83e\udd77) must manually approve the deployment beforehand.<\/p><p>Like this, when the PR is merged and the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch updated, the \u201cTerraform Apply\u201d job is triggered and I have to approve the deployment first:<\/p><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/review_deployment_1.png\" alt=\"deployment review required\" title=\"deployment review required\" \/><\/p><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/review_deployment_2.png\" alt=\"deployment review done\" title=\"deployment review done\" \/><\/p><p>Once approved, waiting a few minutes for the job to complete, we can see the deployment is active and the GHES URL available:<\/p><p><img src=\"\/assets\/images\/2023-02-03-securing-branches-and-deployments\/deployment.png\" alt=\"successful_deployment\" title=\"Successful deployment\" \/><\/p><p>You get it, with environments and their associated protection rules, the last shuriken isn\u2019t a threat anymore.<\/p><h2 id=\"4---shurikens-to-come\">4 - Shurikens to come<\/h2><p>Today we have seen how to protect our code from some shurikens, but there are still more to come. For instance, what if sensitive data (e.g. an Azure access key) was pushed to the repo? Or new compliance rules should be enforced on all the repositories of a big organization? We could investigate the use of <a href=\"https:\/\/docs.github.com\/en\/code-security\/secret-scanning\/about-secret-scanning\">secret scanning<\/a> and <a href=\"https:\/\/docs.github.com\/en\/actions\/using-workflows\/required-workflows\">required workflows<\/a> for this.<\/p><p>Another improvement could be to switch from the <a href=\"https:\/\/github.blog\/2023-02-02-enabling-branch-deployments-through-issueops-with-github-actions\/#understanding-the-branch-deploy-model\"><strong>deploy -&gt; merge<\/strong> model to the <strong>branch deploy<\/strong> model<\/a> for an even safer <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch.<\/p><p>But that\u2019s another story for another time.<\/p><p>Gassh\u014d! \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2023\/02\/03\/securing-branches-and-deployments","tags":["actions","pull-request","administration","security"],"date_published":"2023-02-03T00:00:00+01:00","date_modified":"2023-02-03T00:00:00+01:00","author":{"name":"ghsioux","url":null,"avatar":null}},{"id":"https:\/\/ghsioux.github.io\/2023\/01\/10\/ghes-azure-gitops","title":"Deploying GitHub Enterprise Server on Azure the GitOps way","summary":"A story about GHES, Terraform, GitHub Actions and the GitOps' holy spirit","content_text":"0 - IntroductionAs a zen apprentice I like to free my mind as much as I can, specially regarding if\/where\/how my ressources are deployed in the cloud \u2601\ufe0f.In this post I\u2019ll share a simple way to do so, through the example of a GitHub Enterprise Server (GHES) instance that I use for testing purposes. This GHES instance is described as Terraform code and deployed in Azure using GitHub Actions workflows.The code can be found in this repository which is based on Azure-Samples\/terraform-github-actions, a sample repository that shows how to use GitHub Actions workflows to manage Azure infrastructure with Terraform.1 - The infrastructureThe Terraform code used to describe the target infrastructure - that is, the GHES related resources - is split into several files:\u276f tree -Pa '*.tf|*.tfvars|*.hcl' --prune.\u251c\u2500\u2500 .terraform.lock.hcl\u251c\u2500\u2500 main.tf\u251c\u2500\u2500 outputs.tf\u251c\u2500\u2500 providers.tf\u251c\u2500\u2500 terraform.tfvars\u2514\u2500\u2500 variables.tfOverall this is a typical file structure for a simple Terraform project:  main.tf contains the main Terraform code, where Azure ressources (e.g. storage account, vnet, VM, etc.) are defined to be deployed;  providers.tf references plugins that allow Terraform to interact with cloud providers (here Azure);  variables.tf and terraform.tfvars respectively defines and assign custom values to variables used in main.tf to customize the resources;  outputs.tf defines the outputs that the Terraform code will return regarding the deployed resources (e.g. Azure resource group, VM\u2019s public IP, FQDN).The special file .terraform.lock.hcl is a lock file ensuring that the same versions of the plugins are used by all collaborators of the repo.2 - The Action workflowsThe .github\/workflows directory contains the GitHub Actions workflows that will work with the Terraform code.\u276f tree -Pa '*.yml' --prune.\u2514\u2500\u2500 .github    \u2514\u2500\u2500 workflows        \u251c\u2500\u2500 tf-drift.yml        \u251c\u2500\u2500 tf-plan-apply.yml        \u2514\u2500\u2500 tf-unit-tests.ymlHere are the main characteristics of these workflows:            Workflow      Triggering events      Description                  tf-unit-tests.yml      push on any branch      Runs unit tests and analyze the Terraform code.              tf-plan-apply.yml      pull_request or push to main branch      Builds the Terraform plan and applies it in Azure.              tf-drift.yml      schedule or manual      Detects drifts between the desired and the current infrastructure.      A nice thing is that the Terraform state is stored in an Azure storage account, so that it can be shared between the workflows to retrieve the currently deployed infrastructure. For more information, see the README of the repository.Another noteworthy point is the use of the paths keyword in the workflow files, allowing to trigger the workflows only if the Terraform files have been modified, e.g.:on:  push:    paths:    - '**.tf'    - '**.tfvars' 3 - Putting it all together (a.k.a. the GitOps part)Combining both Terraform and GitHub Actions allows us to embrace the GitOps paradigm. Here is a typical process leveraging this approach:      Clone the repo and create a new branch to work on a new feature, or to update a Terraform variable that\u2019ll in turn update the GHES deployment;        Once the Terraform code has been updated, push the changes to the remote repo and open a pull request towards the main branch;        The tf-unit-tests.yml workflow is triggered to test the Terraform code;    In parallel, the tf-plan-apply.yml workflow is triggered to build the Terraform plan and to share it as a comment in the PR conversation, for review purposes;      After all the PR required checks and reviews have passed, the PR can be merged into the main branch;    Once the PR merged, the tf-plan-apply.yml workflow is triggered again, and this time it applies the Terraform plan in Azure, effectively deploying the GHES resources;At this point, my GitHub Enterprise Server instance is deployed in Azure and ready to be used (or well, to be set up if it\u2019s the first boot :)Now that the deployment is done, we want to ensure the infrastructure is always in line with the Terraform code.Indeed, unwanted changes might occur in the infrastructure along time, like the VM being deleted manually or the DNS name being updated. This is where the tf-drift.yml workflow comes into play.This workflow is triggered every day to detect drifts between the desired (i.e. the Terraform code) and the currently deployed infrastructure. If drifts are detected, the workflow will open a new issue, and I\u2019ll receive a notification from GitHub:4 - The endThat\u2019s it for today folks, I hope you enjoyed this post and that it will help you to get started with Terraform and GitHub Actions.As usual, this is more like a PoC and many improvements can be done. Zen masters often say that \u201cthe journey is never ending\u201d.As a future work, I\u2019d like to play with the Terraform provider for GitHub to store GHES configuration (e.g. organizations, policies, teams) as code, and write additional workflows to leverage it. I\u2019ll also write another post to go further into the main branch protection rules and the unit tests workflow, as it includes some nice code scanning features.Oh and by the way, this blog post has been co-written with Copilot \ud83e\udd16.Gassh\u014d! \ud83d\ude4f","content_html":"<h2 id=\"0---introduction\">0 - Introduction<\/h2><p>As a zen apprentice I like to free my mind as much as I can, specially regarding if\/where\/how my ressources are deployed in the cloud \u2601\ufe0f.<\/p><p>In this post I\u2019ll share a simple way to do so, through the example of a GitHub Enterprise Server (GHES) instance that I use for testing purposes. This GHES instance is described as Terraform code and deployed in Azure using GitHub Actions workflows.<\/p><p>The code can be found <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/\">in this repository<\/a> which is based on <a href=\"https:\/\/github.com\/Azure-Samples\/terraform-github-actions\/\">Azure-Samples\/terraform-github-actions<\/a>, a sample repository that shows how to use GitHub Actions workflows to manage Azure infrastructure with Terraform.<\/p><h2 id=\"1---the-infrastructure\">1 - The infrastructure<\/h2><p>The Terraform code used to describe the target infrastructure - that is, the GHES related resources - is split into several files:<\/p><div class=\"language-zsh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>\u276f tree <span class=\"nt\">-Pa<\/span> <span class=\"s1\">'*.tf|*.tfvars|*.hcl'<\/span> <span class=\"nt\">--prune<\/span><span class=\"nb\">.<\/span>\u251c\u2500\u2500 .terraform.lock.hcl\u251c\u2500\u2500 main.tf\u251c\u2500\u2500 outputs.tf\u251c\u2500\u2500 providers.tf\u251c\u2500\u2500 terraform.tfvars\u2514\u2500\u2500 variables.tf<\/code><\/pre><\/div><\/div><p>Overall this is a typical file structure for a simple Terraform project:<\/p><ul>  <li><code class=\"language-plaintext highlighter-rouge\">main.tf<\/code> contains the main Terraform code, where Azure ressources (e.g. storage account, vnet, VM, etc.) are defined to be deployed;<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">providers.tf<\/code> references plugins that allow Terraform to interact with cloud providers (here Azure);<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">variables.tf<\/code> and <code class=\"language-plaintext highlighter-rouge\">terraform.tfvars<\/code> respectively <strong>defines<\/strong> and <strong>assign custom values<\/strong> to variables used in <code class=\"language-plaintext highlighter-rouge\">main.tf<\/code> to customize the resources;<\/li>  <li><code class=\"language-plaintext highlighter-rouge\">outputs.tf<\/code> defines the outputs that the Terraform code will return regarding the deployed resources (e.g. Azure resource group, VM\u2019s public IP, FQDN).<\/li><\/ul><p>The special file <code class=\"language-plaintext highlighter-rouge\">.terraform.lock.hcl<\/code> is a lock file ensuring that the same versions of the plugins are used by all collaborators of the repo.<\/p><h2 id=\"2---the-action-workflows\">2 - The Action workflows<\/h2><p>The <code class=\"language-plaintext highlighter-rouge\">.github\/workflows<\/code> directory contains the GitHub Actions workflows that will work with the Terraform code.<\/p><div class=\"language-zsh highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>\u276f tree <span class=\"nt\">-Pa<\/span> <span class=\"s1\">'*.yml'<\/span> <span class=\"nt\">--prune<\/span><span class=\"nb\">.<\/span>\u2514\u2500\u2500 .github    \u2514\u2500\u2500 workflows        \u251c\u2500\u2500 tf-drift.yml        \u251c\u2500\u2500 tf-plan-apply.yml        \u2514\u2500\u2500 tf-unit-tests.yml<\/code><\/pre><\/div><\/div><p>Here are the main characteristics of these workflows:<\/p><table>  <thead>    <tr>      <th>Workflow<\/th>      <th>Triggering events<\/th>      <th>Description<\/th>    <\/tr>  <\/thead>  <tbody>    <tr>      <td><code class=\"language-plaintext highlighter-rouge\">tf-unit-tests.yml<\/code><\/td>      <td><code class=\"language-plaintext highlighter-rouge\">push<\/code> on any branch<\/td>      <td>Runs unit tests and analyze the Terraform code.<\/td>    <\/tr>    <tr>      <td><code class=\"language-plaintext highlighter-rouge\">tf-plan-apply.yml<\/code><\/td>      <td><code class=\"language-plaintext highlighter-rouge\">pull_request<\/code> or <code class=\"language-plaintext highlighter-rouge\">push<\/code> to <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch<\/td>      <td>Builds the Terraform plan and applies it in Azure.<\/td>    <\/tr>    <tr>      <td><code class=\"language-plaintext highlighter-rouge\">tf-drift.yml<\/code><\/td>      <td><code class=\"language-plaintext highlighter-rouge\">schedule<\/code> or manual<\/td>      <td>Detects drifts between the desired and the current infrastructure.<\/td>    <\/tr>  <\/tbody><\/table><p>A nice thing is that the Terraform state is stored in an Azure storage account, so that it can be shared between the workflows to retrieve the currently deployed infrastructure. For more information, see <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/blob\/main\/README.md\">the README<\/a> of the repository.<\/p><p>Another noteworthy point is the use of the <a href=\"https:\/\/docs.github.com\/en\/actions\/using-workflows\/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore\"><code class=\"language-plaintext highlighter-rouge\">paths<\/code><\/a> keyword in the workflow files, allowing to trigger the workflows only if the Terraform files have been modified, e.g.:<\/p><div class=\"language-yaml highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"na\">on<\/span><span class=\"pi\">:<\/span>  <span class=\"na\">push<\/span><span class=\"pi\">:<\/span>    <span class=\"na\">paths<\/span><span class=\"pi\">:<\/span>    <span class=\"pi\">-<\/span> <span class=\"s1\">'<\/span><span class=\"s\">**.tf'<\/span>    <span class=\"pi\">-<\/span> <span class=\"s1\">'<\/span><span class=\"s\">**.tfvars'<\/span> <\/code><\/pre><\/div><\/div><h2 id=\"3---putting-it-all-together-aka-the-gitops-part\">3 - Putting it all together (a.k.a. the GitOps part)<\/h2><p>Combining both Terraform and GitHub Actions allows us to embrace the GitOps paradigm. Here is a typical process leveraging this approach:<\/p><ol>  <li>    <p>Clone the repo and create a new branch to work on a new feature, or to update a Terraform variable that\u2019ll in turn update the GHES deployment;<\/p>  <\/li>  <li>    <p>Once the Terraform code has been updated, push the changes to the remote repo and open <a href=\"https:\/\/github.com\/ghsioux-octodemo\/deploy-ghes-azure-terraform\/pull\/2\">a pull request<\/a> towards the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch;<\/p>  <\/li>  <li>    <p>The <code class=\"language-plaintext highlighter-rouge\">tf-unit-tests.yml<\/code> workflow is triggered to test the Terraform code;<img src=\"\/assets\/images\/2023-01-10-ghes-azure-gitops\/unit-tests.png\" alt=\"the unit tests workflow\" title=\"The unit tests workflow\" \/><\/p>  <\/li>  <li>In parallel, the <code class=\"language-plaintext highlighter-rouge\">tf-plan-apply.yml<\/code> workflow is triggered to build the Terraform plan and to share it as a comment in the PR conversation, for review purposes;<img src=\"\/assets\/images\/2023-01-10-ghes-azure-gitops\/terraform_plan.png\" alt=\"the Terraform plan\" title=\"The Terraform plan\" \/><\/li>  <li>    <p>After all the PR <a href=\"https:\/\/docs.github.com\/en\/repositories\/configuring-branches-and-merges-in-your-repository\/defining-the-mergeability-of-pull-requests\/about-protected-branches#require-status-checks-before-merging\">required checks<\/a> and <a href=\"https:\/\/docs.github.com\/en\/pull-requests\/collaborating-with-pull-requests\/reviewing-changes-in-pull-requests\/approving-a-pull-request-with-required-reviews\">reviews<\/a> have passed, the PR can be merged into the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch;<\/p>  <\/li>  <li>Once the PR merged, the <code class=\"language-plaintext highlighter-rouge\">tf-plan-apply.yml<\/code> workflow is triggered again, and this time it applies the Terraform plan in Azure, effectively deploying the GHES resources;<img src=\"\/assets\/images\/2023-01-10-ghes-azure-gitops\/tf-plan-apply-push.png\" alt=\"the Terraform apply\" title=\"The Terraform apply\" \/><\/li><\/ol><p>At this point, my GitHub Enterprise Server instance is deployed in Azure and ready to be used (or well, to be set up if it\u2019s the first boot :)<img src=\"\/assets\/images\/2023-01-10-ghes-azure-gitops\/ghes_first_boot.png\" alt=\"GHES first boot\" title=\"GHES first boot\" \/><\/p><p>Now that the deployment is done, we want to ensure the infrastructure is always in line with the Terraform code.Indeed, unwanted changes might occur in the infrastructure along time, like the VM being deleted manually or the DNS name being updated. This is where the <code class=\"language-plaintext highlighter-rouge\">tf-drift.yml<\/code> workflow comes into play.<\/p><p>This workflow is triggered every day to detect drifts between the desired (i.e. the Terraform code) and the currently deployed infrastructure. If drifts are detected, the workflow will open a new issue, and I\u2019ll receive a <a href=\"https:\/\/docs.github.com\/en\/account-and-profile\/managing-subscriptions-and-notifications-on-github\/setting-up-notifications\/configuring-notifications#about-custom-notifications\">notification from GitHub<\/a>:<img src=\"\/assets\/images\/2023-01-10-ghes-azure-gitops\/drift.png\" alt=\"the drift issue\" title=\"The drift issue\" \/><\/p><h2 id=\"4---the-end\">4 - The end<\/h2><p>That\u2019s it for today folks, I hope you enjoyed this post and that it will help you to get started with Terraform and GitHub Actions.<\/p><p>As usual, this is more like a PoC and many improvements can be done. Zen masters often say that \u201cthe journey is never ending\u201d.<\/p><p>As a future work, I\u2019d like to play with <a href=\"https:\/\/registry.terraform.io\/providers\/integrations\/github\/latest\/docs\">the Terraform provider for GitHub<\/a> to store GHES configuration (e.g. organizations, policies, teams) as code, and write additional workflows to leverage it. I\u2019ll also write another post to go further into the <code class=\"language-plaintext highlighter-rouge\">main<\/code> branch protection rules and the unit tests workflow, as it includes some nice <a href=\"https:\/\/docs.github.com\/en\/code-security\/code-scanning\/automatically-scanning-your-code-for-vulnerabilities-and-errors\/about-code-scanning\">code scanning<\/a> features.<\/p><p>Oh and by the way, this blog post has been co-written with Copilot \ud83e\udd16.<\/p><p>Gassh\u014d! \ud83d\ude4f<\/p>","url":"https:\/\/ghsioux.github.io\/2023\/01\/10\/ghes-azure-gitops","tags":["ghes","terraform","actions","gitops","azure"],"date_published":"2023-01-10T00:00:00+01:00","date_modified":"2023-01-10T00:00:00+01:00","author":{"name":"ghsioux","url":null,"avatar":null}}]}