Skip to content

Fix cis compliance stemcell issues - #702

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

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

Conversation

@karthickaliappa

@karthickaliappa karthickaliappa commented Aug 3, 2026

Copy link
Copy Markdown

This PR addresses CIS benchmark compliance failures on BOSH stemcells by implementing hardening controls and corresponding test assertions for identified CIS rule IDs.

Changes are as below

  • CIS 5.1.18 (SSH MaxStartups): Added MaxStartups 10:30:60 in /etc/ssh/sshd_config to throttle concurrent unauthenticated SSH connections.
  • CIS 5.2.2 (Sudo use_pty): Enabled Defaults use_pty in /etc/sudoers to ensure sudo commands execute within a pseudo-terminal.
  • CIS 5.2.3 (Sudo logfile): Added Defaults logfile=/var/log/sudo.log in /etc/sudoers for dedicated sudo activity logging.
  • CIS 5.4.3.2 (Shell TMOUT): Created /etc/profile.d/01-tmout.sh with readonly TMOUT=900 (declared read-only so a session can't override it) for a 15-minute idle shell session timeout.
  • InSpec Tests: Added InSpec test assertions verifying all four controls.

Impact on Stemcell Users

  • SSH: Throttles unauthenticated connection flooding (>10 concurrent attempts); active logins remain unaffected.
  • Sudo: Commands run in a pseudo-terminal and log activity to /var/log/sudo.log.
  • Sessions: Inactive shell sessions automatically log out after 15 minutes of inactivity.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 3, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The stemcell build enables sudo pseudo-terminal allocation and logging. It includes /etc/sudoers.d configuration. 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 these settings.

Suggested reviewers: aramprice

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description and does not provide the required merge-forward guidance or AI review feedback status. Add the required description sections and document the merge-forward branch strategy and AI review feedback status.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the pull request's main purpose of fixing CIS compliance issues in the stemcell.
✨ Finishing Touches
🧪 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 Outdated
Comment thread bosh-stemcell/spec/support/os_image_shared_examples.rb Outdated
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 thread bosh-stemcell/spec/support/os_image_shared_examples.rb
Comment thread stemcell_builder/stages/bosh_users/assets/sudoers
@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

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bosh-stemcell/spec/support/os_image_shared_examples.rb (1)

247-249: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize MaxStartups matches before contain_exactly.

The regex allows leading spaces or tabs, but scan returns the raw matched text. If sshd_config contains MaxStartups 10:30:60 or \tMaxStartups 10:30:60, this assertion compares against the non-canonical string and fails. Count or build the expected value from stripped matches instead.

🤖 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 247 -
249, Update the MaxStartups expectation in the “sets MaxStartups to 10:30:60”
example to normalize each regex match by removing leading whitespace before
applying contain_exactly. Preserve the existing pattern and expected canonical
value while ensuring indented configuration lines compare successfully.
🤖 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.

Outside diff comments:
In `@bosh-stemcell/spec/support/os_image_shared_examples.rb`:
- Around line 247-249: Update the MaxStartups expectation in the “sets
MaxStartups to 10:30:60” example to normalize each regex match by removing
leading whitespace before applying contain_exactly. Preserve the existing
pattern and expected canonical value while ensuring indented configuration lines
compare successfully.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e41c3742-0438-43e5-9a09-5e2e3674ce2f

📥 Commits

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

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

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 6, 2026
@github-project-automation github-project-automation Bot moved this from Waiting for Changes | Open for Contribution to Pending Merge | Prioritized in Foundational Infrastructure Working Group Aug 6, 2026
…pecs

Annotate SSH MaxStartups (CIS-5.1.18), sudo use_pty (CIS-5.2.2), sudo logfile
(CIS-5.2.3), and TMOUT idle timeout (CIS-5.4.3.2) in build scripts, assets,
and RSpec shared examples.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bosh-stemcell/spec/support/os_image_shared_examples.rb (1)

33-35: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Ignore whitespace-prefixed comments in the !use_pty check.

egrep -v '^#' only skips lines that start with #. A line such as #Defaults !use_pty passes the negative filter as an active override, so this example can fail even though the policy is unchanged. Filter ^[[:space:]]*# instead.

Proposed fix
-      describe command("egrep -sh '!use_pty' /etc/sudoers /etc/sudoers.d/* | egrep -v '^#' --") do
+      describe command("egrep -sh '!use_pty' /etc/sudoers /etc/sudoers.d/* | egrep -v '^[[:space:]]*#' --") do
🤖 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 33 - 35,
Update the `command` assertion in the `!use_pty` check to exclude comments
beginning with optional whitespace by changing the negative filter to match
`^[[:space:]]*#`; preserve the existing file targets and stdout expectation.
🤖 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.

Outside diff comments:
In `@bosh-stemcell/spec/support/os_image_shared_examples.rb`:
- Around line 33-35: Update the `command` assertion in the `!use_pty` check to
exclude comments beginning with optional whitespace by changing the negative
filter to match `^[[:space:]]*#`; preserve the existing file targets and stdout
expectation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d75e3ab0-49d6-494a-acc6-768f1ee4061e

📥 Commits

Reviewing files that changed from the base of the PR and between a38f56b and a43a7d5.

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

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 6, 2026
Update egrep pattern to '^[[:space:]]*#' so commented-out !use_pty lines
with leading spaces or tabs are properly ignored in the spec assertion.

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bosh-stemcell/spec/support/os_image_shared_examples.rb (1)

249-251: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize the scanned SSH lines before comparison.

scan returns the leading whitespace when the directive is indented, but contain_exactly compares the full matched string. Strip each entry before the assertion so an indented MaxStartups 10:30:60 line does not fail.

Suggested fix
-      expect(sshd_config.content.scan(/^[ \t]*MaxStartups\s+\S+$/)).to contain_exactly("MaxStartups 10:30:60")
+      expect(sshd_config.content.scan(/^[ \t]*MaxStartups\s+\S+$/).map(&:strip)).to contain_exactly("MaxStartups 10:30:60")
🤖 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 249 -
251, Normalize the matches produced by the MaxStartups assertion in the “sets
MaxStartups to 10:30:60” example by stripping leading and trailing whitespace
from each scanned entry before contain_exactly compares them. Preserve the
expected directive value and existing scan pattern.
🤖 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 33-35: Update the sudoers scan command assertion in the
surrounding shared examples to verify a successful exit status in addition to
empty stdout, ensuring missing or unreadable files fail the check. Follow the
existing no-match assertion pattern and inspect stderr when needed to
distinguish an expected no-match status from command errors.

---

Outside diff comments:
In `@bosh-stemcell/spec/support/os_image_shared_examples.rb`:
- Around line 249-251: Normalize the matches produced by the MaxStartups
assertion in the “sets MaxStartups to 10:30:60” example by stripping leading and
trailing whitespace from each scanned entry before contain_exactly compares
them. Preserve the expected directive value and existing scan pattern.
🪄 Autofix

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: e64eacfb-70af-422b-b7c6-771b574c4ac9

📥 Commits

Reviewing files that changed from the base of the PR and between a43a7d5 and 6b93fb9.

📒 Files selected for processing (1)
  • bosh-stemcell/spec/support/os_image_shared_examples.rb

Comment thread bosh-stemcell/spec/support/os_image_shared_examples.rb
@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 6, 2026
Strip leading/trailing whitespace from scanned MaxStartups directives
before checking contain_exactly in os_image_shared_examples.rb.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 6, 2026
@github-project-automation github-project-automation Bot moved this from Waiting for Changes | Open for Contribution to Pending Merge | Prioritized in Foundational Infrastructure Working Group Aug 6, 2026

@selzoc selzoc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please add a human-readable summary of the changes to the PR description?

@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 6, 2026
@karthickaliappa
karthickaliappa requested a review from selzoc August 6, 2026 15:25
@selzoc
selzoc requested a review from Alphasite August 6, 2026 20:45
Comment thread stemcell_builder/stages/base_ssh/apply.sh Outdated
Comment thread stemcell_builder/stages/bosh_sudoers/apply.sh Outdated
Comment thread stemcell_builder/stages/bosh_users/assets/sudoers Outdated
Comment thread stemcell_builder/stages/bosh_sudoers/apply.sh Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 7, 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.

3 participants