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

support arbitrary-depth nested values in YAML configuration #1792

Merged

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind design

/kind feature

Any specific area of the project related to this PR?

/area engine

/area tests

What this PR does / why we need it:
Falco loads its configuration from a YAML file. However, we currently support fields with a maximum depth of 2. Fields nested after the second level are not reachable programmatically. This is a limiter for future features and contributions. At the same time, the current code only loads the configuration from file, which makes it impossible to write unit tests for the configuration loader.

This PR introduces a representation-agnostic notation to access configuration fields, independently from their level of nesting and from their underlying representation (YAML or others). Accordingly, the yaml_configuration class has been slightly refactored to address this changes.

Unit tests have been implement to assert that everything works as expected.

Which issue(s) this PR fixes:

Special notes for your reviewer:
The newly proposed syntax for accessing config fields resembles the way nested objects are accessed in JSON. Consider the following YAML file:

base:
  id: 1
  subvalue:
    subvalue2:
      name: 'test'
  list:
    - elem1
    - elem2

Each field can be accessed as:

base.id
base.subvalue.subvalue2.name
base.list[0]
base.list[1]

Does this PR introduce a user-facing change?:

update(userspace/falco): support arbitrary-depth nested values in YAML configuration

This is a change of direction from the current design, that imposes loading
the configuration from file only, and in the object constructor. Instead,
yaml_configuration objects can now be reused ad can load the YAML config
from either file or string. This also makes it easier to unit test this class.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Since now, the maximum depth supported to access config fields is two.
This adds support for accessing fields of arbitrary nesting depth.
A formal grammar has been explicited for the regular language representing
the field keys. The accessor methods have been updated accordingly.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…node

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

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

/approve

whoa! 👏

@poiana poiana added the lgtm label Dec 3, 2021
@poiana
Copy link
Contributor

poiana commented Dec 3, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jasondellaluce, leogr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
Copy link
Contributor

poiana commented Dec 3, 2021

LGTM label has been added.

Git tree hash: d13411f968ca63f8443fa1075da6c9e33e6ecc12

@poiana poiana added the approved label Dec 3, 2021
@leogr
Copy link
Member

leogr commented Dec 3, 2021

/milestone 0.31.0

@poiana poiana added this to the 0.31.0 milestone Dec 3, 2021
Copy link
Contributor

@mstemm mstemm left a comment

Choose a reason for hiding this comment

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

Looks like a valuable change. It's very similar to json pointers, but for yaml!

@poiana poiana merged commit c005af2 into falcosecurity:master Dec 6, 2021
@jasondellaluce jasondellaluce deleted the update/nested-config-options branch December 9, 2021 08:26
jasondellaluce added a commit that referenced this pull request Jan 12, 2022
This fixes the parser introduced in #1792.
Now, nested fields such as `arr[1].subval` are supported, whereas the parser used
to recognize the `.` as an unexpected character.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
poiana pushed a commit that referenced this pull request Jan 17, 2022
This fixes the parser introduced in #1792.
Now, nested fields such as `arr[1].subval` are supported, whereas the parser used
to recognize the `.` as an unexpected character.

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants