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

Storage Account: Enable DefaultAction in Network rules. #3255

Merged
merged 8 commits into from Jun 26, 2019

Conversation

thatInfrastructureGuy
Copy link
Contributor

@thatInfrastructureGuy thatInfrastructureGuy commented Apr 16, 2019

Introduction: DefaultAction is the toggle which enables/disables network rules in azure storage account.
Setting it to Deny enables storage account firewall settings and Allow disables the firewalls.

Problem: When using azure storage account as module with network_rules block, there is no good way to disable network security apart from removing the network_rules block entirely from the root module.

PR objective: This PR aims to solve this problem by implementing DefaultAction variable.

Storage Account - Module with network_rules block:

 network_rules {
    default_action             = "${var.default_action}"
    virtual_network_subnet_ids = ["${var.virtual_network_subnet_ids}"]
    bypass                     = ["${var.bypass}"]
    ip_rules                   = ["${var.ip_rules}"]
  }

Storage Account - Deployment 1 with no firewall:

 network_rules {
    default_action             = "Allow"
    virtual_network_subnet_ids = ""
    bypass                     = ""
    ip_rules                   = ""
  }

Storage Account - Deployment 2 with firewall:

 network_rules {
    default_action             = "Deny"
    virtual_network_subnet_ids = "${azurerm_subnet.test.id"
    bypass                     = ["Logging", "Metrics"]
    ip_rules                   = ["127.0.0.1", "127.0.0.2"]
  }

Signed-off-by: ecp <thatInfrastructureGuy@gmail.com>
Signed-off-by: ecp <thatInfrastructureGuy@gmail.com>
Signed-off-by: ecp <thatInfrastructureGuy@gmail.com>
Copy link
Member

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @thatInfrastructureGuy

Thanks for this PR :)

I've taken a look through and left some comments inline but this is off to a good start - if we can fix up the comments we should be able to run the tests and get this merged 👍

Thanks!

azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
Removed default value. Made value case sensitive.

Signed-off-by: ecp <thatInfrastructureGuy@gmail.com>
@thatInfrastructureGuy
Copy link
Contributor Author

@tombuildsstuff Thanks for quick review. :) I have made the requested changes. I do agree default_action should be required field and having to let users decide on the value of it.

@ghost ghost removed the waiting-response label Apr 16, 2019
@thatInfrastructureGuy
Copy link
Contributor Author

        FAIL: TestAccAzureRMStorageAccount_networkRulesDeleted (150.14s)
    testing.go:538: Step 1 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: azurerm_storage_account.testsa
          network_rules.#:                                       "1" => "0"
          network_rules.0.default_action:                        "Allow" => ""
          network_rules.0.ip_rules.#:                            "1" => "0"
          network_rules.0.ip_rules.3619153832:                   "127.0.0.1" => ""
          network_rules.0.virtual_network_subnet_ids.#:          "1" => "0"
          network_rules.0.virtual_network_subnet_ids.1226267014: "/subscriptions/xxx/r
esourceGroups/acctestAzureRMSA-190416064647690939/providers/Microsoft.Network/virtualNetworks/acctestvirtnet19041606464
7690939/subnets/acctestsubnet190416064647690939" => ""
                                                                                                      
        STATE:

        azurerm_resource_group.testrg:
          network_rules.# = 1
          network_rules.0.bypass.# = 1
          network_rules.0.bypass.625562768 = AzureServices
          network_rules.0.default_action = Allow
          network_rules.0.ip_rules.# = 1
          network_rules.0.ip_rules.3619153832 = 127.0.0.1
          network_rules.0.virtual_network_subnet_ids.# = 1
          network_rules.0.virtual_network_subnet_ids.1226267014 = /subscriptions/xxx/r
esourceGroups/acctestAzureRMSA-190416064647690939/providers/Microsoft.Network/virtualNetworks/acctestvirtnet19041606464
7690939/subnets/acctestsubnet190416064647690939

I believe this happens because the rules itself are not deleted. Only the flag "defaultAction": "Allow" is set on the backend.

@tombuildsstuff
Copy link
Member

@thatInfrastructureGuy

I believe this happens because the rules itself are not deleted. Only the flag "defaultAction": "Allow" is set on the backend.

Indeed - because the NetworkRuleSet created when Allow is set doesn't contain any IP Rules/Virtual Network Rules, these aren't being overridden. If an empty list is specified for those then this should pass 👍

@thatInfrastructureGuy
Copy link
Contributor Author

@tombuildsstuff Thanks for the pointer. However, I am not able to override those IP Rules/Virtual Network Rules even after specifying empty list. I tried the below snippet:

return &storage.NetworkRuleSet{
			DefaultAction:       storage.DefaultActionAllow,
			Bypass:              storage.Bypass(""),
			IPRules:             &[]storage.IPRule{},
			VirtualNetworkRules: &[]storage.VirtualNetworkRule{},
		}

I dont know what I am missing. Can you please guide me here?

@ghost ghost removed the waiting-response label Apr 21, 2019
@katbyte katbyte modified the milestones: v1.27.0, v1.28.0 Apr 25, 2019
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Hi @thatInfrastructureGuy,

Thank you for the PR, this LGTM, however i am curious as to why you explicitly don't send the network rules when it is allow. Will the API not be happy?

azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
@ashishkulk
Copy link

Added response in the comments.

Add test when reverting default action from allow to deny.

Signed-off-by: Ashish <thatInfrastructureGuy@gmail.com>
azurerm/resource_arm_storage_account.go Outdated Show resolved Hide resolved
@katbyte
Copy link
Collaborator

katbyte commented May 16, 2019

@thatInfrastructureGuy,

See my comment left inline. I am still wondering why you are conditionally setting the properties on create/update. Does the API throw an error if you set them?

@katbyte katbyte modified the milestones: v1.28.0, v1.29.0 May 16, 2019
@katbyte
Copy link
Collaborator

katbyte commented May 19, 2019

👋 @thatInfrastructureGuy,

I hope you don't mind but i've pushed a commit demonstrating what I was referring to. I also changed the property to optional as a new required property in an existing block could potentially break peoples configuration.

@katbyte katbyte modified the milestones: v1.29.0, v1.30.0 May 25, 2019
@thatInfrastructureGuy
Copy link
Contributor Author

@katbyte Sorry for late response. I was on vacation for a bit and never really got back to this PR. Thanks so much for review and the commit. I am totally good with it.

@ghost ghost removed the waiting-response label Jun 4, 2019
@katbyte katbyte modified the milestones: v1.30.0, v1.31.0 Jun 7, 2019
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

LGTM now 👍

katbyte added a commit that referenced this pull request Jun 26, 2019
@katbyte katbyte merged commit c470857 into hashicorp:master Jun 26, 2019
@thatInfrastructureGuy thatInfrastructureGuy deleted the storageaccount/vnet branch June 26, 2019 20:52
@ghost
Copy link

ghost commented Jul 27, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants