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

πŸ› fix core asset.labels + ✨ new asset.platformMetadata #5227

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

afiune
Copy link
Contributor

@afiune afiune commented Feb 14, 2025

The labels of an asset come from the asset itself, not the platform, but as some point
we made a mistake to use the platform labels, this PR is the first step to fix this issue.

In this PR we are:

  • Introducing a new field to the proto message asset.Platform.Metadata with the goal
    to give more clarity and avoid confusions with asset.Labels
  • We are deprecating asset.Platform.Labels in favor of asset.Platform.Metadata (this field
    will be remove in v12)
  • We are introducing a new asset.platformMetadata to the asset MQL schema, this
    new field will have the asset.Platform.Metadata
  • We are fixing the asset.labels MQL resource to have the actual asset labels but, we are
    going to merge this field with the platform labels for backwards compatibility

After merging this PR, we will start migrating the use of asset.Platform.Labels to
asset.Platform.Metadata, so that in v12 we can remove `asset.Platform.Labels.

@afiune afiune requested review from chris-rock and arlimus February 14, 2025 21:47
Copy link
Contributor

github-actions bot commented Feb 14, 2025

Test Results

3β€ˆ369 tests  +15   3β€ˆ365 βœ… +15   1m 37s ⏱️ -7s
β€‡β€ˆ392 suites + 1β€‚β€ƒβ€ƒβ€‡β€ˆβ€‡β€‡4 πŸ’€ ± 0 
β€‡β€ˆβ€‡30 files   ± 0β€‚β€ƒβ€ƒβ€‡β€ˆβ€‡β€‡0 ❌ ± 0 

Results for commit 274f071. ± Comparison against base commit 03ab221.

♻️ This comment has been updated with latest results.

@arlimus
Copy link
Member

arlimus commented Feb 14, 2025

Why did we use Platform.Labels before and what change does it make to switch to Asset.Labels? Are there different code paths that set these across different providers? I'm worried that with both fields existing we might run into similar problems again.

@chris-rock
Copy link
Member

I do some extra testing but this is what I discussed with @afiune as a solution. It stuck me that we use asset.Annotations but not asset.Labels. I am 99% sure the labels from platform are actually incorrect.

@arlimus
Copy link
Member

arlimus commented Feb 14, 2025

@chris-rock I asked @afiune to investigate the solution, so we make sure it doesn't break things. We shouldn't have both structures because it can lead to bugs like this one :)

@afiune
Copy link
Contributor Author

afiune commented Feb 15, 2025

Thank you both, I agree with @arlimus, if we don't use one, we should get rid of it.

I will do some digging and report back any findings.

@afiune afiune force-pushed the afiune/fix/core-asset-labels branch 3 times, most recently from 1b6975b to 155fb1f Compare February 15, 2025 23:04
@afiune
Copy link
Contributor Author

afiune commented Feb 17, 2025

@chris-rock @arlimus I found a few places where we are using asset.platform.labels, I can update the tests but I want to check with you both if this change is heading in the right direction, or not.

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Asset labels and platform labels have two different purposes and are not the same. We introduced platform labels to allow platform detection to add dynamic data that is not part of the normal go struct eg. windows uses that

if conn.Asset().Platform.Labels["windows.mondoo.com/product-type"] == "1" {
workstation = true
}
and
pf.Labels["windows.mondoo.com/product-type"] = productType
pf.Labels["windows.mondoo.com/display-version"] = current.DisplayVersion

Generally, asset labels are derived from the asset itself eg. EC2 instance tags and platform labels are operating system / platform specific, like Windows attaches specific information. I think the use of the same name 'labels' on two different structs leads to confusion as it is not always clear for new engineers what the difference is.

I think we should do the following:

  1. we expose platform labels as asset.platformMetadata on asset.
  2. we rename platform.Labels struct to platform.Metadata, which leads to less confusion

This would also require us to update the asset schema:

// General asset information
asset @defaults("name platform version") {
  // Human readable name of the asset
  name string
  // Platform for this asset (redhat, windows, k8s-pod)
  platform string
  // Version of the platform
  version string
  // Architecture this OS is running on
  arch string
  // Human-readable title of the platform (e.g., "Red Hat 8, Container")
  title string
  // List of platform families that this platform belongs to
  family []string
  // Fully qualified domain name (optional)
  fqdn string
  // Build version of the platform (optional)
  build string
  // Platform Metadata eg. key values from /etc/os/release
  platformMetadata map[string]string
  // Asset labels derived from the source system
  labels map[string]string
  // User-provided custom annotations (tags) on the asset
  annotations map[string]string
}

Since policies may depend on platform labels to be exposed on asset, we need to apply this migration into two steps:

  1. Introduce platformMetadata field
  2. Ensure all policies are migrated away to the new platformMetadata field
  3. Switch asset.Labels field over to asset.Labels from platform.Labels in v12

@@ -4,7 +4,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.2
// protoc v5.29.2
// protoc v5.29.3
Copy link
Member

Choose a reason for hiding this comment

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

Those updates should not be part of this PR since they distract the review.

// platform object we use for MVD
func NewMvdPlatform(pf *inventory.Platform) *Platform {
if pf == nil {
func NewMvdPlatform(asset *inventory.Asset) *Platform {
Copy link
Member

Choose a reason for hiding this comment

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

That is not correct. Mvd Platform is just a conversion of the platform object.

conn shared.Connection
platform *inventory.Platform
conn shared.Connection
asset *inventory.Asset
Copy link
Member

Choose a reason for hiding this comment

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

pkg managers do not need to know the asset information

The labels of an asset come from the asset itself, not the platform.

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
@afiune afiune force-pushed the afiune/fix/core-asset-labels branch from 155fb1f to 2138e1d Compare February 21, 2025 04:56
@afiune afiune changed the title πŸ› fix core asset.labels πŸ› fix core asset.labels + ✨ new asset.platformMetadata Feb 21, 2025
@afiune afiune force-pushed the afiune/fix/core-asset-labels branch from 363a056 to 1ac237d Compare February 21, 2025 20:28
We will merge `asset.Labels` and `asset.Platform.Labels` for backwards
compatibility.

Should be removed in v12 when we remove `asset.Platform.Labels`.

Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants