Code Monkey home page Code Monkey logo

globalbao / azure-policy-as-code Goto Github PK

View Code? Open in Web Editor NEW
170.0 19.0 81.0 1.64 MB

Bicep and Terraform code examples for policy-as-code workflows. Azure governance guardrails and automation - by @JesseLoudon

Home Page: https://globalbao.github.io/azure-policy-as-code

License: MIT License

Bicep 31.96% HCL 66.55% PowerShell 1.49%
azure-policy policy-as-code bicep cicd terraform azurerm armtemplates azurepolicy azuredevops terraform-azurerm

azure-policy-as-code's People

Contributors

jesseloudon avatar jloudonunswc avatar rodmhgl avatar rogerm-chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-policy-as-code's Issues

Deprecated Resource: azurerm_policy_assignment

azurerm_policy_assignment is being deprecated and needs to be replaced by new AzureRM resources

Warning: Deprecated Resource

  on modules/policy-assignments/main.tf line 1, in resource "azurerm_policy_assignment" "monitoring_governance":
   1: resource "azurerm_policy_assignment" "monitoring_governance" {

The `azurerm_policy_assignment` resource is deprecated in favour of the:

- `azurerm_management_group_policy_assignment`
- `azurerm_resource_policy_assignment`
- `azurerm_resource_group_policy_assignment`
- `azurerm_subscription_policy_assignment`

resources and will be removed in version 3.0 of the Azure Provider.

(and 5 more similar warnings elsewhere)

BUG: Bicep-CD-Tests MG failure

Describe the bug

ERROR: "status":"Failed","error":"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":["code":"Conflict","message":"\r\n "status": "Failed",\r\n "error": ***\r\n "code": "ResourceDeploymentFailure",\r\n "message": "The resource operation completed with terminal provisioning state 'Failed'.",\r\n "details": [\r\n ***\r\n "code": "DeploymentFailed",\r\n "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",\r\n "details": [\r\n \r\n "code": "Conflict",\r\n "message": "\r\n \"status\": \"Failed\",\r\n \"error\": ***\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n \"details\": [\r\n ***\r\n \"code\": \"DeploymentFailed\",\r\n \"message\": \"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.\",\r\n \"details\": [\r\n \r\n \"code\": \"BadRequest\",\r\n \"message\": \"\\r\\n \\\"error\\\": ***\\r\\n \\\"code\\\": \\\"InvalidCreatePolicySetDefinitionRequest\\\",\\r\\n \\\"message\\\": \\\"The policy set definition 'tagging_initiative' request is invalid. Referenced policy definitions must be of type 'Microsoft.Authorization/policyDefinitions'.\\\"\\r\\n \\r\\n\"\r\n ***\r\n ]\r\n ***\r\n ]\r\n \r\n"\r\n ***,\r\n \r\n "code": "Conflict",\r\n "message": "\r\n \"status\": \"Failed\",\r\n \"error\": ***\r\n \"code\": \"ResourceDeploymentFailure\",\r\n \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n \"details\": [\r\n ***\r\n \"code\": \"DeploymentFailed\",\r\n \"message\": \"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.\",\r\n \"details\": [\r\n \r\n \"code\": \"BadRequest\",\r\n \"message\": \"\\r\\n \\\"error\\\": ***\\r\\n \\\"code\\\": \\\"InvalidCreatePolicySetDefinitionRequest\\\",\\r\\n \\\"message\\\": \\\"The policy set definition 'iam_initiative' request is invalid. Referenced policy definitions must be of type 'Microsoft.Authorization/policyDefinitions'.\\\"\\r\\n \\r\\n\"\r\n ***\r\n ]\r\n ***\r\n ]\r\n \r\n"\r\n \r\n ]\r\n \r\n ]\r\n \r\n"]

To Reproduce
Steps to reproduce the behavior:
Run Bicep-CD-Tests on MG deployment step

Community contribution guide for custom policies

Is your feature request related to a problem? Please describe.
Community members may like to contribute a custom policy to this repo but don't know how.

Describe the solution you'd like
Add a community contribution guide with steps defining:

  • Branch process
  • Language selection
  • Folder selection
  • Custom Policy creation
  • Custom Policy testing
  • Language Linting/Validation checks
  • PR process

BUG: could not find policy 'Audit usage of custom RBAC rules'

Describe the bug
Terraform plan fails when run with the default configuration:

