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

SONARIAC-1892 Modify rule S6975: Fix how to fix it section split #4604

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/header_names/allowed_framework_names.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
* CryptoSwift
* IDZSwiftCommonCrypto
// Azure resource manager
* ARM templates
* JSON templates
* Bicep
// PL/SQL
* DBMS_CRYPTO
Expand Down
2 changes: 1 addition & 1 deletion rules/S117/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include::../why-is-this-an-issue.adoc[]

include::../what-is-the-potential-impact.adoc[]

== How to fix it in ARM templates
== How to fix it in JSON templates

include::../how-to-fix-it-description.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion rules/S1192/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include::../description.adoc[]

include::exceptions-arm.adoc[]

== How to fix it in ARM templates
== How to fix it in JSON templates

include::howtofix-arm.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion rules/S1481/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include::../rationale.adoc[]

== How to fix it in ARM Templates
== How to fix it in JSON templates

The fix for this issue is straightforward.
Once you ensure the unused variable is not part of an incomplete implementation leading to bugs, you just need to remove it.
Expand Down
37 changes: 37 additions & 0 deletions rules/S6321/azureresourcemanager/how-to-fix-it/bicep.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
== How to fix it in Bicep

include::../../common/how-to-fix-it/intro.adoc[]

=== Code examples

==== Noncompliant code example

[source,bicep,diff-id=2,diff-type=noncompliant]
----
resource securityRules 'Microsoft.Network/networkSecurityGroups/securityRules@2022-11-01' = {
name: 'securityRules'
properties: {
direction: 'Inbound'
access: 'Allow'
protocol: '*'
destinationPortRange: '*'
sourceAddressPrefix: '*'
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding Noncompliant comment.
See: https://github.com/SonarSource/rspec/blob/444c23805989cba3ebdd79d578388f8f6626f596/docs/description.adoc

noncompliant lines should always be highlighted with the corresponding comment “// Noncompliant” optionally followed by some explanation) if that is clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's kinda hard to add Noncompliant comments to both code examples you mentioned because it's actually a combination of multiple lines that makes it non-compliant. I'll look into it, see what's possible and how we're dealing with similar situations to be consistent 😉

}
}
----

==== Compliant solution

[source,bicep,diff-id=2,diff-type=compliant]
----
resource securityRules 'Microsoft.Network/networkSecurityGroups/securityRules@2022-11-01' = {
name: 'securityRules'
properties: {
direction: 'Inbound'
access: 'Allow'
protocol: '*'
destinationPortRange: '22'
sourceAddressPrefix: '10.0.0.0/24'
}
}
----
53 changes: 53 additions & 0 deletions rules/S6321/azureresourcemanager/how-to-fix-it/json.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
== How to fix it in JSON templates

include::../../common/how-to-fix-it/intro.adoc[]

=== Code examples

==== Noncompliant 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": [
{
"name": "networkSecurityGroups/example",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2022-11-01",
"properties": {
"protocol": "*",
"destinationPortRange": "*",
"sourceAddressPrefix": "*",
"access": "Allow",
"direction": "Inbound"
}
}
]
}
----

==== 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": [
{
"name": "networkSecurityGroups/example",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2022-11-01",
"properties": {
"protocol": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "10.0.0.0/24",
"access": "Allow",
"direction": "Inbound"
}
}
]
}
----
82 changes: 2 additions & 80 deletions rules/S6321/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,9 @@ Any firewall rule allowing traffic from all IP addresses to standard network por

include::../impact.adoc[]

== How to fix it
include::how-to-fix-it/json.adoc[]

include::../common/how-to-fix-it/intro.adoc[]

=== Code examples

==== Noncompliant 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": [
{
"name": "networkSecurityGroups/example",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2022-11-01",
"properties": {
"protocol": "*",
"destinationPortRange": "*",
"sourceAddressPrefix": "*",
"access": "Allow",
"direction": "Inbound"
}
}
]
}
----

[source,bicep,diff-id=2,diff-type=noncompliant]
----
resource securityRules 'Microsoft.Network/networkSecurityGroups/securityRules@2022-11-01' = {
name: 'securityRules'
properties: {
direction: 'Inbound'
access: 'Allow'
protocol: '*'
destinationPortRange: '*'
sourceAddressPrefix: '*'
}
}
----

==== 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": [
{
"name": "networkSecurityGroups/example",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2022-11-01",
"properties": {
"protocol": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "10.0.0.0/24",
"access": "Allow",
"direction": "Inbound"
}
}
]
}
----

