Skip to content
Draft
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
5 changes: 4 additions & 1 deletion .github/workflows/ocp-test-profiles.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Trigger OCP Tests When Relevant
on:
pull_request:
branches: [ master, 'stabilization*' ]

Check failure on line 4 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

4:41 [brackets] too many spaces inside brackets

Check failure on line 4 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

4:16 [brackets] too many spaces inside brackets
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.run_id }}
cancel-in-progress: true
Expand All @@ -15,7 +15,7 @@
pull-requests: write
steps:
- name: Install Deps
run: dnf install -y cmake make openscap-utils python3-pyyaml python3-jinja2 git python3-deepdiff python3-requests jq python3-pip nodejs

Check failure on line 18 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

18:100 [line-length] line too long (143 > 99 characters)
- name: Install deps python
run: pip install gitpython xmldiff
- name: Checkout
Expand All @@ -33,10 +33,10 @@
- name: Find forking point
env:
BASE_BRANCH: ${{ github.base_ref }}
run: echo "FORK_POINT=$(git merge-base origin/$BASE_BRANCH ${{ github.event.pull_request.head.sha }})" >> $GITHUB_OUTPUT

Check failure on line 36 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

36:100 [line-length] line too long (128 > 99 characters)
id: fork_point
- name: Detect content changes in the PR
run: python3 ./ctf/content_test_filtering.py pr --base ${{ steps.fork_point.outputs.FORK_POINT }} --remote_repo ${{ github.server_url }}/${{ github.repository }} --verbose --rule --output json ${{ github.event.pull_request.number }} > ctf-output.json

Check failure on line 39 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

39:100 [line-length] line too long (259 > 99 characters)
- name: Test if there are no content changes
run: echo "CTF_OUTPUT_SIZE=$(stat --printf="%s" ctf-output.json)" >> $GITHUB_OUTPUT
id: ctf
Expand All @@ -51,23 +51,23 @@
- name: Get product attribute
if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }}
id: product
uses: notiz-dev/github-action-json-property@a5a9c668b16513c737c3e1f8956772c99c73f6e8 # v0.2.0

Check failure on line 54 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

54:100 [line-length] line too long (101 > 99 characters)
with:
path: 'ctf-output.json'
prop_path: 'product'

- name: Build product OCP and RHCOS content
if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' && (contains(steps.product.outputs.prop, 'ocp4') || contains(steps.product.outputs.prop, 'rhcos4')) }}

Check failure on line 60 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

60:100 [line-length] line too long (159 > 99 characters)
run: ./build_product --datastream ocp4 rhcos4 --cel-content=ocp4

- name: Process list of rules into a list of product-profiles to test
if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' && (contains(steps.product.outputs.prop, 'ocp4') || contains(steps.product.outputs.prop, 'rhcos4')) }}

Check failure on line 64 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

64:100 [line-length] line too long (159 > 99 characters)
id: profiles_to_test

Check failure on line 65 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

65:29 [trailing-spaces] trailing spaces
run: |
# Let's grab the profiles for which we have a CI job configured
PROW_CONFIG=https://raw.githubusercontent.com/openshift/release/refs/heads/master/ci-operator/config/ComplianceAsCode/content/ComplianceAsCode-content-master.yaml
curl -o prow_config.yaml ${PROW_CONFIG}
readarray -t TESTED_PROFILES <<< $(grep -r PROFILE= ./prow_config.yaml | sort -u | sed 's/.*export PROFILE=\(.*\)/\1/')

Check failure on line 70 in .github/workflows/ocp-test-profiles.yaml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

70:100 [line-length] line too long (129 > 99 characters)

RULES=$(cat ctf-output.json | jq -r '.rules[]')

Expand All @@ -91,7 +91,10 @@
done

