fix(device): report the configured macOS hostname, not kern.hostname - #229
Open
swarit-stepsecurity wants to merge 3 commits into
Open
swarit-stepsecurity wants to merge 3 commits into
swarit-stepsecurity wants to merge 3 commits into
Conversation
With no HostName set, macOS rewrites kern.hostname from DHCP or reverse DNS on every network change, so a Mac on a VPN resolving through AWS reported ip-…ec2.internal on some scans and its real name on others. Prefer scutil HostName, then LocalHostName, then os.Hostname. Signed-off-by: Swarit Pandey <swarit@stepsecurity.io>
Read HostName and LocalHostName from preferences.plist, the file scutil itself reads, so the common case spawns no subprocess. The layout is not a documented contract, so scutil stays as the fallback. Signed-off-by: Swarit Pandey <swarit@stepsecurity.io>
Member
Author
|
@ashishkurmi can you please add copilot review to this PR? Thanks. This basically reads hostname from |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
macOS devices were flip-flopping between their real name and
ip-…ec2.internal. We reportedos.Hostname(), which on macOS iskern.hostname; with noHostNameset, macOS rewrites it from DHCP or reverse DNS on every network change, so a VPN resolving through AWS renamed the Mac on some scans. The backend stores whatever the latest scan sends, so the device list followed it.On macOS the agent now reports
HostNamewhen an admin has set one, elseLocalHostName. Both are read from/Library/Preferences/SystemConfiguration/preferences.plist(the filescutilreads, parsed with the existinghowett.net/plistdependency), withscutil --getas the fallback since that layout isn't a documented contract, andos.Hostname()last. Windows and Linux are unchanged. Devices are keyed by serial (RegisteredDevicesv1iscustomer_id+device_id), so existing Macs rename once without duplicating; nothing in agent-api keys, matches or notifies on hostname.Type of change
Testing
make lintmake test, plusmake smokeand linux/darwin/windows cross-compiles