Skip to content

✨ Add user.loggedIn field to os provider#7096

Merged
tas50 merged 2 commits intomainfrom
feat/user-logged-in
Apr 2, 2026
Merged

✨ Add user.loggedIn field to os provider#7096
tas50 merged 2 commits intomainfrom
feat/user-logged-in

Conversation

@tas50
Copy link
Copy Markdown
Member

@tas50 tas50 commented Apr 2, 2026

Summary

  • Add a computed loggedIn bool field to the user resource that checks whether the user is currently logged in
  • Uses who on Unix/macOS and query user on Windows via the command resource
  • New field versioned as 13.7.1

Examples

# Check if a specific user is logged in
mql run local -c "user(name: 'tsmith').loggedIn"

# List all users with their login status
mql run local -c "users.list { name loggedIn }"

# Find all currently logged-in users
mql run local -c "users.list.where(loggedIn == true) { name }"

# Assert no shared/service accounts are logged in
mql run local -c "users.list.where(name == 'guest').all(loggedIn == false)"

Test plan

  • Build and install os provider, run mql shell local -c "users.list { name loggedIn }"
  • Verify currently logged-in user shows true, others show false
  • Test on Windows target if available

🤖 Generated with Claude Code

Add a computed `loggedIn` bool field to the `user` resource that checks
whether the user is currently logged in. Uses `who` on Unix/macOS and
`query user` on Windows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

New user.loggedIn field may return incorrect results on Windows and runs a command per-user without caching.

…rror

- Extract loggedInUsers() helper that runs who/query user once and returns
  a username set; the command resource caches the result so iterating
  users.list { loggedIn } no longer runs N commands.
- Skip header row and trim leading ">" from query user output on Windows.
- Check u.Name.Error before accessing u.Name.Data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mondoo-code-review mondoo-code-review bot dismissed their stale review April 2, 2026 17:25

Superseded by new review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

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

New user.loggedIn field correctly caches command output and handles Windows parsing edge cases.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Test Results

5 779 tests  ±0   5 775 ✅ ±0   2m 12s ⏱️ -1s
  433 suites ±0       4 💤 ±0 
   34 files   ±0       0 ❌ ±0 

Results for commit 0de1eab. ± Comparison against base commit c82dbc8.

@tas50 tas50 merged commit 8b48c76 into main Apr 2, 2026
23 checks passed
@tas50 tas50 deleted the feat/user-logged-in branch April 2, 2026 18:52
@github-actions github-actions bot locked and limited conversation to collaborators Apr 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant