Skip to content

feat: add lost-root-password lab with restricted initial access - #175

Merged
HimanM merged 2 commits into
mainfrom
feat/lost-root-password-lab
Jun 11, 2026
Merged

feat: add lost-root-password lab with restricted initial access#175
HimanM merged 2 commits into
mainfrom
feat/lost-root-password-lab

Conversation

@Himans-Butler

Copy link
Copy Markdown
Collaborator

Implements #26 — Lost Root Password lab with restricted SSH access.

Backend Changes

  • Adds support for optional initial_access: restricted in lab.yaml
  • When restricted, the web terminal connects as operator instead of root
  • Backend verify/solution scripts still use root internally (no CI impact)
  • Fully backwards-compatible — existing labs default to full

New Lab: lost-root-password

  • Player starts as operator with no sudo privileges
  • Must exploit a NOPASSWD sudo find misconfiguration to escalate to root
  • solution.sh restores operator to sudo group, cleans up dangerous rule, resets root password
  • verify.sh checks: operator in sudo group, dangerous rule removed, valid sudoers syntax

Documentation

  • LAB_FORMAT.md updated with initial_access section explaining restricted mode

Co-authored-by: HimanM 67066047+HimanM@users.noreply.github.com

@Himans-Butler
Himans-Butler force-pushed the feat/lost-root-password-lab branch from fe3028e to aaebaeb Compare June 10, 2026 18:30
@HimanM HimanM linked an issue Jun 10, 2026 that may be closed by this pull request
@Himans-Butler
Himans-Butler force-pushed the feat/lost-root-password-lab branch 3 times, most recently from fc43958 to 0421f69 Compare June 10, 2026 19:56
Closes #26

- Add backend support for initial_access: restricted in lab.yaml
- When restricted, web terminal connects as operator user
- Backend verify/solution scripts still run as root internally
- Create new lost-root-password lab with privilege escalation via sudo find exploit
- Update LAB_FORMAT.md to document initial_access field

Co-authored-by: HimanM <67066047+HimanM@users.noreply.github.com>
@Himans-Butler
Himans-Butler force-pushed the feat/lost-root-password-lab branch from 0421f69 to aaba6a1 Compare June 10, 2026 20:03
@HimanM HimanM added enhancement New feature or request help wanted Extra attention is needed labels Jun 10, 2026
@Himans-Butler

Himans-Butler commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

It took a few tries to get CI green. Here's what was wrong:

Root Cause

The operator username is problematic on the Ubuntu 24.04 cloud image used by CI. Even though base-passwd does not list it as reserved, cloud-init's users_groups module silently failed to create it. Empirical testing showed:

Username CI Result
operator groups: operator: no such user
opsuser PASSED

Fixes Applied

  1. Changed username operatoropsuser across lab files, backend, and docs.
  2. Rewrote cloud-init.yaml to use individual runcmd items instead of a multi-line string, avoiding potential yaml.dump corruption in the backend.
  3. Fixed solution.sh to use find /root -maxdepth 0 -exec ... (runs once) instead of find / -exec ... which would've executed for every file in the filesystem—literally bricked the runner.
  4. Added debug logging to backend/main.py printing initial_access and injected user list on VM launch.
  5. Updated LAB_FORMAT.md to document initial_access: restricted.

Backend Changes

  • LabInfo model gains initial_access field.
  • launch_lab() injects opsuser into cloud-init users when initial_access == restricted.
  • websocket_terminal() connects as opsuser instead of root when restricted.
  • verify_lab() and internal scripts still use root. No CI impact.

CI is green now.

@Himans-Butler

Copy link
Copy Markdown
Collaborator Author

Quick review, because apparently this lab wanted to trip over a very specific rake:

Please make the username configurable and use the same value consistently in both user-data and websocket_terminal().

- use opsuser for restricted terminal sessions
- keep cloud-init and websocket login paths consistent

Co-authored-by: HimanM <HimanM@users.noreply.github.com>
@Himans-Butler

Copy link
Copy Markdown
Collaborator Author

Green check ✅

Fixed the login mismatch: the restricted terminal now uses opsuser consistently in both cloud-init injection and the websocket SSH connection. I also re-ran a Python compile check on backend/main.py.

This one can stop pretending the user exists under two different names.

@Himans-Butler

Copy link
Copy Markdown
Collaborator Author

Green check ✅

Reviewed and looks good — the restricted login path is now consistent with the lab setup. No blockers.

@HimanM
HimanM merged commit d7538ba into main Jun 11, 2026
1 check passed
@HimanM
HimanM deleted the feat/lost-root-password-lab branch June 11, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LAB IDEA] Lost Root Password

2 participants