-
Notifications
You must be signed in to change notification settings - Fork 794
Add variable support to yamlfile_value template #6563
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
Changes from all commits
423100d
2695955
57c3a7e
8757c19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| default_result: PASS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'API Server Request Timeout' | ||
|
|
||
| description: 'Enter API Server Request Timeout' | ||
|
|
||
| type: string | ||
|
|
||
| operator: equals | ||
|
|
||
| interactive: false | ||
|
|
||
| options: | ||
| 300: "300" | ||
| default: "3600" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| documentation_complete: true | ||
|
|
||
| prodtype: ocp4 | ||
|
|
||
| title: 'Ensure Eviction threshold Settings Are Set - evictionSoft: memory.available' | ||
|
|
||
| description: |- | ||
| <p>Two types of garbage collection are performed on an OpenShift Container Platform node:</p> | ||
|
|
||
| <ul> | ||
| <li>Container garbage collection: Removes terminated containers.</li> | ||
| <li>Image garbage collection: Removes images not referenced by any running pods.</li> | ||
| </ul> | ||
|
|
||
| <p> | ||
| Container garbage collection can be performed using eviction thresholds. | ||
| Image garbage collection relies on disk usage as reported by cAdvisor on the | ||
| node to decide which images to remove from the node. | ||
| </p> | ||
|
|
||
| <p> | ||
| The OpenShift administrator can configure how OpenShift Container Platform | ||
| performs garbage collection by creating a kubeletConfig object for each | ||
| Machine Config Pool using any combination of the following: | ||
| </p> | ||
|
|
||
| <ul> | ||
| <li>soft eviction for containers</li> | ||
| <li>hard eviction for containers</li> | ||
| <li>eviction for images</li> | ||
| </ul> | ||
|
|
||
| <p> | ||
| To configure, follow the directions in | ||
| {{{ weblink(link="https://docs.openshift.com/container-platform/4.5/nodes/nodes/nodes-nodes-garbage-collection.html#nodes-nodes-garbage-collection-configuring_nodes-nodes-configuring", | ||
| text="the documentation") }}} | ||
| </p> | ||
|
|
||
| <p> | ||
| This rule pertains to the <tt>memory.available</tt> setting of the <tt>evictionSoft</tt> | ||
| section. | ||
| </p> | ||
|
|
||
| rationale: |- | ||
| Garbage collection is important to ensure sufficient resource availability | ||
| and avoiding degraded performance and availability. In the worst case, the | ||
| system might crash or just be unusable for a long period of time. | ||
| Based on your system resources and tests, choose an appropriate threshold | ||
| value to activate garbage collection. | ||
|
|
||
| severity: medium | ||
|
|
||
| references: | ||
| cis: 1.3.1 | ||
|
|
||
| identifiers: | ||
| cce@ocp4: CCE-84222-9 | ||
|
|
||
| ocil_clause: '<tt>memory.available</tt> is not set in <tt>evictionSoft</tt> section' | ||
|
|
||
| ocil: |- | ||
| Run the following command on the kubelet node(s): | ||
| <pre>$ oc debug -q node/$NODE -- jq -r '.evictionSoft."memory.available"' /host/etc/kubernetes/kubelet.conf</pre> | ||
| and make sure it outputs | ||
| <pre>{{{ xccdf_value("var_kubelet_evictionsoft_memory_available") }}}</pre> | ||
|
|
||
| template: | ||
| name: yamlfile_value | ||
| vars: | ||
| filepath: /etc/kubernetes/kubelet.conf | ||
| yamlpath: ".evictionSoft['memory.available']" | ||
| xccdf_variable: var_kubelet_evictionsoft_memory_available |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Configure Kubelet EvictionSoft Memory Avilable' | ||
|
|
||
| description: 'Memory Available for the EvictionSoft threshold to trigger.' | ||
|
|
||
| type: string | ||
|
|
||
| operator: equals | ||
|
|
||
| interactive: false | ||
|
|
||
| options: | ||
| default: 500Mi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -577,7 +577,6 @@ CCE-84215-3 | |
| CCE-84217-9 | ||
| CCE-84218-7 | ||
| CCE-84221-1 | ||
| CCE-84222-9 | ||
| CCE-84223-7 | ||
| CCE-84224-5 | ||
| CCE-84225-2 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,39 @@ | |
| <literal_component>{{{ FILEPATH }}}</literal_component> | ||
| {{% endif %}} | ||
| </local_variable> | ||
|
|
||
| {{% if not XCCDF_VARIABLE or (XCCDF_VARIABLE and not EMBEDDED_DATA) %}} | ||
| <ind:yamlfilecontent_test id="test_{{{ rule_id }}}" check="all" check_existence="{{{ CHECK_EXISTENCE|default("only_one_exists") }}}" | ||
| {{{ {'comment': "In the file '" + FILEPATH + "' find only one object at path '" + YAMLPATH + "'."}|xmlattr }}} version="1"> | ||
| <ind:object object_ref="object_{{{ rule_id }}}"/> | ||
| <ind:state state_ref="state_{{{ rule_id }}}"/> | ||
| </ind:yamlfilecontent_test> | ||
| {{% else %}} | ||
| <ind:variable_test id="test_{{{ rule_id }}}" check="all" check_existence="all_exist" comment="comment1" version="1"> | ||
| <ind:object object_ref="variable_object_{{{ rule_id }}}" /> | ||
| <ind:state state_ref="variable_state_{{{ rule_id }}}" /> | ||
| </ind:variable_test> | ||
|
|
||
| <ind:variable_object id="variable_object_{{{ rule_id }}}" version="1"> | ||
| <ind:var_ref>local_variable_{{{ rule_id }}}</ind:var_ref> | ||
| </ind:variable_object> | ||
|
|
||
| <ind:variable_state id="variable_state_{{{ rule_id }}}" version="1"> | ||
| <ind:value datatype="string" operation="equals" var_ref="{{{ XCCDF_VARIABLE }}}"/> | ||
| </ind:variable_state> | ||
|
|
||
| {{% for val in VALUES %}} | ||
| <local_variable id="local_variable_{{{ rule_id }}}" datatype="string" comment="comment1" version="1"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not work with multiple
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh! this might need an enhancement then.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it doesn't make sense to keep this multiple value option here. We should consider only the first element and make sure in the template data processing that the condition is met. Partially, this condition is already met... when using variables and embedded the data processing checks if values is set, I think we would have to expand to check if only a single value is present |
||
| <regex_capture pattern='{{{ val.value }}}'> | ||
| <object_component item_field="value" record_field="#" object_ref="object_{{{ rule_id }}}" /> | ||
| </regex_capture> | ||
| </local_variable> | ||
| {{% endfor %}} | ||
|
|
||
| {{% endif %}} | ||
|
|
||
| {{% if XCCDF_VARIABLE %}} | ||
| <external_variable comment="variable" datatype="string" id="{{{ XCCDF_VARIABLE }}}" version="1" /> | ||
| {{% endif %}} | ||
|
|
||
| {{% if OCP_DATA %}} | ||
| <unix:file_test id="test_file_for_{{{ rule_id }}}" check="all" check_existence="only_one_exists" | ||
|
|
@@ -48,17 +75,26 @@ | |
| <ind:yamlpath>{{{ YAMLPATH }}}</ind:yamlpath> | ||
| </ind:yamlfilecontent_object> | ||
|
|
||
| {{% if not XCCDF_VARIABLE or (XCCDF_VARIABLE and not EMBEDDED_DATA) %}} | ||
| <ind:yamlfilecontent_state id="state_{{{ rule_id }}}" version="1"> | ||
| <ind:value datatype="record"{{% if ENTITY_CHECK %}} entity_check="{{{ ENTITY_CHECK }}}"{{% endif %}}> | ||
| {{% if XCCDF_VARIABLE and not EMBEDDED_DATA %}} | ||
| {{% set name = "#" if not VALUES else (VALUES|first).key|default("#")|escape_yaml_key %}} | ||
| {{% set datatype = "string" if not VALUES else (VALUES|first).type|default("string") %}} | ||
| <field {{{ {'name': name, 'datatype': datatype, 'operation': 'equals'}|xmlattr }}} var_ref="{{{ XCCDF_VARIABLE }}}" /> | ||
| {{% else %}} | ||
| {{% for val in VALUES %}} | ||
| <field {{{ {'name': val.key|default("#")|escape_yaml_key, 'datatype': val.type, 'operation': val.operation, 'entity_check': val.entity_check}|xmlattr }}}>{{{ val.value }}}</field> | ||
| {{% endfor %}} | ||
| {{% endif %}} | ||
| </ind:value> | ||
| </ind:yamlfilecontent_state> | ||
| {{% endif %}} | ||
|
|
||
| {{% if OCP_DATA %}} | ||
| <external_variable comment="Root of OCP data dump" datatype="string" id="ocp_data_root" version="1" /> | ||
| {{% endif %}} | ||
|
|
||
| </def-group> | ||
| {{% endif %}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| def preprocess(data, lang): | ||
|
|
||
| if data.get("xccdf_variable") and data.get("embedded_data") == "true": | ||
| if not data.get("values"): | ||
| raise ValueError( | ||
| "You should specify a capture regex in the 'value' field " | ||
| "when querying for a 'xccdf_value' that returns an embedded value. " | ||
| "Rule ID: {}".format(data["_rule_id"])) | ||
|
|
||
| data["embedded_data"] = data.get("embedded_data", "false") == "true" | ||
| data["ocp_data"] = data.get("ocp_data", "false") == "true" | ||
| return data |
Uh oh!
There was an error while loading. Please reload this page.