Skip to content

⭐ Add jamf provider#7144

Merged
tas50 merged 2 commits into
mainfrom
add-jamf-provider
May 12, 2026
Merged

⭐ Add jamf provider#7144
tas50 merged 2 commits into
mainfrom
add-jamf-provider

Conversation

@AdamVB

@AdamVB AdamVB commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new Jamf Pro provider to mql, enabling querying of Jamf-managed infrastructure via the Jamf Pro API.

Usage

Connect using OAuth2 client credentials and your Jamf Pro instance domain:

mql shell jamf --client-id <CLIENT_ID> --client-secret <CLIENT_SECRET> --instance-domain https://yourdomain.jamfcloud.com

Credentials can also be provided via environment variables: CLIENT_ID, CLIENT_SECRET, INSTANCE_DOMAIN.

Example queries

# List all computers with their OS version and encryption status
jamf.computerInventory { name operatingSystemVersion fileVault2Enabled firewallEnabled }

# Check SSO configuration
jamf.sso { ssoEnabled ssoForEnrollmentEnabled idpProviderType }

# Look up a specific user
jamf.userByName("jsmith") { fullName email position }

# List smart groups
jamf.smartGroups { name smartGroup }

# Get installed packages
jamf.packages { name fileName priority }

# Check Jamf Pro version
jamf.version

New resources

Resource Description
jamf Root resource — provides access to inventory, packages, SSO, users, smart groups, and version
jamfComputer Computer inventory record (hardware, OS, security settings, enrollment info)
jamfComputer.localUserAccounts Local user accounts on a managed computer (lazy-loaded per computer)
jamf.userByName Look up a Jamf user by username (supports init for direct queries)
jamfUsers User summary (id, name)
jamfPackages Software package definition (name, file, category, priority)
ssoSettings SSO configuration (provider type, enrollment settings, session timeout)
computerGroups Smart/static computer groups

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Test Results

7 891 tests  ±0   7 887 ✅ ±0   5m 42s ⏱️ + 1m 59s
  526 suites ±0       4 💤 ±0 
   39 files   ±0       0 ❌ ±0 

Results for commit c3b5c12. ± Comparison against base commit 30374c9.

♻️ This comment has been updated with latest results.

@github-actions

This comment has been minimized.

@AdamVB AdamVB marked this pull request as ready for review April 9, 2026 15:44
@vjeffrey

vjeffrey commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

/review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider may panic on nil pointer dereferences when API returns nil optional fields, and SSO field naming violates MQL conventions.

Comment thread providers/jamf/resources/packages.go Outdated
Comment thread providers/jamf/resources/version.go
Comment thread providers/jamf/resources/jamf.lr
Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/resources/computer_inventory_count.go Outdated
Comment thread providers/jamf/resources/jamf.lr
Comment thread providers/jamf/resources/jamf.lr
@mondoo-code-review mondoo-code-review Bot dismissed their stale review April 9, 2026 16:05

Superseded by new review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Previous review findings (nil panic, naming conventions, typo, id bug) are all addressed; date fields remain as strings.

Comment thread providers/jamf/resources/jamf.lr
@tas50 tas50 changed the title Add jamf provider ⭐ Add jamf provider Apr 9, 2026

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

Review: Nil Handling, Performance, and Logic

Nil Handling

1. No nil checks on any API response. Every resource file dereferences the SDK return value without checking for nil. If any Jamf SDK method returns (nil, nil), these all panic:

  • sso_settings.goinfo.SsoEnabled
  • computer_inventory.goinventory.Results
  • computer_inventory.go:localUserAccounts()inventory.LocalUserAccounts
  • computer_groups.gogroups.Results
  • users.gousers.Users
  • packages.goinventory.Results
  • user_by_name.gouser.ID, user.Name, etc.
  • version.goinfo.Version is nil-checked, but info itself is not

2. Nested struct dereferences in computer_inventory.go. c.General.Name, c.Hardware.Make, c.OperatingSystem.Name, c.Security.AutoLoginDisabled — if any sub-struct (General, Hardware, OperatingSystem, Security) is nil, this panics. The Jamf API can return partial records.

3. sso() returns a singular resource pointer (*mqlSsoSettings). If this ever needs to return nil (e.g., SSO not configured, access denied), it must set a.Sso.State = plugin.StateIsSet | plugin.StateIsNull before return nil, nil. See CLAUDE.md "Never return nil, nil from a singular resource accessor without setting StateIsNull first."

Logic Errors

4. ParseCLI leaks client secret into plaintext conf.Options. (provider.go:55-56):

conf.Options["client_secret"] = clientSecret

The secret already flows through conf.Credentials — storing it again in Options means it could be logged, serialized, or exposed in debug output. Remove client_id and client_secret from conf.Options.

5. ParseCLI env var fallback is tangled. (provider.go:60-74) When credentials come from env vars, the local variables are populated but conf.Options is only partially updated. Consider restructuring: resolve all sources (flags then env) first, then populate conf once at the end.

6. __id is never set in any CreateResource call. Per codebase conventions, __id must be explicitly set for caching. Without it, the runtime can't cache resources and the same API object fetched twice won't get a cache hit. Every CreateResource call needs:

"__id": llx.StringData("some-unique-stable-id"),

7. Fragile id() cache keys — using names instead of unique IDs.

  • mqlComputerGroups.id() returns Name.Data — group names aren't guaranteed unique
  • mqlJamfPackages.id() returns Name.Data — package names can collide
  • mqlJamfUsers.id() returns Name.Data — should use numeric ID (strconv.Itoa)

Use the actual unique ID field (formatted as string) for reliable caching.

8. Resource naming inconsistency in jamf.lr. Mixed prefixing and pluralization: jamfComputer, jamfPackages (plural), jamfUsers (plural), ssoSettings (no prefix), computerGroups (no prefix). Resource types should be singular and consistently named.

Performance

9. computerInventory() has no pagination. (computer_inventory.go:24) GetComputersInventory(url.Values{}) is called with empty params. The Jamf Pro inventory API is paginated — this will silently return only the first page. Customers with more computers than the default page size will get incomplete data. Must loop with page/page-size params.

10. computerInventoryCount() fetches ALL inventory records just to count them. (computer_inventory_count.go) It calls r.GetComputerInventory() which triggers the full inventory fetch, then counts the slice length. Jamf has a dedicated count endpoint — use it instead.

11. localUserAccounts() triggers N+1 API calls. Each jamfComputer.localUserAccounts call hits GetComputerInventoryByID. When iterating all computers' accounts, that's N additional API calls. Consider fetching local accounts in the initial inventory call if the SDK supports a section filter.

tas50
tas50 previously requested changes Apr 9, 2026

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

Address the issues in the comment and let's see if we can get a testing doc for the provider in place so it's easy for folks to check this.

Also it needs tests.

@tas50 tas50 force-pushed the add-jamf-provider branch from 254ecc0 to e2a17fb Compare May 11, 2026 07:34

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider has missing resource IDs and overly generic env var names that will cause caching bugs and credential conflicts.

Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/resources/sso_settings.go
Comment thread providers/jamf/resources/user_by_name.go
Comment thread providers/jamf/provider/provider.go
Comment thread providers/jamf/connection/connection.go
Comment thread providers/jamf/resources/jamf.lr Outdated
@mondoo-code-review mondoo-code-review Bot dismissed their stale review May 11, 2026 07:38

Superseded by new review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dependency bump fixes go-git security vulnerability; previous unresolved findings remain unaddressed.

Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/resources/sso_settings.go
Comment thread providers/jamf/resources/user_by_name.go
Comment thread providers/jamf/provider/provider.go
Comment thread providers/jamf/connection/connection.go
Comment thread providers/jamf/resources/jamf.lr
tas50 added a commit that referenced this pull request May 12, 2026
…ex, docs

Resolves the open review feedback on #7144:

- Add id() / __id for jamf.localUserAccount (computer + uid + username),
  jamf.ssoSettings (singleton), and jamf.userByName (name-keyed) so the
  runtime can cache them correctly.
- Rename env vars to JAMF_CLIENT_ID, JAMF_CLIENT_SECRET, and
  JAMF_INSTANCE_DOMAIN to avoid colliding with other tools/providers.
- Protect the per-computer localUserAccounts cache on JamfConnection
  with sync.RWMutex.
- Expand the jamf and jamf.userByName resource doc-comments to the
  two-part title + description form required by CLAUDE.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tas50 tas50 force-pushed the add-jamf-provider branch from b124411 to 59ef57e Compare May 12, 2026 07:02

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider queries all computer groups but labels the field as smart groups only, returning incorrect results.

Comment thread providers/jamf/resources/computer_groups.go Outdated
Comment thread providers/jamf/resources/packages.go
Comment thread providers/jamf/resources/computer_inventory.go Outdated
Comment thread providers/jamf/config/config.go
Comment thread providers/jamf/resources/jamf.lr
@mondoo-code-review mondoo-code-review Bot dismissed their stale review May 12, 2026 07:14

Superseded by new review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Version alignment and naming fixes applied; several previously-flagged issues (missing __id, unsynchronized map, generic env vars, missing doc comments) remain unaddressed.

