Skip to content

Commit

Permalink
Create rule S6378: Add language AzureResourceManager (JSON) (#2237)
Browse files Browse the repository at this point in the history
[Specification
ticket](https://sonarsource.atlassian.net/browse/APPSEC-777)
[Implementation
ticket](https://sonarsource.atlassian.net/browse/SONARIAC-889)
[RSPEC
Preview](https://sonarsource.github.io/rspec/#/rspec/S6378/azureresourcemanager)

Bicep PR for S6378: #2255 

## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)

---------

Co-authored-by: egon-okerman-sonarsource <[email protected]>
Co-authored-by: Egon Okerman <[email protected]>
  • Loading branch information
3 people authored and guillaume-dequenne-sonarsource committed Jul 3, 2023
1 parent 151ed01 commit 8e180df
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 42 deletions.
8 changes: 8 additions & 0 deletions rules/S6378/ask-yourself.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
== Ask Yourself Whether

The resource:

* Needs to authenticate to Azure resources that support Azure Active Directory (AAD).
* Uses a different Access Control system that doesn't guarantee the same security controls as AAD, or no Access Control system at all.
There is a risk if you answered yes to all of those questions.
1 change: 1 addition & 0 deletions rules/S6378/azureresourcemanager/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
58 changes: 58 additions & 0 deletions rules/S6378/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
include::../description.adoc[]

include::../ask-yourself.adoc[]

include::../recommended.adoc[]

== Sensitive Code Example

[source,json,diff-id=1,diff-type=noncompliant]
----
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.ApiManagement/service",
"apiVersion": "2022-09-01-preview",
"name": "apiManagementService",
}
]
}
----


== Compliant Solution

[source,json,diff-id=1,diff-type=compliant]
----
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.ApiManagement/service",
"apiVersion": "2022-09-01-preview",
"name": "apiManagementService",
"identity": {
"type": "SystemAssigned"
}
}
]
}
----


include::../see.adoc[]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

include::../highlighting.adoc[]

endif::env-github,rspecator-view[]
7 changes: 7 additions & 0 deletions rules/S6378/description.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Disabling Managed Identities can reduce an organization's ability to protect itself against configuration faults and credentials leaks.

Authenticating via managed identities to an Azure resource solely relies on an API call with a non-secret token. The process is inner to Azure: secrets used by Azure are not even accessible to end-users.

In typical scenarios without managed identities, the use of credentials can lead to mistakenly leaving them in code bases. In addition, configuration faults may also happen when storing these values or assigning them permissions.

By transparently taking care of the Azure Active Directory authentication, Managed Identities allow getting rid of day-to-day credentials management.
7 changes: 7 additions & 0 deletions rules/S6378/highlighting.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== Highlighting

Highlight:

* The property that is wrong if it exists.
* The entire resource block if a property is missing.
3 changes: 3 additions & 0 deletions rules/S6378/message.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== Message

- Omitting the "identity" block disables Azure Managed Identities. Make sure it is safe here.
9 changes: 9 additions & 0 deletions rules/S6378/recommended.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
== Recommended Secure Coding Practices

Enable the Managed Identities capabilities of this Azure resource. If supported, use a System-Assigned managed identity, as:

* It cannot be shared across resources.
* Its life cycle is deeply tied to the life cycle of its Azure resource.
* It provides a unique independent identity.
Alternatively, User-Assigned Managed Identities can also be used but don't guarantee the properties listed above.
7 changes: 7 additions & 0 deletions rules/S6378/see.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
== See

* https://owasp.org/Top10/A05_2021-Security_Misconfiguration/[OWASP Top 10 2021 Category A05] - Security Misconfiguration
* https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[OWASP Top 10 2017 Category A06] - Security Misconfiguration
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview[Azure AD Documentation - Managed Identities Overview]
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/managed-identity-best-practice-recommendations[Azure AD Documentation - Managed Identities Best Practices]
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/services-support-managed-identities[Azure AD Documentation - Services that support managed identities]
49 changes: 7 additions & 42 deletions rules/S6378/terraform/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
Disabling Managed Identities can reduce an organization's ability to protect itself against configuration faults and credentials leaks.
include::../description.adoc[]

Authenticating via managed identities to an Azure resource solely relies on an API call with a non-secret token. The process is inner to Azure: secrets used by Azure are not even accessible to end-users.

In typical scenarios without managed identities, the use of credentials can lead to mistakenly leaving them in code bases. In addition, configuration faults may also happen when storing these values or assigning them permissions.

By transparently taking care of the Azure Active Directory authentication, Managed Identities allow getting rid of day-to-day credentials management.


== Ask Yourself Whether

The resource:

* Needs to authenticate to Azure resources that support Azure Active Directory (AAD).
* Uses a different Access Control system that doesn't guarantee the same security controls as AAD, or no Access Control system at all.

There is a risk if you answered yes to all of those questions.


== Recommended Secure Coding Practices

Enable the Managed Identities capabilities of this Azure resource. If supported, use a System-Assigned managed identity, as:

* It cannot be shared across resources.
* Its life cycle is deeply tied to the life cycle of its Azure resource.
* It provides a unique independent identity.

Alternatively, User-Assigned Managed Identities can also be used but don't guarantee the properties listed above.
include::../ask-yourself.adoc[]

include::../recommended.adoc[]

== Sensitive Code Example

Expand Down Expand Up @@ -74,32 +50,21 @@ resource "azurerm_data_factory_linked_service_kusto" "example" {
}
----

== See

* https://owasp.org/Top10/A05_2021-Security_Misconfiguration/[OWASP Top 10 2021 Category A05] - Security Misconfiguration
* https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[OWASP Top 10 2017 Category A06] - Security Misconfiguration
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview[Azure AD Documentation - Managed Identities Overview]
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/managed-identity-best-practice-recommendations[Azure AD Documentation - Managed Identities Best Practices]
* https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/services-support-managed-identities[Azure AD Documentation - Services that support managed identities]
include::../see.adoc[]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

- Omitting the "identity" block disables Azure Managed Identities. Make sure it is safe here.
include::../message.adoc[]

Only for Azure Data Factory
Only for Azure Data Factory:

- Make sure that disabling Azure Managed Identities is safe here.


=== Highlighting

Highlight the resource bloc.

include::../highlighting.adoc[]

endif::env-github,rspecator-view[]

0 comments on commit 8e180df

Please sign in to comment.