# Defensive Macos Hardening

> Use when you must harden a fleet of macOS endpoints against a defined threat model, or audit an existing macOS baseline for gaps. Covers Gatekeeper and XProtect configuration and assessment mode, managed device baselines through MDM configuration profiles, FileVault full disk encryption enforcement, the application firewall and network controls, application allowlisting with Santa or Gatekeeper rules, software update policy, and verification checks that prove each control is actually enforced rather than merely configured.

- Skill: `mizazhaider-ceh/defensive-macos-hardening` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/defensive-macos-hardening`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/defensive-macos-hardening/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/defensive-macos-hardening

---


A macOS hardening baseline is only as strong as its verification. It is
easy to deploy a configuration profile and hard to prove the control it
declares is actually enforced on every host, especially when users hold
admin rights, when hosts drift between check-ins, and when a control has
an assessment mode that logs but does not block. This skill is built
around that distinction: for each control, it gives the configuration,
the enforcement mechanism, and the verification check that proves the
control works. Scope is defensive work on fleets you manage or are
authorized to audit. Apply changes through MDM where possible, test
every baseline change on a pilot group before fleet-wide rollout, and
never weaken a control on a production host to test it.

## Quick Workflow

1. Define the threat model and the user population before touching a
   setting: admin versus standard users, managed versus unmanaged,
   office versus remote.
2. Baseline the current state: Gatekeeper status, FileVault status,
   firewall state, installed profiles, and update compliance, per host.
3. Deploy controls through MDM configuration profiles where a profile
   exists, and through a scripted check where it does not.
4. Verify enforcement, not just configuration: attempt the blocked
   action in a lab host and confirm it is blocked, then confirm the
   same check passes on a sample of fleet hosts.
5. Monitor drift: re-run the verification checks on a schedule and
   alert on hosts that fall out of compliance.
6. Handle exceptions as time-boxed, documented, and scoped grants, not
   as permanent baseline changes.
7. Review the baseline on every major macOS release, because Apple
   moves controls between settings, profiles, and defaults regularly.

## 1. Baseline audit

Before hardening anything, measure the current state so the hardening
work has a before and after. Run the same audit on a pilot host and on
a fleet sample, and store the output as the baseline record.

```bash
spctl --status
fdesetup status
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode
profiles status -type enrollment
softwareupdate --list 2>/dev/null | head -20
```

Example output shape: `spctl --status` reports assessments enabled or
disabled, `fdesetup status` reports FileVault on or off, and the
firewall queries report on or off plus stealth mode. Any host reporting
assessments disabled, FileVault off, or firewall off is non-compliant
until proven otherwise, and the audit must name the host, not just the
count.

## 2. Gatekeeper and XProtect configuration

Gatekeeper checks code signatures and notarization before an app runs,
and XProtect provides signature-based malware detection with behavioral
remediation. The hardening controls are: leave Gatekeeper assessments
enabled, restrict app sources to the App Store and identified
developers, and never teach users to bypass Gatekeeper with a control
click override as a routine step.

```bash
spctl --status
spctl --assess --type execute /Applications/SuspectApp.app 2>&1 | head -10
spctl --list 2>/dev/null | head -30
defaults read /Library/Preferences/com.apple.security GKAutoRearm 2>/dev/null
```

Verify enforcement by assessing a known unsigned test app in the lab:
the assessment must fail, and the user must see the block, not a silent
pass. Review the Gatekeeper rule list (`spctl --list`) for broad
allow rules added by installers, because a single over-broad rule can
undo the control for an entire class of software. XProtect updates
arrive through the system update mechanism, so XProtect currency is
really update compliance, which section 6 covers.

## 3. MDM baselines and configuration profiles

MDM is the only scalable way to enforce a macOS baseline, and
configuration profiles are its unit of control. The baseline profile
set should cover: passcode and authentication policy, FileVault
enforcement with key escrow, firewall state, Gatekeeper settings,
software update deferrals, TCC grants for managed apps only, and
restrictions on removable media and sharing services where the threat
model requires them.

```bash
profiles list 2>/dev/null
profiles show -type enrollment 2>/dev/null | head -30
profiles status -type enrollment
```

Audit profiles the same way you audit any code: review what each
profile sets, who approved it, and whether it is still needed. A stale
profile that grants a TCC permission to a retired app is a live
permission, not history. Remove profiles through MDM, not by deleting
files by hand, so the removal is recorded and reversible. For unmanaged
hosts, document the equivalent manual settings and verify them with
the same checks, accepting that manual settings drift faster.

## 4. FileVault enforcement

FileVault full disk encryption protects data at rest and is a baseline
requirement for any fleet that leaves the office. Enforcement means:
FileVault on, a recovery key escrowed to MDM, and institutional
recovery keys rotated on staff departure. A host that reports FileVault
on but has no escrowed key is only half compliant, because a forgotten
password becomes unrecoverable data loss.

```bash
fdesetup status
fdesetup hasinstitutionalrecoverykey 2>/dev/null
fdesetup list 2>/dev/null | head -20
diskutil apfs list 2>/dev/null | grep -E "FileVault|Encrypted"
```

Verify on a sample of hosts, not just the MDM dashboard, because a
dashboard can report the last known state while the host has since
been wiped, reinstalled, or left unmanaged. Treat any host that cannot
be verified as non-compliant until it checks in.

## 5. Firewall and network controls

The macOS application firewall controls incoming connections per app,
and stealth mode drops unsolicited probes rather than answering them.
The hardening controls are: firewall on, stealth mode on, signed
software receiving incoming connections only where the business need
is documented, and sharing services (file sharing, remote login,
remote management) off unless explicitly required.

```bash
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode
/usr/libexec/ApplicationFirewall/socketfilterfw --listapps 2>/dev/null | head -30
systemsetup -getremotelogin 2>/dev/null
systemsetup -getremoteappleevents 2>/dev/null
```

Verify enforcement from the network, not just from the host: probe a
lab host with the firewall on and confirm the port does not answer,
and confirm that an app added to the allow list actually receives its
traffic. A firewall rule that exists in the UI but does not survive a
reboot or a profile re-push is a drift finding, and drift findings are
what the monitoring step exists to catch.

## 6. Application allowlisting

Allowlisting is the strongest application control and the hardest to
operate, so deploy it in stages: audit mode first, enforcement second,
with an exception process ready before enforcement starts. Santa is the
common open source choice on macOS, operating in monitor mode (log
only) or lockdown mode (block unlisted binaries), while Gatekeeper
rules can provide a lighter form of allowlisting for fleets that cannot
operate Santa.

```bash
santactl status 2>/dev/null | head -30
santactl rule --list 2>/dev/null | head -30
spctl --list --label "Allowed" 2>/dev/null | head -20
```

The staged rollout matters more than the tool choice. Run monitor mode
for at least one full business cycle, review the log for legitimate
software the baseline missed, add rules for that software, and only
then switch to lockdown. An allowlist deployed without a monitor phase
blocks legitimate work on day one, and the exception flood that follows
usually ends with the control being disabled. Record every rule with a
justification and an owner, and review the rule set quarterly.

## 7. Software update policy

Updates are the delivery mechanism for XProtect, Gatekeeper rule
updates, and security patches, so update compliance is a security
control, not an IT convenience metric. The policy should set: automatic
security updates on, a deferral window short enough that critical
patches land within days, and a pilot group that receives updates
first to catch bad releases before fleet-wide rollout.

```bash
softwareupdate --list 2>/dev/null
defaults read /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled 2>/dev/null
defaults read /Library/Preferences/com.apple.SoftwareUpdate ConfigDataInstall 2>/dev/null
defaults read /Library/Preferences/com.apple.SoftwareUpdate CriticalUpdateInstall 2>/dev/null
```

Report compliance as the fraction of hosts on the current or
previous patch level, with the tail (hosts more than one release
behind) named explicitly. A host that has not checked in for updates in
30 days is a finding, whether it is powered off, unmanaged, or broken,
and the report must distinguish those three cases.

## Edge cases

- Users with admin rights can change local settings that MDM does not
  lock, so a profile that sets but does not enforce a value will drift;
  prefer payloads that restrict the setting over payloads that merely
  set a default.
- Gatekeeper overrides by users are legitimate in narrow cases
  (in-house tools, research software), so the exception process must
  be fast enough that users do not route around it, or the control
  will be bypassed socially rather than technically.
- FileVault escrow fails silently when a host enrolls without network
  access to the escrow service; verify escrow per host, not per
  enrollment batch.
- The application firewall does not filter outgoing connections, so
  it is not a data loss prevention control; pair it with network
  egress controls where that threat matters.
- Santa in lockdown mode blocks unsigned scripts and tools that
  developers and analysts rely on, so developer hosts need a scoped
  policy, not the standard office policy.
- Major macOS releases move settings between System Settings panes and
  rename profile payload keys, so re-validate the baseline against the
  new release in the lab before pushing it to the fleet.
- Remote and hybrid workers may go weeks without VPN or office network
  access, so MDM check-in and update compliance windows must reflect
  real connectivity, not an office assumption.

## Key references

- Apple Platform Security Guide, macOS protections, Gatekeeper,
  XProtect, and FileVault: https://support.apple.com/guide/security/welcome/web
- Apple MDM protocol and configuration profile reference for the
  payloads used in this skill: https://developer.apple.com/documentation/devicemanagement
- CIS Benchmark for macOS, the community baseline most fleets adapt
  rather than adopt verbatim: https://www.cisecurity.org/cis-benchmarks
- MITRE ATT&CK macOS mitigations mapped to the controls in this skill:
  https://attack.mitre.org/matrices/enterprise/macos/
- The companion privesc skill privesc-macos for the attack vectors
  these controls are meant to close, and the companion forensics skill
  forensics-macos-artifacts for the log retention and TCC auditing
  settings that make post-incident investigation possible.

## See also

- `endpoint-hardening-baseline`: Use it instead when the baseline must cover a mixed Windows, macOS, and Linux fleet rather than macOS alone.

