Skip to content

Conversation

jaym
Copy link
Contributor

@jaym jaym commented Jul 16, 2025

DO NOT MERGE

  • Props are now namespaced to either a policy or query
  • Props on policies 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:

# props.mql.yaml
policies:
  - 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-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/cnspec scan -f props.mql.yaml
home.+: "ex on 1"
home.+: "ex on 2"
homeDir.+: "ex on 3"
user.+: "ada is the user"
go run ./apps/cnspec scan -f props.mql.yaml --props userHome="return 'foo'"
homeDir.+: "foo on 3"
user.+: "ada is the user"
home.+: "foo on 1"
home.+: "foo on 2"
# props.mql.yaml
policies:
  - 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-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/cnspec scan -f props.mql.yaml
home.+: "p2 on 2"
home.+: "p1 on 1"
homeDir.+: "p3 on 3"
user.+: "ada is the user"
go run ./apps/cnspec scan -f props.mql.yaml --props home="return 'foo'"
home.+: "foo on 2"
homeDir.+: "p3 on 3"
user.+: "ada is the user"
home.+: "foo on 1"

Copy link
Contributor

github-actions bot commented Jul 16, 2025

Test Results

  1 files   28 suites   1m 19s ⏱️
520 tests 519 ✅ 1 💤 0 ❌
521 runs  520 ✅ 1 💤 0 ❌

Results for commit 0b03bb7.

♻️ This comment has been updated with latest results.

@jaym jaym changed the title Prep work to support v2 policies Make properties work properly Jul 20, 2025
@jaym jaym marked this pull request as ready for review July 21, 2025 08:54
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!! ditto as mondoohq/cnquery#5795

@jaym jaym force-pushed the jdm/props-v2 branch 3 times, most recently from 63226df to a5df6e2 Compare July 30, 2025 11:11
- Props are now namespaced to either a policy or query
- Props on policies 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
policies:
  - 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-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/cnspec scan -f props.mql.yaml
```

```
home.+: "ex on 1"
home.+: "ex on 2"
homeDir.+: "ex on 3"
user.+: "ada is the user"
```

```
go run ./apps/cnspec scan -f props.mql.yaml --props userHome="return 'foo'"
```

```
homeDir.+: "foo on 3"
user.+: "ada is the user"
home.+: "foo on 1"
home.+: "foo on 2"
```

```yaml
policies:
  - 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-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/cnspec scan -f props.mql.yaml
```

```
home.+: "p2 on 2"
home.+: "p1 on 1"
homeDir.+: "p3 on 3"
user.+: "ada is the user"
```

```
go run ./apps/cnspec scan -f props.mql.yaml --props home="return 'foo'"
```

```
home.+: "foo on 2"
homeDir.+: "p3 on 3"
user.+: "ada is the user"
home.+: "foo on 1"
```
@jaym jaym merged commit 72359ac into main Jul 31, 2025
22 of 23 checks passed
@jaym jaym deleted the jdm/props-v2 branch July 31, 2025 18:05
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 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