fleetdm / fleet

Open-source platform for IT, security, and infrastructure teams. (Linux, macOS, Chrome, Windows, cloud, data center)
https://fleetdm.com
Other
2.65k stars 379 forks source link

Uploaded package doesn't map to existing software title #19144

Open noahtalerman opened 1 month ago

noahtalerman commented 1 month ago

Fleet version: Unknown but likely an issue in Fleet 4.50. We decided not to resolve this in 4.50


💥  Actual behavior

Roberto: This has happened with a couple of apps already. Note how the installer is "Microsoft Edge", but after I install it, I have a different software title named "Microsoft Edge.app", from a different source:

image (31)

🧑‍💻  Steps to reproduce

  1. Upload Microsoft Edge (.pkg) to Fleet
  2. Install Microsoft Edge on a host

🕯️ More info (optional)

Discussion from Slack here (internal)

Noah: Is this a door we can’t walk back out of? Put differently, if we ship as-is and a user uploads Edge, will we be able to “squish” the two software titles into one title for them in a later release? If yes, I think we can ship as-is and file a bug so we can make a quick follow up to improve the matching.

Roberto: The matching is done in two places:

  1. when the user uploads the installer, we try to match installer metadata -> existing title, If we don't find any, we create a new one
  2. in a cron job, after getting host software via osquery we try to match incoming host software -> existing title. for software that was already uploaded, we can't do 1 easily anymore, so if that's what we need to tweak it'll be a bit challenging

Noah: Got it. So, if we were to ship as-is w/ a bug fix later, then we’d probably do two things:

Odds are we don’t get the matching perfectly even if we plugged all the gaps this release right?

So, even if we plugged all the gaps we know of now, I’m thinking it’s likely we’ll add something like that new cron to match uploaded software later.

🛠️ To fix

Improve version > title matching for macOS apps.

Improve name, bundle_identifier extraction. For name extraction get information in the following order of priority:

  1. bundle-version[0].bundle[0].path (extract from first <bundle-version> -> <bundle> -> path attribute)
  2. title
  3. product.id
  4. pkg-ref[0].id

For bundle ID extraction get information in the following order of priority:

  1. must-close[0].app[0].id extract from first <must-close> -> <app> -> id attribute)
  2. product.id
  3. pkg-ref[0].id
marko-lisica commented 1 month ago

Hey @roperzh, we decided to work on software title matching separately from VPP story. Can you take a look at "To fix" section of issue description.

It's mostly what we discussed yesterday during our call, with one change. Instead of merging title that's created via upload to osquery reported title, we would like to do reverse (merge osquery title to one that we created). What do you think about this approach?

Also, I spent some time and dug into many distribution.plist files for different apps, so I would like to update the extraction logic.

I found out that some apps have must-close element and bundle ID is always correct there. (e.g. in Zoom's package only correct bundle ID is inside the must-close element, that's why I would check that first and if not available, then go to the next one). Also, I found out that many packages have bundle element inside bundle-version element which has path attribute, which is usually <app_name>.app which I would use before the <title> element.

marko-lisica commented 1 month ago

@roperzh btw I used the format bundle-version[0].bundle[0].path which might not be correct but added an explanation of what should we read in parentheses.

roperzh commented 1 month ago

@marko-lisica sorry for the delay on this

It's mostly what we discussed yesterday during our call, with one change. Instead of merging title that's created via upload to osquery reported title, we would like to do reverse (merge osquery title to one that we created). What do you think about this approach?

this makes sense, we should reach out to you ASAP if we find any gotchas during the actual implementation, but I can't think of anything right now.

I found out that some apps have must-close element and bundle ID is always correct there. (e.g. in Zoom's package only correct bundle ID is inside the must-close element, that's why I would check that first and if not available, then go to the next one). Also, I found out that many packages have bundle element inside bundle-version element which has path attribute, which is usually .app which I would use before the element.</p> </blockquote> <p>This is awesome, thanks!</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/roperzh"><img src="https://avatars.githubusercontent.com/u/4419992?v=4" />roperzh</a> commented <strong> 3 weeks ago</strong> </div> <div class="markdown-body"> <p>A note in regards to <code>must-close</code> from the <a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html">docs</a></p> <blockquote> <p><strong>must-close</strong></p> <p>Identifies applications that must be closed before the package is installed.</p> </blockquote> <p>This seems a bit brittle to me.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/roperzh"><img src="https://avatars.githubusercontent.com/u/4419992?v=4" />roperzh</a> commented <strong> 2 weeks ago</strong> </div> <div class="markdown-body"> <p>@marko-lisica the script in the issue description wasn't working with a bunch of distribution files so I implemented a different approach.</p> <p>If you're interested and have any feedback, the unit tests here use real distribution files I extracted from different <code>pkg</code> installers and show the current output:</p> <p><a href="https://github.com/fleetdm/fleet/blob/a75c041be6d426acd4472d904436435f2322487b/pkg/file/xar_test.go#L170-L225">https://github.com/fleetdm/fleet/blob/a75c041be6d426acd4472d904436435f2322487b/pkg/file/xar_test.go#L170-L225</a></p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>