azure-policy icon indicating copy to clipboard operation
azure-policy copied to clipboard

Issue: Unable to Audit ResourceType "Microsoft.Storage/storageAccounts/blobServices/containers"

Open mylameaccount opened this issue 7 years ago • 28 comments

I am trying to audit the Alias "Microsoft.Storage/storageAccounts/blobServices/containers/publicAccess" however I am finding no way to get to the resourceType "Microsoft.Storage/storageAccounts/blobServices/containers".

It seems that there are some missing relationships. This is what I am observing so far:

  • "Microsoft.Storage/storageAccounts/blobServices/containers" does not seem to exist as a standalone resourceType.

  • "Microsoft.Storage/storageAccounts" doesn't seem to have a related resourceType of "Microsoft.Storage/storageAccounts/blobServices/containers"

  • "Microsoft.Storage/storageAccounts/blobServices" doesn't seem to exists as a standalone resourceType.

  • "Microsoft.Storage/storageAccounts" doesn't seem to have a related resourceType of "Microsoft.Storage/storageAccounts/blobServices"

I would expect to have seen some sort of relationship between the resourceTypes. Is there a relationship between them?

  • "storageAccounts" <--> "blobServices"
  • "blobServices" <--> "containers"
  • "storageAccounts" <--> "containers"

This is an example of a policyRule I would like to be able to do but it does not work at this time. Please recommend the appropriate appoach to get to the alias "Microsoft.Storage/storageAccounts/blobServices/containers/publicAccess" for auditing:


    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Storage/storageAccounts/blobServices/containers/publicAccess",
                "equals": "Private"
              }
            ]
          }
        }
      }
    }

This is the resulting compliance details output from the rule above:


Reason for non-compliance
No related resources match the effect details in the policy definition.
EXISTENCE CONDITION
Type
Microsoft.Storage/storageAccounts/blobServices/containers


mylameaccount avatar May 02 '19 18:05 mylameaccount

If you try {scope}/providers/Microsoft.Storage/storageAccounts/{SA_name}/blobServices, this will fail with a "HttpResourceNotFound". This is because blobServices contains a singleton of name 'default'. {scope}/providers/Microsoft.Storage/storageAccounts/{SA_name}/blobServices/default will work and list this instance.

To list the containers, you can use {scope}/providers/Microsoft.Storage/storageAccounts/{SA_name}/blobServices/default/containers

As for the policy you are trying to write, there are a few issues which I will outline below. This policy is not possible today. 1. In the case of applying the policy when an applicable resource is changed: Whenever Microsoft.Storage/storageAccounts/blobServices/containers are created/updated, the policy will be evaluated. During evaluation we know the exact resource that is being changed and will evaluate against it. This should work just fine. However, it is possible to create containers via data plane operations. In this case, the policy will not be evaluated. This is a known gap which the storage team plans to address in the coming months.

If the container is created through the Azure Portal, it first tries to create it via the control plane. If this fails (which it will if your policy was a 'deny'), the portal tries to create the container via a data plane operation which will succeed.

2. In the case of compliance checks on existing resources in your environment: Let's say we have existing containers in your environment which are non-compliant with the policy. We scan subscriptions by listing all resource types in Microsoft.Storage namespace. Unfortunately, Microsoft.Storage does not list the Microsoft.Storage/storageAccounts/blobServices/containers resource type. Due to this, we don't know about it which is why you see "No related resources match the effect details in the policy definition."

For this policy to work, the following changes are needed:

  • Microsoft.Storage needs to support collection GET on _{scope}/providers/Microsoft.Storage/storageAccounts/{SA_name}/blobServices
  • Microsoft.Storage needs to list Microsoft.Storage/storageAccounts/blobServices/containers resource type.
  • Microsoft.Storage needs to support collection GET on Microsoft.Storage/storageAccounts/blobServices/containers. I believe this is possible today, but does not return all containers which is a problem.

rohit-bh avatar May 02 '19 20:05 rohit-bh

I appreciate the way you have outlined the reason why it doesn't work, however this is an Azure limiting use case for us.

stephenfrichardson avatar May 04 '19 12:05 stephenfrichardson

This is helpful information and I also appreciate how you outlined the reasons why it doesn't work. It appears that all of the following do not work as well:

  • Microsoft.Storage/storageAccounts/blobServices/containers
  • Microsoft.Storage/storageAccounts/blobServices
  • Microsoft.Storage/storageAccounts/queueServices
  • Microsoft.Storage/storageAccounts/fileServices
  • Microsoft.Storage/storageAccounts/tableServices

It may be on creation that some of these will audit however that disappear on their own eventually and are never seen again as you pointed out will happen. I tried some tests with Deny however as you said this won't work if provisioned via the portal but it didn't deny no matter how I triggered the creation. Portal, Powershell, Rest, template. Its possible I did something wrong there but it appears not to have worked.

The most frustrating part of this at this time is that there are so many aliases that don't seem to work for one reason or another throughout Azure Policy. I appreciate aliases being created however creating and testing of some of these policies takes a lot of time. If they don't work the assumption is that its on the policy definition authors side. To find out these are issues with Azure Policy is frustrating.

Each Alias published MUST be working and return useful data. This should be required for publishing. I found one alias that returns an object that is unusable in Azure Policy. We are wasting time with non-functioning aliases trying to get them working and no knowing they are broken.

Storage Aliases must work! There are storage settings that we need to audit for. Storage Accounts are a huge risk for us all.

I have clients that are talking about creating home grown auditing rules engines and leaving Azure Policy out of the picture. Please fix this as having a consistent tool for helping with governance across all clients is important to me and others.

mylameaccount avatar May 08 '19 23:05 mylameaccount

PG Team, is there a ETA for this? If not for the feature please remove the non-working alias which saves a lot of time for everyone who are trying to consume

ashimabdul avatar May 13 '19 09:05 ashimabdul

Storage team will provide an update this week.

mentat9 avatar May 13 '19 19:05 mentat9

The Azure Policy works on container to deny changes on public access. You can see the following sample. However, we don't recommend you to use it for now as it only governs for changes with ARM operations. When customers change it with Storage SDKs (data plane), Azure Policy can't detect. It's known gap that Storage team is actively working with Azure Policy team to address. We don't have ETA yet.

The good news is that Storage is developing an new account property to prevent container public access. And you can use Azure Policy to enforce it just like other properties in storage account. The ETA is Q3 CY19.

Azure Policy team will remove the policy alias on container to avoid confusion soon. @LizMS can provide ETA.

Sample governance policy for container public access (Working in management plane but not recommended): {   "if": {     "allOf": [       {         "field": "type",         "equals": "Microsoft.Storage/storageAccounts/blobServices/containers"       },       {         "not": {           "field":"Microsoft.Storage/storageAccounts/blobServices/containers/publicAccess",           "equals": "None"         }       }     ]   },   "then": {     "effect": "deny"   } }

fhryo-msft avatar May 14 '19 01:05 fhryo-msft

All aliases for this resource type have been removed. Details on this and a few other problematic resource types are documented in a new Known Issues section of the readme: https://github.com/Azure/azure-policy#known-issues.

mentat9 avatar Jun 04 '19 02:06 mentat9

The good news is that Storage is developing an new account property to prevent container public access. And you can use Azure Policy to enforce it just like other properties in storage account. The ETA is Q3 CY19.

@LizMs, @mentat9 - Any updates on this one? Thanks

pbillany avatar Aug 13 '19 14:08 pbillany

Last I heard it is expected to be available around the end of September. @fhryo-msft, is that still looking like a good ETA?

mentat9 avatar Aug 13 '19 17:08 mentat9

Yes, the ETA stays unchanged.

fhryo-msft avatar Aug 13 '19 18:08 fhryo-msft

Okay - thanks for the prompt update!

pbillany avatar Aug 14 '19 08:08 pbillany

Hi, has this property been released yet? Thanks.

pbillany avatar Sep 26 '19 12:09 pbillany

Unfortunately, the property will be shipped later than this month. We will look for latest estimate and update.

fhryo-msft avatar Sep 27 '19 06:09 fhryo-msft

Hi, is there an updated estimate for this?

jhawrysz avatar Nov 05 '19 20:11 jhawrysz

Hi, is there an updated estimate for this?

Any chance to solve this problem ?

The following solutions are not working ...

Microsoft.Storage/storageAccounts/blobServices/containers.publicAccess Microsoft.Storage/storageAccounts/blobServices/containers/publicAccess

Benoit-Gaumard avatar Nov 14 '19 13:11 Benoit-Gaumard

Please not use container public access alias in the policy. It's not working as expected.

The new estimate is Jun 2020 to ship new storage account property for public access enforcement.

fhryo-msft avatar Nov 14 '19 19:11 fhryo-msft

June 2020 ? Thank you.

Benoit-Gaumard avatar Nov 14 '19 20:11 Benoit-Gaumard

Dang... June?

JoelCBennett avatar Feb 14 '20 00:02 JoelCBennett

Yes. It is already June and is not working.

fzavalloni avatar Jun 05 '20 13:06 fzavalloni

Dear Microsoft, did you mean June 2021 or is this never going to happen? I see total lack of process or commitment to customer. Will this happen in near future or should we just stop following this thread with 0 hope?

ashimabdul avatar Jun 05 '20 15:06 ashimabdul