Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add policy pack - Check Azure VNets have flow log enabled. Closes #893 #894

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vkumbha
Copy link
Contributor

@vkumbha vkumbha commented Dec 23, 2024

Policy Pack

image

Flow Log is not configured

image

Flow Log is configured but not enabled

image

Flow Log is configured but the resource is not found in CMDB to determine if it is enabled/disabled

image

Flow Log is configured and enabled

image

@vkumbha vkumbha self-assigned this Dec 23, 2024
resource "turbot_policy_setting" "azure_network_virtual_network_approved" {
resource = turbot_policy_pack.main.id
type = "tmod:@turbot/azure-network#/policy/types/virtualNetworkApproved"
value = "Check: Approved"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only want to add the Check option?
In general, we include the Enforce option as well if the policy supports it.

Copy link
Contributor Author

@vkumbha vkumbha Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SumitPopat I believe that if a Virtual Network does not have Flow Logs enabled, the goal should be to enforce the creation of Flow Logs rather than deleting the VNet. However, since the Azure Flow Log stack (similar to the AWS > VPC > VPC > Flow Logging) is not currently available, we decided to proceed with a Check mode approach in this case.

resource "turbot_policy_pack" "main" {
title = "Check Azure Virtual Networks Have Flow Logs Enabled"
description = "Ensure that logging is enabled for Azure Virtual Networks to monitor traffic and maintain security compliance."
akas = ["azure_network_check_virtual_networks_have_flowlog_enabled"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the aka would be azure_network_enforce_virtual_networks_have_flowlog_enabled if we include the Enforce option too?

Comment on lines +23 to +38
name:get(path:"name")
flowLogs:get(path:"flowLogs")
}
}
- |
{
resource {
name:get(path:"name")
flowLogs:get(path:"flowLogs")
}
resources(filter:"resourceTypeId:tmod:@turbot/azure-networkwatcher#/resource/types/flowLog $.id:'{{ $.resource.flowLogs[0].id }}'"){
items {
enabled:get(path:"enabled")
id:get(path:"id")
name:get(path:"name")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name:get(path:"name")
flowLogs:get(path:"flowLogs")
}
}
- |
{
resource {
name:get(path:"name")
flowLogs:get(path:"flowLogs")
}
resources(filter:"resourceTypeId:tmod:@turbot/azure-networkwatcher#/resource/types/flowLog $.id:'{{ $.resource.flowLogs[0].id }}'"){
items {
enabled:get(path:"enabled")
id:get(path:"id")
name:get(path:"name")
}
name: get(path:"name")
flowLogs: get(path:"flowLogs")
}
}
- |
{
resource {
name: get(path:"name")
flowLogs: get(path:"flowLogs")
}
resources(filter:"resourceTypeId:tmod:@turbot/azure-networkwatcher#/resource/types/flowLog $.id:'{{ $.resource.flowLogs[0].id }}' resourceTypeLevel:self"){
items {
enabled:get(path:"enabled")
id:get(path:"id")
name:get(path:"name")
}

{%- set matchedFlowLog = subscriptionFlowLog %}
{%- endif %}
{%- endfor %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the existing format for setting approved > custom policies. For reference please check: https://github.com/turbot/guardrails-samples/blob/main/policy_packs/aws/ec2/enforce_instances_use_amis_with_approved_tags/policies.tf#L13

Comment on lines +11 to +14
This [policy pack](https://turbot.com/guardrails/docs/concepts/policy-packs) can help you configure the following settings for network security groups:

- Check if flow logs are configured for Azure Virtual Networks
- Validate that flow logging status is enabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This [policy pack](https://turbot.com/guardrails/docs/concepts/policy-packs) can help you configure the following settings for network security groups:
- Check if flow logs are configured for Azure Virtual Networks
- Validate that flow logging status is enabled
This [policy pack](https://turbot.com/guardrails/docs/concepts/policy-packs) can help you configure the following settings for virtual networks:
- Check if flow logs are configured and enabled
- Delete unapproved virtual networks if flow logging is not enabled


If this policy pack is attached to a Guardrails folder, its policies will be applied to all accounts and resources in that folder. The policy pack can also be attached to multiple resources.

For more information, please see [Policy Packs](https://turbot.com/guardrails/docs/concepts/policy-packs).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the Enable Enforcement block if the Enforce option is added to the Policy Pack.

@vkumbha vkumbha requested a review from SumitPopat February 19, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants