-
Notifications
You must be signed in to change notification settings - Fork 34
✨ Add macOS FileVault, Gatekeeper, and SIP resources #7059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ failback | |
| fargate | ||
| filestore | ||
| filesz | ||
| filevault | ||
| firefox | ||
| firestore | ||
| FLEXGROUP | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Copyright (c) Mondoo, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package resources | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "go.mondoo.com/mql/v13/llx" | ||
| ) | ||
|
|
||
| type mqlMacosFilevaultInternal struct { | ||
| lock sync.Mutex | ||
| fetched bool | ||
| output string | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) fetchStatus() (string, error) { | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
| m.lock.Lock() | ||
| defer m.lock.Unlock() | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
|
|
||
| res, err := NewResource(m.MqlRuntime, "command", map[string]*llx.RawData{ | ||
| "command": llx.StringData("fdesetup status"), | ||
| }) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| cmd := res.(*mqlCommand) | ||
| if exit := cmd.GetExitcode(); exit.Data != 0 { | ||
| return "", errors.New("fdesetup status failed: " + cmd.GetStderr().Data) | ||
| } | ||
|
|
||
| // fdesetup status outputs lines like: | ||
| // "FileVault is On." | ||
| // "FileVault is Off." | ||
| // "Encryption in progress: Percent completed = 50.0" | ||
| // "Decryption in progress: Percent completed = 50.0" | ||
| output := strings.TrimSpace(cmd.GetStdout().Data) | ||
| lines := strings.SplitN(output, "\n", 2) | ||
|
|
||
| m.output = strings.TrimSpace(lines[0]) | ||
| m.fetched = true | ||
| return m.output, nil | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) status() (string, error) { | ||
| return m.fetchStatus() | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) enabled() (bool, error) { | ||
| status, err := m.fetchStatus() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| return strings.Contains(status, "FileVault is On") || | ||
| strings.Contains(status, "Encryption in progress"), nil | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) runFdesetup(subcmd string) (string, error) { | ||
| res, err := NewResource(m.MqlRuntime, "command", map[string]*llx.RawData{ | ||
| "command": llx.StringData("fdesetup " + subcmd), | ||
| }) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| cmd := res.(*mqlCommand) | ||
| if exit := cmd.GetExitcode(); exit.Data != 0 { | ||
| return "", errors.New("fdesetup " + subcmd + " failed: " + cmd.GetStderr().Data) | ||
| } | ||
| return strings.TrimSpace(cmd.GetStdout().Data), nil | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) hasPersonalRecoveryKey() (bool, error) { | ||
| enabled, err := m.enabled() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if !enabled { | ||
| return false, nil | ||
| } | ||
| // fdesetup haspersonalrecoverykey outputs "true" or "false" | ||
| output, err := m.runFdesetup("haspersonalrecoverykey") | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return output == "true", nil | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) hasInstitutionalRecoveryKey() (bool, error) { | ||
| enabled, err := m.enabled() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if !enabled { | ||
| return false, nil | ||
| } | ||
| // fdesetup hasinstitutionalrecoverykey outputs "true" or "false" | ||
| output, err := m.runFdesetup("hasinstitutionalrecoverykey") | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return output == "true", nil | ||
| } | ||
|
|
||
| func (m *mqlMacosFilevault) users() ([]any, error) { | ||
| enabled, err := m.enabled() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !enabled { | ||
| return []any{}, nil | ||
| } | ||
| // fdesetup list outputs lines like: | ||
| // "user1,85632A00-1234-5678-ABCD-123456789ABC" | ||
| // "user2,95632A00-1234-5678-ABCD-123456789ABC" | ||
| output, err := m.runFdesetup("list") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if output == "" { | ||
| return []any{}, nil | ||
| } | ||
|
|
||
| var users []any | ||
| for _, line := range strings.Split(output, "\n") { | ||
| line = strings.TrimSpace(line) | ||
| if line == "" { | ||
| continue | ||
| } | ||
| // Each line is "username,UUID" — extract the username | ||
| parts := strings.SplitN(line, ",", 2) | ||
| users = append(users, parts[0]) | ||
| } | ||
|
|
||
| return users, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) Mondoo, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package resources | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "go.mondoo.com/mql/v13/llx" | ||
| ) | ||
|
|
||
| type mqlMacosGatekeeperInternal struct { | ||
| lock sync.Mutex | ||
| fetched bool | ||
| output string | ||
| } | ||
|
|
||
| func (m *mqlMacosGatekeeper) fetchStatus() (string, error) { | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
| m.lock.Lock() | ||
| defer m.lock.Unlock() | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
|
|
||
| res, err := NewResource(m.MqlRuntime, "command", map[string]*llx.RawData{ | ||
| "command": llx.StringData("spctl --status"), | ||
| }) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| cmd := res.(*mqlCommand) | ||
| if exit := cmd.GetExitcode(); exit.Data != 0 { | ||
| return "", errors.New("spctl --status failed: " + cmd.GetStderr().Data) | ||
| } | ||
|
|
||
| // spctl --status outputs: | ||
| // "assessments enabled" (Gatekeeper on) | ||
| // "assessments disabled" (Gatekeeper off) | ||
| m.output = strings.TrimSpace(cmd.GetStdout().Data) | ||
| m.fetched = true | ||
| return m.output, nil | ||
| } | ||
|
|
||
| func (m *mqlMacosGatekeeper) status() (string, error) { | ||
| return m.fetchStatus() | ||
| } | ||
|
|
||
| func (m *mqlMacosGatekeeper) enabled() (bool, error) { | ||
| status, err := m.fetchStatus() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| return strings.Contains(status, "assessments enabled"), nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) Mondoo, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package resources | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "go.mondoo.com/mql/v13/llx" | ||
| ) | ||
|
|
||
| type mqlMacosSipInternal struct { | ||
| lock sync.Mutex | ||
| fetched bool | ||
| output string | ||
| } | ||
|
|
||
| func (m *mqlMacosSip) fetchStatus() (string, error) { | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
| m.lock.Lock() | ||
| defer m.lock.Unlock() | ||
| if m.fetched { | ||
| return m.output, nil | ||
| } | ||
|
|
||
| res, err := NewResource(m.MqlRuntime, "command", map[string]*llx.RawData{ | ||
| "command": llx.StringData("csrutil status"), | ||
| }) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| cmd := res.(*mqlCommand) | ||
| if exit := cmd.GetExitcode(); exit.Data != 0 { | ||
| return "", errors.New("csrutil status failed: " + cmd.GetStderr().Data) | ||
| } | ||
|
|
||
| // csrutil status outputs: | ||
| // "System Integrity Protection status: enabled." | ||
| // "System Integrity Protection status: disabled." | ||
| // May also include individual configuration flags on separate lines | ||
| output := strings.TrimSpace(cmd.GetStdout().Data) | ||
| lines := strings.SplitN(output, "\n", 2) | ||
|
|
||
| m.output = strings.TrimSpace(lines[0]) | ||
| m.fetched = true | ||
| return m.output, nil | ||
| } | ||
|
|
||
| func (m *mqlMacosSip) status() (string, error) { | ||
| return m.fetchStatus() | ||
| } | ||
|
|
||
| func (m *mqlMacosSip) enabled() (bool, error) { | ||
| status, err := m.fetchStatus() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| return strings.Contains(status, "status: enabled"), nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.