Recently I started building out some Azure infrastructure. Few months in I noticed a new Azure subscription that I didn't create. After some digging I found it was a "free trial" that one of the guys was using the learn on. GREAT, I absolutely loved every part of this... except that it was under the company Azure tenant.
I found more and more that when I looked at various blades I would see references to his resource groups, subscription, billing profile, etc. I didn't like seeing objects that didn't belong to the company. This is for a single "trial". Now imagine this as we grow and more users do "free trials".
I started looking at options to block new subscriptions by end users and was surprised to find that you couldn't directly! I found plenty of references to "just use RBAC" or "users can't, must be owner", etc. After more digging, I found that this is partially true, but doesn't cover "Pay as you go", "Azure for students", "Free Trial" options.
These 3 options cannot currently be blocked!
But just because you can't block a subscription from being made, doesn't mean you can't control the resources created under it, or rather block them.
That is where Daraw Techie comes in! Allow the subscription (because you have to), but block what can be done with it.
Azure Policy to Deny Creation of All Resources – DaRaw Techie
This guy did a great job of coming up with a solution and documenting it. My goal here is to run through the steps briefly, and provide some copy / paste options ;)
- Go to Management Groups in Azure
- Create a new Management Group under the "Tenant Root Group"
- I called mine "Non-Company Resources"
- Click on Settings
- Change the default manage group for subscriptions to "Non-CompanyResources"
- Turn on "require write permissions for creating new management groups"
- Click back to "overview"
- Under the Tenant Root Group (click on it under Management Groups"
- Expand Governance and click on Policy
- Expand Authoring and click on Definitions
- Search for "Not allowed"
- Duplicate the definition
- Change the definition location to your new Management Group
- Change name to "Deny all resources"
- Remove all in the Policy Rule and paste in the following to the Policy Rule
{ "mode": "All", "policyRule": { "if": { "field": "type", "like": "Microsoft.*" }, "then": { "effect": "deny" } }, "parameters": {} }
- Create
- Now, go back to your Management Groups, and click into the New management Group.
- Expand Governance -> Policy
- you'll land on the Compliance tab
- Assign Policy
- Make sure scope is set to the "Non-CompanyResources". It should default here if you selected it in the Management Group.
- For the Policy Definition, search for "Deny All" and select your new definition.
- Add
- Review and Create, then Create
- After a minute and a refresh you should see it assigned.
- Now we can move subscriptions to the new Management Group
- Testing - Logged into the account with the Subscription I moved I tried to create a new Resource Group