PSRule
repository·main·Indexed 19 days ago
https://github.com/microsoft/psruleA cross-platform engine used to validate Infrastructure as Code (IaC) and objects against custom rules. PSRule integrates into DevOps workflows via Azure Pipelines, GitHub Actions, and Visual Studio Code to provide fast feedback and quality gates. It supports rule definitions in YAML, JSON, and PowerShell, and is compatible with Linux, MacOS, and Windows. Key features include a Domain Specific Language (DSL) for assertions, a .NET SDK, and a command-line tool (Microsoft.PSRule.Tool).
What's inside PSRule
- The PSRule Build Tool is a utility designed to prepare specific artifacts required before building a PSRule solution. It serves as a pre-build step to ensure all necessary components and dependencies are in place for the main PSRule build process.
What is PSRule and what can it validate?
mainPSRule is a PowerShell-based engine designed to validate Infrastructure as Code (IaC) and any arbitrary PowerShell object. It acts as a validation engine that processes object graphs against a set of defined rules.
PSRule natively supports the following file formats:
- YAML (
.yamlor.yml) - JSON (
.json) - PowerShell Data Files (
.psd1) - Markdown front matter (
.mdor.markdown)
Common IaC tools like Terraform can be integrated by exporting their state or plans to JSON (e.g.,
terraform show -json) and passing that output to PSRule.- YAML (
What is PSRule?
mainPSRule is a rules engine designed for testing Infrastructure as Code (IaC). It performs static analysis on various IaC artifacts to ensure they adhere to defined standards and best practices.
Supported artifacts for analysis include:
- Templates
- Manifests
- Pipelines
- Workflows
Overview of PSRule features and objectives
mainPSRule is a cross-platform module designed for validating infrastructure as code (IaC).
Key Features
- DevOps Support: Built to provide fast feedback in pull requests and implement quality gates between environments (dev, test, prod).
- Extensibility: Rules can be defined using YAML, JSON, or PowerShell formats.
- Reusability: Rules can be shared across teams or organizations and can be disabled where they are not applicable.
Core Design Principles
- Cross-platform: Supports rule validation and authoring on Linux, MacOS, and Windows. It can also run in a Linux container for CI systems that do not support PowerShell natively.
Overview of Microsoft.PSRule.Types
mainTheMicrosoft.PSRule.Typeslibrary provides the core underlying type definitions and support structures used by the PSRule engine. It is a foundational component for developers working with PSRule types in .NET.Explore PSRule community modules
mainThere are third-party modules available for PSRule. Note that these are maintained by external authors and should be evaluated for security and licensing before use in an organization.
Author Name Description cloudyspells PSRule.Rules.AzureDevOps Rules to validate Azure DevOps projects Use Microsoft.PSRule.Badges for badge creation
mainTheMicrosoft.PSRule.Badgeslibrary provides the underlying implementation and support for creating badges within the PSRule badge API. It is intended to be used as a dependency when working with the PSRule badge ecosystem to generate visual indicators for rule compliance or status.Use PSRule Editor Services in Visual Studio Code
mainThePSRule.EditorServiceslibrary provides the language server support required to enable PSRule features within Visual Studio Code. This allows for language-specific intelligence, such as syntax highlighting, validation, and error reporting, directly within the editor.Consume PSRule for .NET using the SDK
mainThe PSRule SDK for .NET allows developers to integrate PSRule capabilities directly into .NET applications. This package provides the necessary interfaces and logic to consume PSRule's rule-based validation and analysis within the .NET ecosystem.Explore PSRule related projects and ecosystem
mainThe PSRule ecosystem is distributed across several specialized repositories for CI/CD integration, IDE support, monitoring, and specific rule sets. Depending on your needs, you may want to use specific modules for Azure, Kubernetes, or GitHub validation.
### Official Microsoft Projects | Name | Description | | :--- | :--- | | [ps-rule](https://github.com/microsoft/ps-rule) | GitHub continuous integration using GitHub Actions | | [PSRule-pipelines](https://github.com/microsoft/PSRule-pipelines) | Azure DevOps continuous integration using Azure Pipelines | | [PSRule-vscode](https://github.com/microsoft/PSRule-vscode) | Support for running and authoring rules within Visual Studio Code | | [PSRule.Monitor](https://github.com/microsoft/PSRule.Monitor) | Support for logging PSRule analysis results to Azure Monitor | | [PSRule.Rules.Azure](https://aka.ms/ps-rule-azure) | Rules to validate Azure resources and IaC | | [PSRule.Rules.Azure-quickstart](https://github.com/Azure/PSRule.Rules.Azure-quickstart) | Sample code for Azure validation | | [PSRule.Rules.CAF](https://github.com/microsoft/PSRule.Rules.CAF) | Rules for Azure Cloud Adoption Framework (CAF) | | [PSRule.Rules.GitHub](https://github.com/microsoft/PSRule.Rules.GitHub) | Rules to validate GitHub repositories | | [PSRule.Rules.Kubernetes](https://github.com/microsoft/PSRule.Rules.Kubernetes) | Rules to validate Kubernetes resources | | [PSRule.Rules.MSFT.OSS](https://github.com/microsoft/PSRule.Rules.MSFT.OSS) | Rules for Microsoft OSS requirements |Overview of PSRule Keywords
mainPSRule uses specific language keywords within rule definitions to implement logic, such as checking for the existence of properties, validating field values, or comparing counts against configuration thresholds. These keywords allow you to define complex validation logic in a declarative way within your rules.What is a Selector and how to use it
mainA Selector is a filtering mechanism used to determine if a rule should be executed or skipped. Selectors use YAML or JSON expressions to evaluate properties on a target object.
- If the selector evaluates to
true, the rule is run and will either pass or fail. - If the selector evaluates to
false, the rule is skipped.
Selectors are useful for narrowing down the scope of rules (e.g., only running a rule on services that have an 'Automatic' start type).
--- # Synopsis: Find services with an automatic start type. apiVersion: github.com/microsoft/PSRule/2025-01-01 kind: Selector metadata: name: Yaml.IsAutomaticService spec: if: field: StartType startsWith: Automatic convert: true- If the selector evaluates to