зеркало из
1
0
Форкнуть 0
Rules to validate Azure resources and infrastructure as code (IaC) using PSRule.
Перейти к файлу
dependabot[bot] 9259b3b622
Bump actions/upload-artifact from 3 to 4 (#2609)
* Bump actions/upload-artifact from 3 to 4

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Pipeline updates

* Fixes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bernie White <bewhite@microsoft.com>
2024-01-02 00:17:40 +10:00
.config Fixes and improvements for Export-AzRuleData #1341 (#2001) 2023-01-25 01:28:15 +10:00
.devcontainer Minor updates to codespace config (#2585) 2023-12-08 11:17:07 +10:00
.github Bump actions/upload-artifact from 3 to 4 (#2609) 2024-01-02 00:17:40 +10:00
.ps-rule Fixed false positives for secure parameter #2556 (#2561) 2023-12-01 01:35:11 +10:00
.vscode Add secure value check #1476 (#2504) 2023-11-02 19:46:53 +10:00
data Updated providers and policy aliases #2579 (#2582) 2023-12-11 00:39:34 +10:00
docs Bump xunit.runner.visualstudio from 2.5.4 to 2.5.6 (#2619) 2024-01-01 22:45:43 +10:00
overrides Update docs build templates (#2596) 2023-12-12 12:26:25 +10:00
scripts Updated providers and policy aliases #2579 (#2582) 2023-12-11 00:39:34 +10:00
src Fixes cast with union array and mock #2614 (#2615) 2023-12-18 16:51:44 +10:00
tests Bump xunit.runner.visualstudio from 2.5.4 to 2.5.6 (#2619) 2024-01-01 22:45:43 +10:00
.editorconfig Code quality updates (#2267) 2023-06-07 11:40:46 +10:00
.gitignore Update to docs build for Spanish (#1742) 2022-10-03 22:06:36 +10:00
.markdownlint.json Doc updates #2134 (#2142) 2023-04-07 17:19:30 +10:00
BaselineToc.Doc.ps1 Quality updates for documentation (#2562) 2023-12-01 04:48:34 +10:00
CHANGELOG.md Updates to change log (#1673) 2022-09-20 13:29:03 +10:00
CODE_OF_CONDUCT.md Apply OSS guidelines #250 #251 (#260) 2020-02-06 22:22:54 +11:00
CONTRIBUTING.md Fixes for documentation links including #2557 (#2558) 2023-11-29 01:56:40 +10:00
GitVersion.yml Added GitVersion config (#1375) 2022-04-26 13:37:16 +10:00
LICENSE Apply OSS guidelines #250 #251 (#260) 2020-02-06 22:22:54 +11:00
NuGet.config Add NuGet config (#1647) 2022-09-14 18:37:27 +10:00
PSRule.Rules.Azure.sln Updated providers and policy aliases #2579 (#2582) 2023-12-11 00:39:34 +10:00
README.md Fixes for documentation links including #2557 (#2558) 2023-11-29 01:56:40 +10:00
RuleHelp.Doc.ps1 Update links with Azure org #800 (#804) 2021-06-18 00:14:44 +10:00
RuleToc.Doc.ps1 Quality updates for documentation (#2562) 2023-12-01 04:48:34 +10:00
SECURITY.md Updated template file (#2523) 2023-11-09 00:35:41 +10:00
SUPPORT.md Web updates (#803) 2021-06-17 23:55:40 +10:00
ThirdPartyNotices.txt Export template with custom subscription and resource group #651 (#659) 2021-02-22 21:27:01 +10:00
bicepconfig.json Fixes cast with union array and mock #2614 (#2615) 2023-12-18 16:51:44 +10:00
build.ps1 Update build to use GitHub Actions #1696 (#2030) 2023-02-12 00:29:20 +10:00
mkdocs.yml Update docs build templates (#2596) 2023-12-12 12:26:25 +10:00
modules.json Dependencies/powershell bump (#2293) 2023-07-03 00:27:44 +10:00
pipeline.build.ps1 Update development tools to .NET 7.0 #1870 (#2473) 2023-10-08 04:17:35 +10:00
ps-docs.yaml Bump CI pipeline (#828) 2021-07-06 13:58:43 +10:00
ps-project.yaml Bump PSRule dependency to v1.9.0 #1081 (#1082) 2021-11-11 01:48:16 +10:00
ps-rule.yaml Update GitHub Actions build CI (#2029) 2023-02-11 22:33:58 +10:00
requirements-docs.txt Bump pymdown-extensions from 10.5 to 10.7 (#2622) 2024-01-01 13:04:21 +10:00

README.md

PSRule for Azure

A suite of rules to validate Azure resources and infrastructure as code (IaC) using PSRule.

Open in vscode.dev

Features of PSRule for Azure include:

  • Learn by example - Fix issues quickly, and learn how to improve your Infrastructure as Code..

  • Framework aligned - Apply principals of Azure Well-Architected Framework to your workloads.

  • Start day one - Leverage over 400 pre-built rules to test Azure resources.

  • DevOps integrated - Test Azure infrastructure as code such as Bicep or Azure Resource Manager templates.

  • Cross-platform - Run locally or in the cloud on MacOS, Linux, and Windows.

  • Open community - Open source rules for the Azure community.

Project objectives

  1. Ready to go:
  2. DevOps:
    • Resources and templates can be validated before deployment within DevOps workflows.
    • Allow pull request (PR) validation to prevent invalid configuration being merged.
  3. Enterprise ready:
    • Rules can be directly adopted and additional enterprise specific rules can be layed on.
    • Provide regular baselines to allow progressive adoption.

Support

This project uses GitHub Issues to track bugs and feature requests. Before logging an issue please see our troubleshooting guide.

Please search the existing issues before filing new issues to avoid duplicates.

  • For new issues, file your bug or feature request as a new issue.
  • For help, discussion, and support questions about using this project, join or start a discussion.

If you have any problems with the PSRule engine, please check the project GitHub issues page instead.

Support for this project/ product is limited to the resources listed above.

Getting the modules

This project requires the PSRule and Az PowerShell modules. For details on each see install.

You can download and install these modules from the PowerShell Gallery.

Module Description Downloads / instructions
PSRule.Rules.Azure Validate Azure resources and infrastructure as code using PSRule. latest / instructions

For rule and integration modules see related projects.

Getting started

PSRule for Azure provides two methods for analyzing Azure resources:

  • Pre-flight - Before resources are deployed from Azure Resource Manager templates.
  • In-flight - After resources are deployed to an Azure subscription.

For specific use cases see scenarios. For additional details see the FAQ.

To get started with a sample repository, see PSRule for Azure Quick Start on GitHub.

Using with GitHub Actions

The following example shows how to setup GitHub Actions to validate templates pre-flight.

  1. See Creating a workflow file.
  2. Reference Microsoft/ps-rule with modules: 'PSRule.Rules.Azure'.

For example:

# Example: .github/workflows/analyze-arm.yaml

#
# STEP 1: Template validation
#
name: Analyze templates
on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main
jobs:
  analyze_arm:
    name: Analyze templates
    runs-on: ubuntu-latest
    steps:

    - name: Checkout
      uses: actions/checkout@v3

    # STEP 2: Run analysis against exported data
    - name: Analyze Azure template files
      uses: microsoft/ps-rule@v2.9.0
      with:
        modules: 'PSRule.Rules.Azure'  # Analyze objects using the rules within the PSRule.Rules.Azure PowerShell module.

Using with Azure Pipelines

The following example shows how to setup Azure Pipelines to validate templates pre-flight.

  1. Install PSRule extension for Azure DevOps marketplace.
  2. Create a new YAML pipeline with the Starter pipeline template.
  3. Add the Install PSRule module task.
    • Set module to PSRule.Rules.Azure.
  4. Add the PSRule analysis task.
    • Set input type to repository.
    • Set modules to PSRule.Rules.Azure.

For example:

# Example: .azure-pipelines/analyze-arm.yaml

#
# STEP 2: Template validation
#
jobs:
- job: 'analyze_arm'
  displayName: 'Analyze templates'
  pool:
    vmImage: 'ubuntu-22.04'
  steps:

  # STEP 3: Install PSRule.Rules.Azure from the PowerShell Gallery
  - task: ps-rule-install@2
    displayName: Install PSRule.Rules.Azure
    inputs:
      module: 'PSRule.Rules.Azure'   # Install PSRule.Rules.Azure from the PowerShell Gallery.

  # STEP 4: Run analysis against exported data
  - task: ps-rule-assert@2
    displayName: Analyze Azure template files
    inputs:
      modules: 'PSRule.Rules.Azure'   # Analyze objects using the rules within the PSRule.Rules.Azure PowerShell module.

Using locally

The following example shows how to setup PSRule locally to validate templates pre-flight.

  1. Install the PSRule.Rules.Azure module and dependencies from the PowerShell Gallery.
  2. Run analysis against repository files.

For example:

# STEP 1: Install PSRule.Rules.Azure from the PowerShell Gallery
Install-Module -Name 'PSRule.Rules.Azure' -Scope CurrentUser;

# STEP 2: Run analysis against exported data
Assert-PSRule -Module 'PSRule.Rules.Azure' -InputPath 'out/templates/' -Format File;

Export in-flight resource data

The following example shows how to setup PSRule locally to validate resources running in a subscription.

  1. Install the PSRule.Rules.Azure module and dependencies from the PowerShell Gallery.
  2. Connect and set context to an Azure subscription from PowerShell.
  3. Export the resource data with the Export-AzRuleData cmdlet.
  4. Run analysis against exported data.

For example:

# STEP 1: Install PSRule.Rules.Azure from the PowerShell Gallery
Install-Module -Name 'PSRule.Rules.Azure' -Scope CurrentUser;

# STEP 2: Authenticate to Azure, only required if not currently connected
Connect-AzAccount;

# Confirm the current subscription context
Get-AzContext;

# STEP 3: Exports a resource graph stored as JSON for analysis
Export-AzRuleData -OutputPath 'out/templates/';

# STEP 4: Run analysis against exported data
Assert-PSRule -Module 'PSRule.Rules.Azure' -InputPath 'out/templates/';

Additional options

By default, resource data for the current subscription context will be exported.

To export resource data for specific subscriptions use:

  • -Subscription - to specify subscriptions by id or name.
  • -Tenant - to specify subscriptions within an Azure Active Directory Tenant by id.

For example:

# Export data from two specific subscriptions
Export-AzRuleData -Subscription 'Contoso Production', 'Contoso Non-production';

To export specific resource data use:

  • -ResourceGroupName - to filter resources by Resource Group.
  • -Tag - to filter resources based on tag.

For example:

# Export information from two resource groups within the current subscription context
Export-AzRuleData -ResourceGroupName 'rg-app1-web', 'rg-app1-db';

To export resource data for all subscription contexts use:

  • -All - to export resource data for all subscription contexts.

For example:

# Export data from all subscription contexts
Export-AzRuleData -All;

To filter results to only failed rules, use Invoke-PSRule -Outcome Fail. Passed, failed and error results are shown by default.

For example:

# Only show failed results
Invoke-PSRule -InputPath 'out/templates/' -Module 'PSRule.Rules.Azure' -Outcome Fail;

The output of this example is:

   TargetName: storage

RuleName                            Outcome    Recommendation
--------                            -------    --------------
Azure.Storage.UseReplication        Fail       Storage accounts not using GRS may be at risk
Azure.Storage.SecureTransferRequ... Fail       Storage accounts should only accept secure traffic
Azure.Storage.SoftDelete            Fail       Enable soft delete on Storage Accounts

A summary of results can be displayed by using Invoke-PSRule -As Summary.

For example:

# Display as summary results
Invoke-PSRule -InputPath 'out/templates/' -Module 'PSRule.Rules.Azure' -As Summary;

The output of this example is:

RuleName                            Pass  Fail  Outcome
--------                            ----  ----  -------
Azure.ACR.MinSku                    0     1     Fail
Azure.AppService.PlanInstanceCount  0     1     Fail
Azure.AppService.UseHTTPS           0     2     Fail
Azure.Resource.UseTags              73    36    Fail
Azure.SQL.ThreatDetection           0     1     Fail
Azure.SQL.Auditing                  0     1     Fail
Azure.Storage.UseReplication        1     7     Fail
Azure.Storage.SecureTransferRequ... 2     6     Fail
Azure.Storage.SoftDelete            0     8     Fail

Scenarios

For walk through examples of PSRule for Azure module usage see:

Rule reference

PSRule for Azure includes rules across five pillars of the Microsoft Azure Well-Architected Framework.

To view a list of rules by Azure resources see:

Baseline reference

The following baselines are included within PSRule.Rules.Azure.

Language reference

PSRule for Azure extends PowerShell with the following cmdlets.

Commands

PSRule for Azure included the following cmdlets:

Concepts

To find out more, look at these conceptual topics:

For a list of projects and integrations see Related projects.

Changes and versioning

This repository uses semantic versioning to declare breaking changes. For details please see the changes and versioning.

Contributing

This project welcomes contributions and suggestions. If you are ready to contribute, please visit the contribution guide.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Maintainers

License

This project is licensed under the MIT License.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.