-
Notifications
You must be signed in to change notification settings - Fork 99
Added Azure.APIM.PolicyBase #2140
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
Merged
BernieWhite
merged 13 commits into
Azure:main
from
BenjaminEngeset:BenjaminEngeset/apim-policy-base
Apr 29, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c6f75f7
Added Azure.APIM.PolicyBase
b6feca5
Updated helper function
b50c107
Merge branch 'main' into BenjaminEngeset/apim-policy-base
ddbbba9
Added tests
d55c3df
Fix merge conflict
281ff42
Updated rule
b76be98
Added switch ignore global parameter
b6cfb7c
Fixes
BernieWhite c3cff11
Merge branch 'main' into BenjaminEngeset/apim-policy-base
BernieWhite 3b7f5f3
Added Azure.PolicyBase
c2fc517
Fixes
5fdd8f5
Update doc
019a0b4
Merge branch 'main' into BenjaminEngeset/apim-policy-base
BenjaminEngeset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| severity: Important | ||
| pillar: Security | ||
| category: Design | ||
| resource: API Management | ||
| online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.APIM.PolicyBase/ | ||
| --- | ||
|
|
||
| # Base element | ||
|
|
||
| ## SYNOPSIS | ||
|
|
||
| Base element for any policy element in a section should be configured. | ||
|
|
||
| ## DESCRIPTION | ||
|
|
||
| Determine the policy evaluation order by placement of the base (`<base />`) element in each section in the policy definition at each scope. | ||
|
|
||
| API Management supports the following scopes _Global_ (all API), _Workspace_, _Product_, _API_, or _Operation_. | ||
|
|
||
| The _base_ element inherits the policies configured in that section at the next broader (parent) scope. | ||
| Otherwise inherited security or other controls may not apply. | ||
| The _base_ element can be placed before or after any policy element in a section, depending on the wanted evaluation order. | ||
| However, if security controls are defined in inherited scopes it may decrease the effectiveness of these controls. | ||
| For most cases, unless otherwise specified in the policy reference (such as `cors`) the _base_ element should be specified as the first element in each section. | ||
|
|
||
| A specific exception is at the _Global_ scope. | ||
| The _Global_ scope does not need the _base_ element because this is the peak scope from which all others inherit. | ||
|
|
||
| ## RECOMMENDATION | ||
|
|
||
| Consider configuring the base element for any policy element in a section. | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| ### Configure with Azure template | ||
|
|
||
| To deploy API Management policies that pass this rule: | ||
|
|
||
| - Configure an policy sub-resource. | ||
| - Configure the base element before or after any policy element in a section in `properties.value` property. | ||
|
|
||
| For example an API policy: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "Microsoft.ApiManagement/service/apis/policies", | ||
| "apiVersion": "2021-08-01", | ||
| "name": "[format('{0}/{1}', parameters('name'), 'policy')]", | ||
| "properties": { | ||
| "value": "<policies><inbound><base /><ip-filter action=\"allow\"><address-range from=\"10.1.0.1\" to=\"10.1.0.255\" /></ip-filter></inbound><backend><base /></backend><outbound><base /></outbound><on-error><base /></on-error></policies>", | ||
| "format": "xml" | ||
| }, | ||
| "dependsOn": [ | ||
| "[resourceId('Microsoft.ApiManagement/service/apis', parameters('name'))]" | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| ### Configure with Bicep | ||
|
|
||
| To deploy API Management policies that pass this rule: | ||
|
|
||
| - Configure an policy sub-resource. | ||
| - Configure the base element before or after any policy element in a section in `properties.value` property. | ||
|
|
||
| For example an API policy: | ||
|
|
||
| ```bicep | ||
| resource apiName_policy 'Microsoft.ApiManagement/service/apis/policies@2021-08-01' = { | ||
| parent: api | ||
| name: 'policy' | ||
| properties: { | ||
| value: '<policies><inbound><base /><ip-filter action=\"allow\"><address-range from=\"10.1.0.1\" to=\"10.1.0.255\" /></ip-filter></inbound><backend><base /></backend><outbound><base /></outbound><on-error><base /></on-error></policies>' | ||
| format: 'xml' | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## NOTES | ||
|
|
||
| The rule only checks against `rawxml` and `xml` policy formatted content. Global policies are excluded since they don't benefit from the base element. | ||
|
|
||
| ## LINKS | ||
|
|
||
| - [Secure application configuration and dependencies](https://learn.microsoft.com/azure/well-architected/security/design-app-dependencies) | ||
| - [Things to know](https://learn.microsoft.com/azure/api-management/api-management-howto-policies#things-to-know) | ||
| - [Mitigate OWASP API threats](https://learn.microsoft.com/azure/api-management/mitigate-owasp-api-threats#recommendations-6) | ||
| - [Apply policies specified at different scopes](https://learn.microsoft.com/azure/api-management/api-management-howto-policies#apply-policies-specified-at-different-scopes) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service/apis/resolvers/policies) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service/products/policies) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service/apis/policies) | ||
| - [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service/apis/operations/policies) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.