Error: reading Policy Definition (Display Name "Audit usage of custom RBAC rules"): loading Policy
Definition List: could not find policy 'Audit usage of custom RBAC rules' with
module.policyset_definitions.data.azurerm_policy_definition.builtin_policies_iam_governance[0], on
modules/policyset-definitions/variables.tf line 100, in data "azurerm_policy_definition"
"builtin_policies_iam_governance": 100: data "azurerm_policy_definition" "builtin_policies_iam_governance {

To Reproduce
Steps to reproduce the behavior:

  1. Clone Repo
  2. Configure Backend
  3. Run terraform plan
  4. See error

Expected behavior
terraform plan would complete and display the plan as usual.

Additional context
It appears the policy has been renamed to "Audit usage of custom RBAC roles"

How to add an object inside policySetDefinitions parameters

Is your feature request related to a problem? Please describe.
Let's assume a policy have more than one parameter. We want to be able to set those parameters when deploying the policy (in Bicep). Is it possible to have all the parameters of a policy in one object defined in the parameters property of policySetDefinitions? If it's possible, how do we later set this object parameter in policyDefinitions?

Example:
This policy definition seems to have more than one parameter:
https://github.com/globalbao/azure-policy-as-code/blob/main/Bicep/demos/security-governance/deploy-sub-dev.bicep#L75

Currently, the parameters are hard-coded. How can we set those parameters when deploying (for example using parameters files). Please note that there might be several policies with parameters which have similar name. "Effect" is a common parameter name. That is the reason, I am looking for an object per policy.

2x deprecated policies

Describe the errors

Error: reading Policy Definition (Display Name "RDP access from the Internet should be blocked"): loading Policy Definition List: could not find policy 'RDP access from the Internet should be blocked'

with module.policyset_definitions.data.azurerm_policy_definition.builtin_policies_security_governance[6],
on modules/policyset-definitions/variables.tf line 109, in data "azurerm_policy_definition" "builtin_policies_security_governance":
109: data "azurerm_policy_definition" "builtin_policies_security_governance" {

Error: reading Policy Definition (Display Name "SSH access from the Internet should be blocked"): loading Policy Definition List: could not find policy 'SSH access from the Internet should be blocked'

with module.policyset_definitions.data.azurerm_policy_definition.builtin_policies_security_governance[7],
on modules/policyset-definitions/variables.tf line 109, in data "azurerm_policy_definition" "builtin_policies_security_governance":
109: data "azurerm_policy_definition" "builtin_policies_security_governance" {

Bicep CD job - AzureCLI SP failure

Describe the bug
GitHub Action azure/CLI@v1 fails with

ERROR: Could not retrieve credential from local cache for service principal xyz. Run az login for this service principal.

Issue tracking: Azure/login#162

Workaround:
Change azcliversion in azure/CLI@v1 to 2.29.2 which is compatible with azure/login@v1:

- name: Azure CLI script
  uses: azure/CLI@v1
  with:
    azcliversion: 2.29.2

Add SPN creation steps for Bicep usage to readme

Is your feature request related to a problem? Please describe.
Bicep users may like some guidance on creating and using an SPN for managing policy as code workflows

Describe the solution you'd like
SPN creation steps should cover:

  • Azure CLI e.g. az ad sp create-for-rbac
  • Suitable built-in RBAC roles
  • Onboarding credentials to GitHub secrets for use with GitHub Actions

Bicep CI validation step failure

Describe the bug

Bicep CI validation step failure for PR #9

To Reproduce

Run Bicep CI on a PR

Expected behavior

Bicep CI is successful on PR

Logs

https://github.com/globalbao/azure-policy-as-code/actions/runs/1369747466

You are not currently on a branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

fatal: Invalid symmetric difference expression main...901b6845f8521b31aaea46bf06723925c6461dae
2021-10-21 22:27:39 [WARN]   No files were found in the GITHUB_WORKSPACE:[/github/workspace] to lint!
2021-10-21 22:27:39 [ERROR]   Failed to switch back to branch!
2021-10-21 22:27:39 [FATAL]   [fatal: reference is not a tree: 901b6845f8521b31aaea46bf06723925c6461dae]

Add Decorators to Bicep parameters

Bicep parameters are used extensively throughout Subscription/Management Group modules

Need to add Decorators where appropriate to assist usage and provide further context for module users

For example:

  • Secure parameters
  • Allowed values
  • Length constraints
  • Integer constraints
  • Description

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.