Comment thread providers/jamf/resources/jamf.lr.versions
Comment thread providers/jamf/resources/computer_inventory_count.go
tas50 added a commit that referenced this pull request May 12, 2026
A first-PR provider whose Version hasn't shipped should use that version
for every .lr.versions entry, not version+1 — the "next patch" rule only
applies to additive changes after a release. Came up on the jamf provider
review (#7144) where 13.0.0 was correct for the initial cut.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tas50 tas50 dismissed their stale review May 12, 2026 11:23

Issues fixed

@tas50

tas50 commented May 12, 2026

Copy link
Copy Markdown
Member

/review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Incremental improvements to Jamf provider: limits inventory sections and fixes userByName init semantics.

Comment thread providers/jamf/resources/user_by_name.go
Comment thread providers/jamf/resources/user_by_name.go
tas50 added a commit that referenced this pull request May 12, 2026
Address review feedback on PR #7144:
- Replace fragile len(args) > 1 short-circuit with explicit args["id"]
  check so the "already hydrated" path is self-documenting.
- Guard against a nil ResourceUser from GetUserByName before
  dereferencing its fields.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixes nil-dereference crash and fragile argument check in userByName, but most previous findings remain unaddressed.

Comment thread providers/jamf/resources/user_by_name.go
Comment thread providers/jamf/connection/connection.go
Comment thread providers/jamf/provider/provider.go
Comment thread providers/jamf/resources/jamf.lr
@tas50 tas50 force-pushed the add-jamf-provider branch 2 times, most recently from b50ada6 to 7c4b062 Compare May 12, 2026 19:36

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider adds computer inventory, SSO, packages, users, and groups querying via Jamf Pro API.

Comment thread providers/jamf/provider/provider.go Outdated
Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/resources/computer_groups.go
@tas50 tas50 force-pushed the add-jamf-provider branch from 7c4b062 to 481e723 Compare May 12, 2026 19:40

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf Pro provider adds querying of computer inventory, packages, SSO settings, users, and groups.

Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/provider/provider.go

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider is well-structured; one test will fail due to a missing env var setup.

Comment thread providers/jamf/provider/provider_test.go
@tas50 tas50 force-pushed the add-jamf-provider branch from 481e723 to c913800 Compare May 12, 2026 19:45

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider will not be discoverable by the CLI due to missing registration in defaults.go

Comment thread Makefile
Comment thread providers/jamf/config/config.go
Comment thread providers/jamf/resources/computer_inventory.go
Comment thread providers/jamf/resources/sso_settings.go

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf Pro provider adds querying of computer inventory, SSO settings, packages, users, and computer groups.

Comment thread providers/jamf/resources/jamf.lr
Comment thread providers/jamf/config/config.go
@tas50

tas50 commented May 12, 2026

Copy link
Copy Markdown
Member

/review

@tas50 tas50 force-pushed the add-jamf-provider branch from dc2efd6 to 066929b Compare May 12, 2026 19:58

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New Jamf provider is functional but has a platform identifier bug that embeds the URL scheme in the platform ID path.

Comment thread providers/jamf/connection/connection.go
Comment thread providers/jamf/connection/connection_test.go
Comment thread providers/jamf/config/config.go
@tas50 tas50 force-pushed the add-jamf-provider branch 2 times, most recently from 66afea7 to 71b85bf Compare May 12, 2026 20:06
Adds a new Jamf Pro provider to mql, enabling queries against
Jamf-managed infrastructure via the Jamf Pro API. Authentication
uses OAuth2 client credentials (flags or JAMF_CLIENT_ID /
JAMF_CLIENT_SECRET / JAMF_INSTANCE_DOMAIN env vars).

Resources:
- jamf — root, exposes computerInventory, computerInventoryCount,
  packages, sso, version, users, computerGroups
- jamf.computer — computer inventory record (hardware, OS, security
  posture, enrollment state, local user accounts)
- jamf.computer.localUserAccount — local user account on a managed Mac
- jamf.package — software package definition
- jamf.ssoSettings — SSO configuration (singleton)
- jamf.computerGroup — smart or static computer group
- jamf.user — Jamf user directory entry
- jamf.userByName — lookup a Jamf user by username via init()

Also bumps go-git/v5 transitively in the jamf module to address
GHSA-3xc5-wrhm-f963, and fixes a stale cnquery/v9 reference in the
mql scan command output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tas50 tas50 force-pushed the add-jamf-provider branch from 71b85bf to 230d20f Compare May 12, 2026 20:09
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tas50 tas50 self-requested a review May 12, 2026 20:16
@tas50 tas50 merged commit 72830cc into main May 12, 2026
21 checks passed
@tas50 tas50 deleted the add-jamf-provider branch May 12, 2026 21:06
@github-actions github-actions Bot locked and limited conversation to collaborators May 12, 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.

3 participants