[source,bicep,diff-id=2,diff-type=compliant]
----
resource securityRules 'Microsoft.Network/networkSecurityGroups/securityRules@2022-11-01' = {
name: 'securityRules'
properties: {
direction: 'Inbound'
access: 'Allow'
protocol: '*'
destinationPortRange: '22'
sourceAddressPrefix: '10.0.0.0/24'
}
}
----
include::how-to-fix-it/bicep.adoc[]

== Resources

Expand Down
4 changes: 2 additions & 2 deletions rules/S6378/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include::../recommended.adoc[]

== Sensitive Code Example

Using ARM templates:
Using JSON templates:

[source,json,diff-id=1,diff-type=noncompliant]
----
Expand Down Expand Up @@ -35,7 +35,7 @@ resource sensitiveApiManagementService 'Microsoft.ApiManagement/service@2022-09-

== Compliant Solution

Using ARM templates:
Using JSON templates:

[source,json,diff-id=1,diff-type=compliant]
----
Expand Down
51 changes: 51 additions & 0 deletions rules/S6385/azureresourcemanager/how-to-fix-it/bicep.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
== How to fix it in Bicep

include::../../common/fix/rationale.adoc[]

=== Code examples

==== Noncompliant code example

[source,bicep,diff-id=2,diff-type=noncompliant]
----
targetScope = 'managementGroup'

resource roleDef 'Microsoft.Authorization/roleDefinitions@2022-04-01' = { // Sensitive
properties: {
permissions: [
{
actions: ['*']
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding Noncompliant comment

notActions: []
}
]

assignableScopes: [
managementGroup().id
]
}
}
----

==== Compliant solution

[source,bicep,diff-id=2,diff-type=compliant]
----
targetScope = 'managementGroup'

resource roleDef 'Microsoft.Authorization/roleDefinitions@2022-04-01' = {
properties: {
permissions: [
{
actions: ['Microsoft.Compute/*']
notActions: []
}
]

assignableScopes: [
managementGroup().id
]
}
}
----

include::../../common/fix/extra-mile.adoc[]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
== How to fix it
== How to fix it in JSON templates

include::../common/fix/rationale.adoc[]
include::../../common/fix/rationale.adoc[]

=== Code examples

Expand Down Expand Up @@ -32,26 +32,6 @@ include::../common/fix/rationale.adoc[]
}
----

[source,bicep,diff-id=2,diff-type=noncompliant]
----
targetScope = 'managementGroup'

resource roleDef 'Microsoft.Authorization/roleDefinitions@2022-04-01' = { // Sensitive
properties: {
permissions: [
{
actions: ['*']
notActions: []
}
]

assignableScopes: [
managementGroup().id
]
}
}
----

==== Compliant solution

[source,json,diff-id=1,diff-type=compliant]
Expand Down Expand Up @@ -80,22 +60,4 @@ resource roleDef 'Microsoft.Authorization/roleDefinitions@2022-04-01' = { // Sen
}
----

[source,bicep,diff-id=2,diff-type=compliant]
----
targetScope = 'managementGroup'

resource roleDef 'Microsoft.Authorization/roleDefinitions@2022-04-01' = {
properties: {
permissions: [
{
actions: ['Microsoft.Compute/*']
notActions: []
}
]

assignableScopes: [
managementGroup().id
]
}
}
----
include::../../common/fix/extra-mile.adoc[]
4 changes: 2 additions & 2 deletions rules/S6385/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ include::../common/description.adoc[]

include::../common/impact/description.adoc[]

include::how_to_fix_it.adoc[]
include::how-to-fix-it/json.adoc[]

include::../common/fix/extra-mile.adoc[]
include::how-to-fix-it/bicep.adoc[]

include::../see.adoc[]

Expand Down
2 changes: 1 addition & 1 deletion rules/S6437/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include::../../../shared_content/secrets/impact/financial_loss.adoc[]

include::../../../shared_content/secrets/impact/security_downgrade.adoc[]

== How to fix it in ARM Templates
== How to fix it in JSON templates

=== Code examples

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== How to fix it in ARM templates
== How to fix it in JSON templates

=== Code examples

Expand Down Expand Up @@ -31,4 +31,4 @@
}
}
}
----
----
2 changes: 1 addition & 1 deletion rules/S6648/azureresourcemanager/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Secure parameters can be assigned a default value which will be used if the para

If the default value contains a secret, it will be disclosed to all accounts that have read access to the deployment history.

include::how-to-fix-it/arm.adoc[]
include::how-to-fix-it/json.adoc[]

include::how-to-fix-it/bicep.adoc[]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== How to fix it in ARM Templates
== How to fix it in JSON templates

By setting `properties.expressionEvaluationOptions.scope` to `Inner` in the parent template, template evaluations are limited to the scope of the nested template. This makes it impossible to expose secure parameters defined in the parent template.

Expand Down
Loading
Loading