ALL_PROFILES+=(${ELIGIBLE_PROFILES[@]})
PROFILES+=(${ELIGIBLE_PROFILES[$(($RANDOM%(${#ELIGIBLE_PROFILES[@]})))]})
# Only add a profile if there are eligible profiles with CI jobs
if [ ${#ELIGIBLE_PROFILES[@]} -gt 0 ]; then
PROFILES+=(${ELIGIBLE_PROFILES[$(($RANDOM%(${#ELIGIBLE_PROFILES[@]})))]})
fi
done

# Sort and ensure that the profiles are unique
Expand Down
1 change: 1 addition & 0 deletions components/at.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ packages:
- at
rules:
- file_at_deny_not_exist
- file_permissions_at_binaries
- service_atd_disabled
2 changes: 2 additions & 0 deletions components/dnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages:
- dnf-automatic
- dnf-plugin-subscription-manager
- libdnf-plugin-subscription-manager
- python3-dnf
rules:
- clean_components_post_updating
- disable_weak_deps
Expand All @@ -12,6 +13,7 @@ rules:
- ensure_gpgcheck_local_packages
- ensure_gpgcheck_never_disabled
- ensure_gpgcheck_repo_metadata
- file_permissions_dnf_binaries
- package_dnf-automatic_installed
- package_dnf-plugin-subscription-manager_installed
- package_libdnf-plugin-subscription-manager_installed
5 changes: 5 additions & 0 deletions components/nmap-ncat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: nmap-ncat
packages:
- nmap-ncat
rules:
- file_permissions_nmap_ncat_binaries
5 changes: 5 additions & 0 deletions components/socat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: socat
packages:
- socat
rules:
- file_permissions_socat_binaries
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
documentation_complete: true

title: 'Restrict Execution of At Job Scheduling Binaries'

description: |-
On RHCOS, packages in the base image cannot be removed. As a compensating
control, job scheduling utilities such as at should have their execute
permissions removed to prevent unauthorized task scheduling.
{{{ describe_file_permissions(file="/usr/bin/at", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/atq", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/atrm", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/batch", perms="0644") }}}

rationale: |-
The at package provides the ability to schedule one-time tasks for future
execution. While not installed by default on RHCOS, if present, attackers
could use these utilities to schedule malicious tasks, making it harder to
detect and trace unauthorized activity. On immutable systems like RHCOS,
removing execute permissions prevents these tools from being used while
maintaining system integrity.

severity: high

identifiers:
cce@rhcos4: CCE-86492-6

platform: rhcos4

ocil: |-
{{{ describe_file_permissions(file="/usr/bin/at", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/atq", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/atrm", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/batch", perms="0644") }}}

template:
name: file_permissions
vars:
filepath:
- /usr/bin/at
- /usr/bin/atq
- /usr/bin/atrm
- /usr/bin/batch
filemode: '0644'
missing_file_pass: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with correct permissions (0000)
touch /usr/bin/at
touch /usr/bin/atq
touch /usr/bin/atrm
touch /usr/bin/batch
chmod 0000 /usr/bin/at
chmod 0000 /usr/bin/atq
chmod 0000 /usr/bin/atrm
chmod 0000 /usr/bin/batch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# platform = multi_platform_all

# Remove binaries - should pass because missing_file_pass: true
rm -f /usr/bin/at
rm -f /usr/bin/atq
rm -f /usr/bin/atrm
rm -f /usr/bin/batch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with wrong permissions (0755)
touch /usr/bin/at
touch /usr/bin/atq
touch /usr/bin/atrm
touch /usr/bin/batch
chmod 0755 /usr/bin/at
chmod 0755 /usr/bin/atq
chmod 0755 /usr/bin/atrm
chmod 0755 /usr/bin/batch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
documentation_complete: true

title: 'Restrict Execution of DNF Package Manager Binaries'

description: |-
On RHCOS, packages in the base image cannot be removed. As a compensating
control, package management utilities such as dnf and yum should have their
execute permissions removed to prevent unauthorized package installation.
{{{ describe_file_permissions(file="/usr/bin/dnf", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/dnf-3", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/yum", perms="0644") }}}

rationale: |-
The dnf and python3-dnf packages provide package management utilities for
installing, updating, and removing software. RHCOS is designed to be an
immutable operating system managed through atomic upgrades and containerization.
Retaining these utilities with execute permissions allows unauthorized users
to install or modify packages, potentially compromising system integrity.
On immutable systems like RHCOS, removing execute permissions prevents
unauthorized package management while maintaining system integrity.

severity: high

identifiers:
cce@rhcos4: CCE-86494-2

platform: rhcos4

ocil: |-
{{{ describe_file_permissions(file="/usr/bin/dnf", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/dnf-3", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/yum", perms="0644") }}}

template:
name: file_permissions
vars:
filepath:
- /usr/bin/dnf
- /usr/bin/dnf-3
- /usr/bin/yum
filemode: '0644'
missing_file_pass: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with correct permissions (0000)
touch /usr/bin/dnf
touch /usr/bin/dnf-3
touch /usr/bin/yum
chmod 0000 /usr/bin/dnf
chmod 0000 /usr/bin/dnf-3
chmod 0000 /usr/bin/yum
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# platform = multi_platform_all

# Remove binaries - should pass because missing_file_pass: true
rm -f /usr/bin/dnf
rm -f /usr/bin/dnf-3
rm -f /usr/bin/yum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with wrong permissions (0755)
touch /usr/bin/dnf
touch /usr/bin/dnf-3
touch /usr/bin/yum
chmod 0755 /usr/bin/dnf
chmod 0755 /usr/bin/dnf-3
chmod 0755 /usr/bin/yum
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
documentation_complete: true

title: 'Restrict Execution of Netcat Binaries'

description: |-
On RHCOS, packages in the base image cannot be removed. As a compensating
control, network utilities such as netcat should have their execute permissions
removed to prevent unauthorized use.
{{{ describe_file_permissions(file="/usr/bin/ncat", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/nc", perms="0644") }}}

rationale: |-
Utilities such as netcat can be used for legitimate troubleshooting,
but they also present a significant security risk if misused by attackers
to create unauthorized network connections, transfer data, or establish
reverse shells. On immutable operating systems like RHCOS, removing execute
permissions prevents these tools from being used while maintaining system integrity.

severity: high

identifiers:
cce@rhcos4: CCE-86483-5

platform: rhcos4

ocil: |-
{{{ describe_file_permissions(file="/usr/bin/ncat", perms="0644") }}}
{{{ describe_file_permissions(file="/usr/bin/nc", perms="0644") }}}

template:
name: file_permissions
vars:
filepath:
- /usr/bin/ncat
- /usr/bin/nc
filemode: '0644'
missing_file_pass: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with correct permissions (0000)
touch /usr/bin/ncat
touch /usr/bin/nc
chmod 0000 /usr/bin/ncat
chmod 0000 /usr/bin/nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# platform = multi_platform_all

# Remove binaries - should pass because missing_file_pass: true
rm -f /usr/bin/ncat
rm -f /usr/bin/nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# platform = multi_platform_all

# Create binaries with wrong permissions (0755)
touch /usr/bin/ncat
touch /usr/bin/nc
chmod 0755 /usr/bin/ncat
chmod 0755 /usr/bin/nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
documentation_complete: true

title: 'Restrict Execution of Socat Binaries'

description: |-
On RHCOS, packages in the base image cannot be removed. As a compensating
control, network utilities such as socat should have their execute permissions
removed to prevent unauthorized use.
{{{ describe_file_permissions(file="/usr/bin/socat", perms="0644") }}}

rationale: |-
Utilities such as socat can be used for legitimate troubleshooting,
but they also present a significant security risk if misused by attackers
to create unauthorized network connections, transfer data, or establish
reverse shells. On immutable operating systems like RHCOS, removing execute
permissions prevents these tools from being used while maintaining system integrity.

severity: high

identifiers:
cce@rhcos4: CCE-86484-3

platform: rhcos4

ocil: |-
{{{ describe_file_permissions(file="/usr/bin/socat", perms="0644") }}}

template:
name: file_permissions
vars:
filepath: /usr/bin/socat
filemode: '0644'
missing_file_pass: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# platform = multi_platform_all

# Create binary with correct permissions (0000)
touch /usr/bin/socat
chmod 0000 /usr/bin/socat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# platform = multi_platform_all

# Remove binary - should pass because missing_file_pass: true
rm -f /usr/bin/socat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# platform = multi_platform_all

# Create binary with wrong permissions (0755)
touch /usr/bin/socat
chmod 0755 /usr/bin/socat
4 changes: 4 additions & 0 deletions products/rhcos4/profiles/default.profile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ selections:
- file_permissions_backup_etc_group
- etc_system_fips_exists
- package_net-snmp_removed
- file_permissions_at_binaries
- file_permissions_dnf_binaries
- file_permissions_nmap_ncat_binaries
- file_permissions_socat_binaries
- package_fapolicyd_installed
- audit_rules_for_ospp
- sshd_enable_pam
Expand Down
4 changes: 0 additions & 4 deletions shared/references/cce-redhat-avail.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
CCE-86483-5
CCE-86484-3
CCE-86492-6
CCE-86494-2
CCE-86497-5
CCE-86498-3
CCE-86499-1
Expand Down
31 changes: 31 additions & 0 deletions shared/templates/file_permissions/kubernetes.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# platform = multi_platform_rhcos
# reboot = true
# strategy = restrict
# complexity = low
# disruption = low
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
spec:
config:
ignition:
version: 3.1.0
systemd:
units:
- name: {{{ rule_id }}}-permissions.service
enabled: true
contents: |
[Unit]
Description=Set file permissions for {{{ rule_id }}}
DefaultDependencies=no
After=local-fs.target

[Service]
Type=oneshot
{{% for path in FILEPATH %}}
ExecStart=/bin/bash -c 'test -e {{{ path }}} && chmod {{{ FILEMODE }}} {{{ path }}} || true'
{{% endfor %}}
RemainAfterExit=yes

[Install]
WantedBy=basic.target
1 change: 1 addition & 0 deletions shared/templates/file_permissions/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ supported_languages:
- ansible
- bash
- oval
- kubernetes
Loading