Skip to content

Fix cis compliance stemcell issues - #702

Open
karthickaliappa wants to merge 3 commits into
cloudfoundry:ubuntu-jammyfrom
karthickaliappa:fix-cis-compliance-stemcell-issues
Open

Fix cis compliance stemcell issues#702
karthickaliappa wants to merge 3 commits into
cloudfoundry:ubuntu-jammyfrom
karthickaliappa:fix-cis-compliance-stemcell-issues

Conversation

@karthickaliappa

Copy link
Copy Markdown

Changes should be made in the earliest applicable branch, and
merged forward through subsequent branches.

  1. PR should be created against the oldest stemcell branch, ex: ubuntu-<short_name-N>
  2. After this PR has been merged create a PR to merge ubuntu-<short_name-N> into ubuntu-<short_name-N+1>
  3. Repeat as needed for subsequent stemcell line branches

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 3, 2026

Copy link
Copy Markdown

CLA Missing ID

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The stemcell build enables sudo pseudo-terminal allocation and logging. It creates /etc/profile.d/01-tmout.sh with readonly, exported TMOUT=900 and mode 0644. It normalizes SSH configuration to MaxStartups 10:30:60. Shared OS image examples validate all three configurations.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing CIS compliance issues in the stemcell.
Description check ✅ Passed The description includes the repository's merge-forward requirements but omits the AI review feedback section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bosh-stemcell/spec/support/os_image_shared_examples.rb`:
- Around line 74-80: Update the `/etc/profile.d/01-tmout.sh` InSpec example to
assert that the file is owned by root and its group is root, alongside the
existing file, mode, and content checks.
- Around line 241-244: Update the “sets MaxStartups to 10:30:60” example to
validate the effective configuration rather than mere presence: assert that
active MaxStartups directives contain exactly one entry with the expected value,
or use sshd -T to verify the process-effective value. Preserve the expected
value “MaxStartups 10:30:60”.

In `@stemcell_builder/stages/base_ssh/apply.sh`:
- Around line 27-28: Quote the chroot-derived paths in the sshd_config update
commands: update the sed target and output redirection associated with the
MaxStartups replacement so "$chroot" cannot undergo word splitting or glob
expansion. Preserve the existing deletion and append behavior.
- Around line 27-28: Update the MaxStartups cleanup in apply.sh to remove
directives with either spaces or tabs before appending the stemcell value.
Ensure all existing MaxStartups lines are normalized away so only the appended
`MaxStartups 10:30:60` directive remains.

In `@stemcell_builder/stages/bosh_users/apply.sh`:
- Around line 41-45: Quote the $chroot path expansion in both the here-document
redirection and the chmod command within the TMOUT profile setup, preserving the
existing file path and permissions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f9395556-6990-419d-af0d-2a4f1a0d305e

📥 Commits

Reviewing files that changed from the base of the PR and between d316db2 and 438eb27.

📒 Files selected for processing (4)
  • bosh-stemcell/spec/support/os_image_shared_examples.rb
  • stemcell_builder/stages/base_ssh/apply.sh
  • stemcell_builder/stages/bosh_users/apply.sh
  • stemcell_builder/stages/bosh_users/assets/sudoers

