Mac: power settings, firewall, SSH key
- pmset: never sleep, no disk sleep, restart after a power cut, wake on network. The Mac had sleep 1 and only stayed up because BlueBubbles runs caffeinate. - Application firewall on, keeping signed software allowed automatically, stealth and block-all off. Hermes's ad hoc signed Python (dashboard on 9119) is allowed explicitly, since an unattended Mac blocks unsigned programs silently. - Local id_ed25519.pub in phil's authorized_keys (already there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f53992d652
commit
fe268bd171
6 files changed
+102
-2
No files matched your search
@@ -10,3 +10,11 @@ homebrew_formulae:
|
|||||||
homebrew_casks:
|
homebrew_casks:
|
||||||
- beeper
|
- beeper
|
||||||
- claude-code
|
- claude-code
|
||||||
|
|
||||||
|
# Power settings (pmset, AC power). The Mac had `sleep 1` and only stayed up
|
||||||
|
# because BlueBubbles runs caffeinate; this keeps it up on its own.
|
||||||
|
mac_pmset:
|
||||||
|
sleep: 0 # never sleep
|
||||||
|
disksleep: 0 # never spin down disks
|
||||||
|
autorestart: 1 # power back on after a power cut
|
||||||
|
womp: 1 # wake on network access
|
||||||
+12
-2
@@ -3,8 +3,18 @@
|
|||||||
Manages cogitator-02, an Apple Silicon Mac on the tailnet (`mac.yml`,
|
Manages cogitator-02, an Apple Silicon Mac on the tailnet (`mac.yml`,
|
||||||
`PLAYBOOK=mac.yml bin/deploy`).
|
`PLAYBOOK=mac.yml bin/deploy`).
|
||||||
|
|
||||||
- **Homebrew**: taps, formulae and casks listed in `group_vars/mac/main.yml`.
|
- **Homebrew** (tag `homebrew`): taps, formulae and casks listed in
|
||||||
Installs what's missing; never upgrades or removes.
|
`group_vars/mac/main.yml`. Installs what's missing; never upgrades or removes.
|
||||||
|
- **SSH key** (tag `ssh`): your local `~/.ssh/id_ed25519.pub` in phil's
|
||||||
|
`authorized_keys`. Other keys there are left alone.
|
||||||
|
- **Power** (tag `power`): `mac_pmset` in `group_vars/mac/main.yml`: never
|
||||||
|
sleep, power back on after a power cut, wake on network.
|
||||||
|
- **Firewall** (tag `firewall`): macOS's application firewall on, with signed
|
||||||
|
software allowed automatically (SSH, BlueBubbles, AirPlay, Tailscale), no
|
||||||
|
stealth mode and no block-all. Hermes's own Python isn't properly signed, so
|
||||||
|
it's allowed explicitly (its web dashboard listens on port 9119). Any other
|
||||||
|
unsigned program that needs incoming connections must be added the same way,
|
||||||
|
or the firewall silently blocks it.
|
||||||
|
|
||||||
Ansible logs in as `phil`. sudo needs phil's password, which is in the vault
|
Ansible logs in as `phil`. sudo needs phil's password, which is in the vault
|
||||||
as `vault_cogitator02.become_password`; only tasks with `become: true` use it.
|
as `vault_cogitator02.become_password`; only tasks with `become: true` use it.
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# macOS's application firewall. It filters incoming connections per program:
|
||||||
|
# Apple's and other properly signed apps are allowed automatically (SSH,
|
||||||
|
# BlueBubbles, AirPlay, Tailscale), unsigned ones are blocked. Nothing is
|
||||||
|
# asked on screen because nobody sits at this Mac, so an unsigned program
|
||||||
|
# that listens has to be allowed here.
|
||||||
|
- name: Read firewall settings
|
||||||
|
ansible.builtin.command: "{{ socketfilterfw }} --{{ item }}"
|
||||||
|
loop: [getglobalstate, getallowsigned, getstealthmode, getblockall, listapps]
|
||||||
|
register: firewall_read
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Note the current firewall settings
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
firewall_current: "{{ firewall_read.results | map(attribute='stdout') | join('\n') }}"
|
||||||
|
|
||||||
|
- name: Allow signed software, no stealth mode, don't block everything
|
||||||
|
ansible.builtin.command: "{{ socketfilterfw }} {{ item.set }}"
|
||||||
|
loop:
|
||||||
|
- { set: --setallowsigned on, current: built-in signed software ENABLED }
|
||||||
|
- { set: --setallowsignedapp on, current: downloaded signed software ENABLED }
|
||||||
|
- { set: --setstealthmode off, current: stealth mode is off }
|
||||||
|
- { set: --setblockall off, current: block all state set to disabled }
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.set }}"
|
||||||
|
when: item.current not in firewall_current
|
||||||
|
become: true
|
||||||
|
|
||||||
|
# Hermes's own Python (ad hoc signed) serves its web dashboard on port 9119.
|
||||||
|
# Its path has a version in it, so every Python Hermes has installed is allowed.
|
||||||
|
- name: Find Hermes's Python
|
||||||
|
ansible.builtin.find:
|
||||||
|
paths: "{{ ansible_user_dir }}/.hermes/tools"
|
||||||
|
patterns: '^python3\.\d+$'
|
||||||
|
use_regex: true
|
||||||
|
recurse: true
|
||||||
|
depth: 3
|
||||||
|
file_type: file
|
||||||
|
register: hermes_python
|
||||||
|
|
||||||
|
- name: Allow Hermes's Python
|
||||||
|
ansible.builtin.shell: >-
|
||||||
|
{{ socketfilterfw }} --add {{ item.path | quote }} &&
|
||||||
|
{{ socketfilterfw }} --unblockapp {{ item.path | quote }}
|
||||||
|
loop: "{{ hermes_python.files }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.path }}"
|
||||||
|
when: firewall_current is not search((item.path | regex_escape) ~ '\s*\n\s*\(Allow incoming')
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Turn the firewall on
|
||||||
|
ansible.builtin.command: "{{ socketfilterfw }} --setglobalstate on"
|
||||||
|
when: "'Firewall is enabled' not in firewall_current"
|
||||||
|
become: true
|
||||||
@@ -15,3 +15,17 @@
|
|||||||
name: "{{ homebrew_casks }}"
|
name: "{{ homebrew_casks }}"
|
||||||
state: present
|
state: present
|
||||||
tags: homebrew
|
tags: homebrew
|
||||||
|
|
||||||
|
- name: SSH key
|
||||||
|
ansible.posix.authorized_key:
|
||||||
|
user: "{{ ansible_user }}"
|
||||||
|
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_ed25519.pub') }}"
|
||||||
|
tags: ssh
|
||||||
|
|
||||||
|
- name: Power settings
|
||||||
|
ansible.builtin.import_tasks: power.yml
|
||||||
|
tags: power
|
||||||
|
|
||||||
|
- name: Firewall
|
||||||
|
ansible.builtin.import_tasks: firewall.yml
|
||||||
|
tags: firewall
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
- name: Read power settings
|
||||||
|
ansible.builtin.command: pmset -g custom
|
||||||
|
register: pmset_current
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Set power settings
|
||||||
|
ansible.builtin.command: pmset -a {{ item.key }} {{ item.value }}
|
||||||
|
loop: "{{ mac_pmset | dict2items }}"
|
||||||
|
when: >-
|
||||||
|
(pmset_current.stdout | regex_search('(?m)^\\s*' ~ item.key ~ '\\s+(\\S+)', '\\1')
|
||||||
|
| default([''], true) | first) != (item.value | string)
|
||||||
|
become: true
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
socketfilterfw: /usr/libexec/ApplicationFirewall/socketfilterfw
|
||||||
Reference in new issue
Block a user