Skip to content

Commit 1fdd2b8

Browse files
LuciaSirovamartin-mat
authored andcommitted
Task hardcoded_ip_adresses_in_k8s_runtime_configuration doesnt flag network adress as hardcoded adress
Signed-off-by: Lucia Sirova <lucia.sirova@tietoevry.com> Add methods for checking whether ip adress and mask is valid Signed-off-by: Lucia Sirova <lucia.sirova@tietoevry.com> Add adding allowed ip adresses via config Signed-off-by: Lucia Sirova <lucia.sirova@tietoevry.com>
1 parent db251a9 commit 1fdd2b8

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

CNF_TESTSUITE_YML_USAGE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ Example setting:
8989

9090
`white_list_container_names: [coredns]`
9191

92+
##### hardcoded_ip_exceptions
93+
94+
The values of this optional key are the IP addresses that are allowed to appear as hardcoded values in the configuration of the CNF.
95+
This value is used to allow particular hardcoded IPs to be exempted from the `hardcoded_ip_adresses_in_k8s_runtime_configuration` test when the CNF is being validated.
96+
The reason this is needed is because the CNF Testsuite checks all configuration files and manifests used by the CNF for the presence of hardcoded IP addresses.
97+
While hardcoding IPs is generally discouraged in cloud-native environments, there may be cases where certain addresses are justified and cannot be avoided.
98+
This exception list can be used to explicitly allow such IPs and prevent them from being reported as violations.
99+
100+
````yaml
101+
config_version: v2
102+
common:
103+
hardcoded_ip_exceptions:
104+
- ip: 8.8.8.8
105+
- ip: 4.4.4.4
106+
````
107+
92108
##### `docker_insecure_registries`
93109

94110
The docker client expects the image registries to be using an HTTPS API endpoint. This option is used to configure insecure registries that the docker client should be allowed to access.

docs/TEST_DOCUMENTATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,8 +1481,8 @@ Review all Helm Charts & Kubernetes Manifest files for the CNF and remove all oc
14811481

14821482
#### Overview
14831483

1484-
The hardcoded ip address test will scan all of the CNF's workload resources and check for any static, hardcoded ip addresses being used in the configuration. CIDR notation is allowed and will not cause the test to fail.
1485-
Expectation: That no hardcoded IP addresses (without CIDR masks) are found in the Kubernetes workload resources for the CNF.
1484+
The hardcoded ip address test will scan all of the CNF's workload resources and check for any static, hardcoded ip addresses being used in the configuration. CIDR notation is allowed and will not cause the test to fail. IP addresses that are justified by application logic are possible to be included in `hardcoded_ip_exceptions` in the [CNF configuration](https://github.com/lfn-cnti/testsuite/blob/main/CNF_TESTSUITE_YML_USAGE.md) and will be excluded from violation reports.
1485+
Expectation: That no hardcoded IP addresses are found in the Kubernetes workload resources for the CNF unless they are in CIDR format or explicitly listed in `hardcoded_ip_exceptions`.
14861486

14871487
#### Rationale
14881488

sample-cnfs/sample_coredns/chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ service:
3232
annotations:
3333
prometheus.io/scrape: "true"
3434
prometheus.io/port: "9153"
35+
hardcodedIpTest: "8.8.8.8 4.4.4.4"
3536

3637
serviceAccount:
3738
create: false

sample-cnfs/sample_coredns/cnf-testsuite.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ deployments:
55
- name: coredns
66
helm_directory: chart
77
namespace: cnfspace
8+
common:
9+
hardcoded_ip_exceptions:
10+
- ip: 8.8.8.8
11+
- ip: 4.4.4.4

src/tasks/utils/cnf_installation/config_versions/config_v2.cr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module CNFInstall
1717
white_list_container_names = [] of String,
1818
docker_insecure_registries = [] of String,
1919
image_registry_fqdns = {} of String => String,
20-
five_g_parameters = FiveGParameters.new()
20+
five_g_parameters = FiveGParameters.new(),
21+
hardcoded_ip_exceptions = [] of HardcodedIPsAllowed
2122
def initialize()
2223
end
2324
end
@@ -125,5 +126,9 @@ module CNFInstall
125126
end
126127
end
127128
end
129+
130+
class HardcodedIPsAllowed < CNFInstall::Config::ConfigBase
131+
getter ip : String
132+
end
128133
end
129134
end

src/tasks/workload/configuration.cr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,24 @@ desc "Does the CNF have hardcoded IPs in the K8s resource configuration"
213213
task "hardcoded_ip_addresses_in_k8s_runtime_configuration" do |t, args|
214214
task_response = CNFManager::Task.task_runner(args, task: t) do |args, config|
215215
current_dir = FileUtils.pwd
216-
allowed_ip_adresses = [
216+
allowed_ip_addresses = [
217217
"127.0.0.1",
218218
"0.0.0.0"
219219
]
220+
hardcoded_ip_exceptions = config.common.hardcoded_ip_exceptions
220221

221222
found_violations = [] of NamedTuple(line_number: Int32, line: String)
222223
line_number = 1
223224
File.open(COMMON_MANIFEST_FILE_PATH) do |file|
224225
file.each_line do |line|
225226
ip_adress_regex = /((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d{1,2}))?/
226-
227227
if line.matches?(/NOTES:/)
228228
break
229229
elsif matches = line.scan(ip_adress_regex)
230230
matches.each do |match|
231231
ip = match[1]
232232
cidr_suffix = match[2]?
233-
234-
next if allowed_ip_adresses.includes?(ip) || cidr_suffix
235-
233+
next if allowed_ip_addresses.includes?(ip) || hardcoded_ip_exceptions.any? { |e| e.ip == ip } || cidr_suffix
236234
found_violations << {line_number: line_number, line: line.strip}
237235
end
238236
end

0 commit comments

Comments
 (0)