Comment thread bosh-stemcell/spec/support/os_image_shared_examples.rb
Comment thread bosh-stemcell/spec/support/os_image_shared_examples.rb
Comment thread stemcell_builder/stages/base_ssh/apply.sh Outdated
Comment thread stemcell_builder/stages/bosh_users/apply.sh Outdated
- Set MaxStartups 10:30:100 in sshd_config (CIS 5.1.18)
- Enable use_pty and logfile=/var/log/sudo.log in sudoers (CIS 5.2.2, 5.2.3)
- Configure TMOUT=900 shell timeout in /etc/profile.d/01-tmout.sh (CIS 5.4.3.2)
- Add corresponding rspec tests in os_image_shared_examples
- Change MaxStartups from default 10:30:100 to 10:30:60 in sshd_config
- Update corresponding rspec test assertion
- Assert root ownership and group for /etc/profile.d/01-tmout.sh in rspec tests
- Ensure MaxStartups scan validates single directive in sshd_config
- Normalize MaxStartups sed pattern to match tab/space indentations and quote chroot paths
- Quote chroot path expansions in TMOUT profile script creation
@karthickaliappa
karthickaliappa force-pushed the fix-cis-compliance-stemcell-issues branch from 1f0b772 to 7936f44 Compare August 3, 2026 14:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bosh-stemcell/spec/support/os_image_shared_examples.rb`:
- Around line 29-30: Update the sudo policy assertions in the shared examples
around the content match checks to validate the effective settings for the
intended sudo user, rather than relying only on ordered /etc/sudoers entries.
Ensure included sudoers files cannot override use_pty or logfile, while
preserving verification of the intended values.

In `@stemcell_builder/stages/bosh_users/assets/sudoers`:
- Around line 7-8: Update the sudoers asset by adding the /etc/sudoers.d include
directive after the privilege entries, preserving the required drop-in policy
loading and existing sudo configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c8b15601-c6dc-4ad1-aeb0-289e7b975a07

📥 Commits

Reviewing files that changed from the base of the PR and between 438eb27 and 7936f44.

📒 Files selected for processing (4)
  • bosh-stemcell/spec/support/os_image_shared_examples.rb
  • stemcell_builder/stages/base_ssh/apply.sh
  • stemcell_builder/stages/bosh_users/apply.sh
  • stemcell_builder/stages/bosh_users/assets/sudoers

Comment on lines +29 to +30
its(:content) { should match(/^Defaults\s+use_pty$/) }
its(:content) { should match(%r{^Defaults\s+logfile=/var/log/sudo\.log$}) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repository files matching os_image_shared_examples.rb:"
fd -a 'os_image_shared_examples.rb' . || true

file="$(fd 'os_image_shared_examples.rb' . | head -n 1 || true)"
if [ -n "${file:-}" ]; then
  echo
  echo "Size:"
  wc -l "$file"
  echo
  echo "Relevant file contents:"
  cat -n "$file"
fi

echo
echo "Search for sudoers examples/use_pty/logfile:"
rg -n "use_pty|sudoers|logfile=/var/log/sudo\\.log|Defaults" . || true

echo
echo "Search for sudo executable/config validation in specs/support:"
rg -n "sudo --|visudo|/etc/sudoers|Defaults|PTYS|logfile" . || true

Repository: cloudfoundry/bosh-linux-stemcell-builder

Length of output: 50396


🌐 Web query:

sudoers Defaults use_pty last match wins includedir behavior sudo man pages

💡 Result:

In the sudoers configuration, the following behaviors apply regarding Defaults options, rule matching, and included directories: Defaults use_pty The use_pty option controls whether sudo runs commands in a new pseudo-terminal (pty) [1][2]. As of sudo version 1.9.14, use_pty is enabled by default to enhance security by preventing terminal-based attacks (such as TIOCSTI or TIOCLINUX command injection) [3]. Running in a pty creates an additional process to monitor the command and pass terminal signals [1][2]. If this interferes with specific workflows—such as those requiring direct access to the invoking user's terminal or asynchronous background processing—you can restore the historic behavior by adding Defaults!use_pty to your sudoers file [1][2][3]. Last Match Wins The sudoers file processes entries in the order they appear [4][5]. When multiple entries match a user and command, they are applied sequentially, and the last matching entry determines the final permission, tag, or option [4][6][7]. Because of this last-match-wins policy, the order of rules—including those in included files—is critical [4][5][6]. Includedir Behavior The @includedir directive (and the legacy #includedir) allows sudo to process additional configuration files from a specified directory, such as /etc/sudoers.d/ [8][9]. When sudo encounters an @includedir directive, it suspends processing of the current file, reads each file in the specified directory in lexicographical (alphabetical) order, and then returns to the original file [8][9][10]. Because sudoers rules are cumulative and evaluated in order, the lexicographical sorting of filenames (e.g., 01_file, 10_file) effectively determines which rules are processed last and thus which rules take precedence [4][6][8]. Sudo skips files with names containing a period ('.') or ending in a tilde ('~') to avoid processing editor or package manager temporary/backup files [8][11].

Citations:


Validate the effective sudo policy.

/etc/sudoers.d defaults can reorder or override the assertions because Defaults entries are cumulative and later matching entries can disable use_pty or change logfile. Check the effective policy for the intended sudo user, or ensure the included files prohibit conflicting sudoers settings.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bosh-stemcell/spec/support/os_image_shared_examples.rb` around lines 29 - 30,
Update the sudo policy assertions in the shared examples around the content
match checks to validate the effective settings for the intended sudo user,
rather than relying only on ordered /etc/sudoers entries. Ensure included
sudoers files cannot override use_pty or logfile, while preserving verification
of the intended values.

Comment on lines +7 to +8
Defaults use_pty
Defaults logfile=/var/log/sudo.log

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Preserve the /etc/sudoers.d include in this asset.

stemcell_builder/stages/bosh_users/apply.sh copies this asset directly to /etc/sudoers at Lines 26-27. This asset has no #includedir /etc/sudoers.d, but bosh-stemcell/spec/support/os_image_shared_examples.rb requires it at Line 28. The image will fail that check, and sudo drop-in policies will not load. Add the include after the privilege entries.

Proposed fix
 %bosh_sudoers ALL=(ALL) NOPASSWD: ALL
+
+#includedir /etc/sudoers.d
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stemcell_builder/stages/bosh_users/assets/sudoers` around lines 7 - 8, Update
the sudoers asset by adding the /etc/sudoers.d include directive after the
privilege entries, preserving the required drop-in policy loading and existing
sudo configuration.

@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Waiting for Changes | Open for Contribution in Foundational Infrastructure Working Group Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting for Changes | Open for Contribution

Development

Successfully merging this pull request may close these issues.

1 participant