Skip to content

Conversation

jaym
Copy link
Contributor

@jaym jaym commented Jul 16, 2025

DO NOT MERGE

  • Props are now namespaced to either a pack or query
  • Props on packs need to reference props through for
  • We will automatically make the for references if a pack does
    not define any props but includes queries with props

Examples:

packs:
  - uid: example1
    name: Example policy 1
    version: "1.0.0"
    authors:
      - name: Mondoo
        email: hello@mondoo.com
    groups:
      - title: group1
        filters: return true
        queries:
          - uid: variant-1
          - uid: variant-2
          - uid: variant-3
          - uid: variant-4
    props:
      - uid: userHome
        for:
          - uid: home
          - uid: homeDir
        mql: return "ex"

queries:
  - uid: variant-check
    title: Variant check
    variants:
      - uid: variant-1
      - uid: variant-2
      - uid: variant-3

  - uid: variant-1
    mql: props.home + " on 1"
    props:
      - uid: home
        mql: return "p1"

  - uid: variant-2
    mql: props.home + " on 2"
    props:
      - uid: home
        mql: return "p2"

  - uid: variant-3
    mql: props.homeDir + " on 3"
    props:
      - uid: homeDir
        mql: return "p3"

  - uid: variant-4
    mql: props.user + " is the user"
    props:
      - uid: user
        mql: return "ada"
go run ./apps/cnquery scan -f packprops.mql.yaml --json| jq .
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t": {
      "mrn": "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "ex on 1"
          }
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "ex on 2"
          }
        },
        "V/uj0v1oehI=": {
          "content": {}
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "ex on 3"
          }
        }
      }
    }
  }
}
go run ./apps/cnquery scan -f ~/Downloads/packprops.mql.yaml --json --props userHome="return 'foo'" | jq .
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2": {
      "mrn": "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "foo on 1"
          }
        },
        "OAKBq9so/78=": {
          "content": {}
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "foo on 2"
          }
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "foo on 3"
          }
        }
      }
    }
  }
}
# packprops2.mql.yaml
packs:
  - uid: example1
    name: Example policy 1
    version: "1.0.0"
    authors:
      - name: Mondoo
        email: hello@mondoo.com
    groups:
      - title: group1
        filters: return true
        queries:
          - uid: variant-1
          - uid: variant-2
          - uid: variant-3
          - uid: variant-4
queries:
  - uid: variant-check
    title: Variant check
    variants:
      - uid: variant-1
      - uid: variant-2
      - uid: variant-3

  - uid: variant-1
    mql: props.home + " on 1"
    props:
      - uid: home
        mql: return "p1"

  - uid: variant-2
    mql: props.home + " on 2"
    props:
      - uid: home
        mql: return "p2"

  - uid: variant-3
    mql: props.homeDir + " on 3"
    props:
      - uid: homeDir
        mql: return "p3"

  - uid: variant-4
    mql: props.user + " is the user"
    props:
      - uid: user
        mql: return "ada"
go run ./apps/cnquery scan -f ~/Downloads/packprops.mql.yaml --json --props home="return 'foo'" | jq .
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV": {
      "mrn": "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "foo on 1"
          }
        },
        "OAKBq9so/78=": {
          "content": {}
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "foo on 2"
          }
        },
        "SHIUM1ACvIk=": {
          "content": {}
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "p3 on 3"
          }
        }
      }
    }
  }
}

Copy link
Contributor

github-actions bot commented Jul 16, 2025

Test Results

4 360 tests  +2   4 356 ✅ +2   2m 7s ⏱️ -8s
  408 suites ±0       4 💤 ±0 
   30 files   ±0       0 ❌ ±0 

Results for commit b90b876. ± Comparison against base commit d5d0632.

♻️ This comment has been updated with latest results.

@jaym jaym changed the title Support properties being renamed to properties instead of queries Make properties work properly Jul 20, 2025
@jaym jaym marked this pull request as ready for review July 20, 2025 23:12
Copy link
Member

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Amazing update!! woooooot 🎉

nitpick 1

go run ./apps/cnquery scan -f packprops.mql.yaml --json --props userHome='return "foo"' | jq .

followed by the example output, where we can see that the default prop from the policy is being applied. Is the command not matching the output perhaps? (it look slike the command would override it with foo, just like in the example below)

nitpick 2

any reason to include variant-check in the last example?

@jaym
Copy link
Contributor Author

jaym commented Jul 23, 2025

I've fixed the comment for nitpick 1. I copied over the wrong command, it should not have any props in the CLI command.

variant-check should not be in the second example.

jaym and others added 4 commits July 23, 2025 09:37
- Props are now namespaced to either a pack or query
- Props on packs need to reference props through `for`
- We will automatically make the `for` references if a pack does
  not define any props but includes queries with props

Examples:
```yaml
packs:
  - uid: example1
    name: Example policy 1
    version: "1.0.0"
    authors:
      - name: Mondoo
        email: hello@mondoo.com
    groups:
      - title: group1
        filters: return true
        queries:
          - uid: variant-1
          - uid: variant-2
          - uid: variant-3
          - uid: variant-4
    props:
      - uid: userHome
        for:
          - uid: home
          - uid: homeDir
        mql: return "ex"

queries:
  - uid: variant-check
    title: Variant check
    variants:
      - uid: variant-1
      - uid: variant-2
      - uid: variant-3

  - uid: variant-1
    mql: props.home + " on 1"
    props:
      - uid: home
        mql: return "p1"

  - uid: variant-2
    mql: props.home + " on 2"
    props:
      - uid: home
        mql: return "p2"

  - uid: variant-3
    mql: props.homeDir + " on 3"
    props:
      - uid: homeDir
        mql: return "p3"

  - uid: variant-4
    mql: props.user + " is the user"
    props:
      - uid: user
        mql: return "ada"
```

```
go run ./apps/cnquery scan -f packprops.mql.yaml --json --props userHome='return "foo"' | jq .
```

```json
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t": {
      "mrn": "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tMfGA9ieUOgzgBdSMBNSEl6t": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "ex on 1"
          }
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "ex on 2"
          }
        },
        "V/uj0v1oehI=": {
          "content": {}
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "ex on 3"
          }
        }
      }
    }
  }
}
```

```
go run ./apps/cnquery scan -f ~/Downloads/packprops.mql.yaml --json --props userHome="return 'foo'" | jq .
```

```json
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2": {
      "mrn": "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tWggTTzYD0E1FDi20NmN4Bh2": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "foo on 1"
          }
        },
        "OAKBq9so/78=": {
          "content": {}
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "foo on 2"
          }
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "foo on 3"
          }
        }
      }
    }
  }
}
```

```
packs:
  - uid: example1
    name: Example policy 1
    version: "1.0.0"
    authors:
      - name: Mondoo
        email: hello@mondoo.com
    groups:
      - title: group1
        filters: return true
        queries:
          - uid: variant-1
          - uid: variant-2
          - uid: variant-3
          - uid: variant-4
queries:
  - uid: variant-check
    title: Variant check
    variants:
      - uid: variant-1
      - uid: variant-2
      - uid: variant-3

  - uid: variant-1
    mql: props.home + " on 1"
    props:
      - uid: home
        mql: return "p1"

  - uid: variant-2
    mql: props.home + " on 2"
    props:
      - uid: home
        mql: return "p2"

  - uid: variant-3
    mql: props.homeDir + " on 3"
    props:
      - uid: homeDir
        mql: return "p3"

  - uid: variant-4
    mql: props.user + " is the user"
    props:
      - uid: user
        mql: return "ada"
```

```
go run ./apps/cnquery scan -f ~/Downloads/packprops.mql.yaml --json --props home="return 'foo'" | jq .
```

```
{
  "assets": {
    "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV": {
      "mrn": "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV",
      "name": "planetexpress"
    }
  },
  "data": {
    "//explorer.api.mondoo.com/assets/309tniQ7vAYnVTMznDD7A94kqEV": {
      "values": {
        "FCEF4O8XoOs=": {
          "content": {
            "user.+": "ada is the user"
          }
        },
        "JvBACGPwF6o=": {
          "content": {}
        },
        "NsipGp24tRk=": {
          "content": {
            "home.+": "foo on 1"
          }
        },
        "OAKBq9so/78=": {
          "content": {}
        },
        "OU6YpdHiWPQ=": {
          "content": {
            "home.+": "foo on 2"
          }
        },
        "SHIUM1ACvIk=": {
          "content": {}
        },
        "yNnJGUyTSts=": {
          "content": {
            "homeDir.+": "p3 on 3"
          }
        }
      }
    }
  }
}
```
@jaym jaym merged commit 7566f91 into main Jul 30, 2025
17 checks passed
@jaym jaym deleted the jdm/props-v2 branch July 30, 2025 10:37
@github-actions github-actions bot locked and limited conversation to collaborators Jul 30, 2025
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.

2 participants