2021-09-15 08:10:36 +00:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2022-02-07 11:08:29 +01:00
|
|
|
An ingress rule allowing all inbound SSH traffic for AWS:
|
2021-09-15 08:10:36 +00:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,terraform]
|
2021-09-15 08:10:36 +00:00
|
|
|
----
|
|
|
|
resource "aws_security_group" "noncompliant" {
|
|
|
|
name = "allow_ssh_noncompliant"
|
|
|
|
description = "allow_ssh_noncompliant"
|
|
|
|
vpc_id = aws_vpc.main.id
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
description = "SSH rule"
|
|
|
|
from_port = 22
|
2022-02-07 11:08:29 +01:00
|
|
|
to_port = 22
|
2021-09-15 08:10:36 +00:00
|
|
|
protocol = "tcp"
|
2022-02-07 11:08:29 +01:00
|
|
|
cidr_blocks = ["0.0.0.0/0"] # Noncompliant
|
2021-09-15 08:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2022-02-07 11:08:29 +01:00
|
|
|
A security rule allowing all inbound SSH traffic for Azure:
|
|
|
|
|
|
|
|
[source,terraform]
|
|
|
|
----
|
|
|
|
resource "azurerm_network_security_rule" "noncompliant" {
|
|
|
|
priority = 100
|
|
|
|
direction = "Inbound"
|
|
|
|
access = "Allow"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
|
|
|
source_address_prefix = "*" # Noncompliant
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2022-02-11 09:19:08 +01:00
|
|
|
A firewall rule allowing all inbound SSH traffic for GCP:
|
|
|
|
|
|
|
|
[source,terraform]
|
|
|
|
----
|
|
|
|
resource "google_compute_firewall" "noncompliant" {
|
|
|
|
network = google_compute_network.default.name
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["0.0.0.0/0"] # Noncompliant
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
A security rule allowing all inbound SSH traffic for Azure:
|
|
|
|
|
|
|
|
[source,terraform]
|
|
|
|
----
|
|
|
|
resource "azurerm_network_security_rule" "noncompliant" {
|
|
|
|
priority = 100
|
|
|
|
direction = "Inbound"
|
|
|
|
access = "Allow"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
|
|
|
source_address_prefix = "*" # Noncompliant
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-09-15 08:10:36 +00:00
|
|
|
== Compliant Solution
|
|
|
|
|
2022-02-07 11:08:29 +01:00
|
|
|
An ingress rule allowing inbound SSH traffic from specific IP addresses for AWS:
|
2021-09-15 08:10:36 +00:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,terraform]
|
2021-09-15 08:10:36 +00:00
|
|
|
----
|
|
|
|
resource "aws_security_group" "compliant" {
|
|
|
|
name = "allow_ssh_compliant"
|
|
|
|
description = "allow_ssh_compliant"
|
|
|
|
vpc_id = aws_vpc.main.id
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
description = "SSH rule"
|
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
protocol = "tcp"
|
2022-02-07 11:08:29 +01:00
|
|
|
cidr_blocks = ["1.2.3.0/24"]
|
2021-09-15 08:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2022-02-07 11:08:29 +01:00
|
|
|
A security rule allowing inbound SSH traffic from specific IP addresses for Azure:
|
|
|
|
|
2022-02-11 09:19:08 +01:00
|
|
|
|
2022-02-07 11:08:29 +01:00
|
|
|
[source,terraform]
|
|
|
|
----
|
|
|
|
resource "azurerm_network_security_rule" "compliant" {
|
|
|
|
priority = 100
|
|
|
|
direction = "Inbound"
|
|
|
|
access = "Allow"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
|
|
|
source_address_prefix = "1.2.3.0"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2022-02-11 09:19:08 +01:00
|
|
|
A firewall rule allowing inbound SSH traffic from specific IP addresses for GCP:
|
|
|
|
|
|
|
|
[source,terraform]
|
|
|
|
----
|
|
|
|
resource "google_compute_firewall" "compliant" {
|
|
|
|
network = google_compute_network.default.name
|
|
|
|
|
|
|
|
allow {
|
|
|
|
protocol = "tcp"
|
|
|
|
ports = ["22"]
|
|
|
|
}
|
|
|
|
|
|
|
|
source_ranges = ["10.0.0.1/32"]
|
|
|
|
}
|
|
|
|
----
|
2022-02-04 17:28:24 +01:00
|
|
|
include::../see.adoc[]
|