Skip to content
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

✨ add serial number to asset ids #4539

Merged
merged 7 commits into from
Sep 18, 2024
Merged

Conversation

slntopp
Copy link
Member

@slntopp slntopp commented Aug 12, 2024

No description provided.

Copy link
Contributor

github-actions bot commented Aug 12, 2024

Test Results

3 099 tests  ±0   3 098 ✅ ±0   1m 38s ⏱️ +9s
  371 suites +1       1 💤 ±0 
   28 files   ±0       0 ❌ ±0 

Results for commit ff8c8a6. ± Comparison against base commit 3dbfee7.

♻️ This comment has been updated with latest results.

@@ -161,6 +162,17 @@ func GatherPlatformInfo(conn shared.Connection, pf *inventory.Platform, idDetect
}, hostErr
}
return &PlatformInfo{}, nil
case idDetector == ids.IdDetector_SerialNumber:
serial, err := serialnumber.SerialNumber(conn, pf)
Copy link
Member

Choose a reason for hiding this comment

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

Have we tested that for macos, windows and linux?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is taken from the existing resource - machine.system.serial - which works on all aforementioned OS's
My tests so far show that the on the systems which don't provide that data (for example CI containers) serial evaluates to empty string, so it's omitted in the asset.ids

@@ -52,7 +53,7 @@ func IdentifyPlatform(conn shared.Connection, p *inventory.Platform, idDetectors
// fallback to default id detectors
switch conn.Type() {
case shared.Type_Local:
idDetectors = []string{ids.IdDetector_Hostname, ids.IdDetector_CloudDetect}
idDetectors = []string{ids.IdDetector_Hostname, ids.IdDetector_SerialNumber, ids.IdDetector_CloudDetect}
Copy link
Member

Choose a reason for hiding this comment

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

I think we want to do some more real-life testing before we enable this as default.

Copy link
Member Author

Choose a reason for hiding this comment

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

As expected, if host can't provide serial name - it's just returned empty, therefore is not used as asset id.
Asset id is actually asset.ids, so server seeks for and uses the id server prefers (hostname at the moment).
If asset returns two or more ids this doesn't influence existing processes.

Tested on:

  • MacOS
  • Darwin Container
  • Linux Container
  • Linux Desktop
  • Windows Desktop
  • Windows VM

@vjeffrey
Copy link
Contributor

i tested this pr by running a scan on my local mac, changing my hostname, and then scanning again. the hostname value was updates as expected but i had the same serial number recorded in both cases (as expected).
i was testing to see if there any problems reporting in to the server if we report diff hostnames along with the serial id, and i didnt run into any issues
@jaym just for peace of mind, can you confirm it's fine to have two assets reporting in that have one asset id that is the same and one asset id that is different?

@jaym
Copy link
Contributor

jaym commented Sep 5, 2024

just for peace of mind, can you confirm it's fine to have two assets reporting in that have one asset id that is the same and one asset id that is different?

No that does not seem ok.

Here's a scenario. We have an asset A with platform id a that has scanned. Then we have an asset B with platform id b that has scanned.

Now, asset A scans with [a, shared]. It is successful. If asset B scans with [b,shared] it will fail because it matches asset B through platform id b and asset A through platform id shared.

@slntopp
Copy link
Member Author

slntopp commented Sep 7, 2024

Isn't detectors (therefore ids) order predefined?

@atomic111
Copy link
Member

@slntopp @vjeffrey

Can we read the asset name from

scutil --get ComputerName

Because then the hostname is not changing.

@slntopp
Copy link
Member Author

slntopp commented Sep 12, 2024

@atomic111 id detectors aren't OS specific and using existing resources from os provider where they can, so i'm not sure about this one.
Using serial number seems better either way, because unlike hostname it can't be changed on any platform

@atomic111
Copy link
Member

@jaym when can we merge this

@jaym
Copy link
Contributor

jaym commented Sep 13, 2024

I think we need a way to prioritize platform ids if we want to take this change, otherwise it will be a breaking change. We will get into a state where if there are already duplicate representations of an asset where the hostname is flopping around, it will succeed once with a specific hostname in the platform id. Once it comes back with a different hostname in the platform id, the asset will not be able to scan

@slntopp slntopp force-pushed the mik/add-serial-number-to-asset-ids branch from 1d319fd to 591d726 Compare September 18, 2024 16:04
@slntopp slntopp force-pushed the mik/add-serial-number-to-asset-ids branch from 42078e0 to ff8c8a6 Compare September 18, 2024 16:25
@vjeffrey vjeffrey merged commit 5e5e620 into main Sep 18, 2024
15 checks passed
@vjeffrey vjeffrey deleted the mik/add-serial-number-to-asset-ids branch September 18, 2024 19:24
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2024
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.

5 participants