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

added validation function for config keys #3004

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

h4l0gen
Copy link

@h4l0gen h4l0gen commented Jan 10, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

/kind release

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area engine

/area tests

/area proposals

/area CI

What this PR does / why we need it:
This PR checks for existing configuration keys in falco.yaml.
Which issue(s) this PR fixes:
Emit a warning when trying to set a non-existing config key #2924

Fixes #2924

Special notes for your reviewer:
I'd like to discuss the available configuration options that I added in the fixed.yaml schema.
Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link

poiana commented Jan 10, 2024

Welcome @h4l0gen! It looks like this is your first PR to falcosecurity/falco 🎉

@poiana poiana added the size/L label Jan 10, 2024
@Andreagit97
Copy link
Member

ei @h4l0gen thank you for this! We will try to take a look ASAP! We are in the middle of Falco 0.37.0 release so we could have a little delay with the review of new PRs

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.

Hey,

I quickly looked at this, and it is a great starting point! Thank you.

First thing that came to my mind is: Could we relay on some more formal validation mechanism (like https://json-schema.org/specification) instead of just having fixed.yaml with all default values? 🤔

IIRC, YAML can be validated using a json-schema (cc @jasondellaluce @LucaGuerra )

Also left a comment (see below)

}
void falco_configuration::load_yaml(const std::string& config_name, const yaml_helper& config)
{
YAML::Node fixedSchema = YAML::LoadFile("userspace/falco/fixed.yaml");
Copy link
Member

Choose a reason for hiding this comment

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

This can work only when in development mode. A better solution would be to embed the file into the Falco binary so as not to load an external file at runtime.

Copy link
Author

Choose a reason for hiding this comment

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

hey @leogr,
Thanks for reviewing. I will embed file into Falco binary and along with that try to find other validation mechanisms too.

@FedeDP
Copy link
Contributor

FedeDP commented Jan 17, 2024

Could we relay on some more formal validation mechanism (like https://json-schema.org/specification) instead of just having fixed.yaml with all default values?

Fully agree with this one! We already have the valijson dep from libs: https://github.com/falcosecurity/libs/blob/master/cmake/modules/valijson.cmake and is being used by plugins to validate init config schema, if set by the plugin API: https://github.com/falcosecurity/libs/blob/48277b17e1cd906ec9faec7fa45bc9b795e66fc1/userspace/libsinsp/plugin.cpp#L678; i think we can do something similar?

@FedeDP
Copy link
Contributor

FedeDP commented Jan 17, 2024

valijson ships also a yaml-cpp adapter; here is an example: https://github.com/tristanpenman/valijson/blob/master/tests/test_yaml_cpp_adapter.cpp and here is the code: https://github.com/tristanpenman/valijson/blob/master/include/valijson/adapters/yaml_cpp_adapter.hpp

@Andreagit97 Andreagit97 added this to the 0.38.0 milestone Jan 17, 2024
@h4l0gen
Copy link
Author

h4l0gen commented Jan 18, 2024

Thank you for the suggestions, @leogr and @FedeDP . I am working on it.

@h4l0gen
Copy link
Author

h4l0gen commented Jan 24, 2024

Hey @Andreagit97 @leogr @FedeDP, I have included Valijson and utilized the YAML-CPP adapter. Please take a look and provide any suggestions or corrections if I have made any mistakes. Thank you!!

#include <re2/re2.h>

#include "valijson/adapters/yaml_cpp_adapters.hpp"
#include "ValidationUtils.h"
Copy link
Member

@leogr leogr Jan 25, 2024

Choose a reason for hiding this comment

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

Where does ValidationUtils.h come from? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for this, @leogr. I forgot to commit the ValidationUtils.h file 😅. This header file is being used for the validateKeysRecursive function.

Copy link
Author

Choose a reason for hiding this comment

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

Hey @leogr , could you please take a look at this PR so that we can finish our work on it?

@h4l0gen h4l0gen force-pushed the kapil branch 2 times, most recently from fce2570 to 96cc234 Compare January 25, 2024 18:14
@h4l0gen
Copy link
Author

h4l0gen commented Feb 11, 2024

Hey @leogr, could you please review this PR again? It would be greatly appreciated, and we can then finish our work on this issue.

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.

Hey @leogr, could you please review this PR again? It would be greatly appreciated, and we can finish our work on this issue.

The valijson version we are pulling via libs is v0.6 (which does not come with the yaml adapter). So, to make this work, we must first try to update valijson in libs (0.7 or later) (@LucaGuerra @FedeDP can you take a look at that?)

@h4l0gen, meanwhile, I suggest you clean up this PR by removing all now unnecessary stuff (e.g., userspace/falco/fixed.yaml and possibly other stuff). Also, rebase on top of the latest master. Thank you!

@@ -183,6 +184,45 @@ void falco_configuration::load_engine_config(const std::string& config_name, con
m_changes_in_engine_config = true;
}


std::vector<std::string> fixedSchemaKeysVec = {
Copy link
Member

Choose a reason for hiding this comment

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

Since we are going to use valijson, do we still need this?

@@ -0,0 +1,161 @@
rules_file:
Copy link
Member

Choose a reason for hiding this comment

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

I guess this file is not needed anymore.

@leogr
Copy link
Member

leogr commented Feb 23, 2024

@h4l0gen

As an example, this is a schema file describing the rules YAML files format: https://github.com/falcosecurity/falco-playground/blob/main/src/components/Editor/falcoSchema.json

We basically need something similar for the falco.yaml config.

@h4l0gen
Copy link
Author

h4l0gen commented Feb 23, 2024

Okay, thanks @leogr . I will implement this change.

@poiana poiana added size/M and removed size/L labels Feb 25, 2024
Signed-off-by: h4l0gen <ks3913688@gmail.com>
Signed-off-by: h4l0gen <ks3913688@gmail.com>
Signed-off-by: h4l0gen <ks3913688@gmail.com>
Signed-off-by: h4l0gen <ks3913688@gmail.com>
Signed-off-by: h4l0gen <ks3913688@gmail.com>
Signed-off-by: h4l0gen <ks3913688@gmail.com>
This reverts commit 1373bb2.

Signed-off-by: h4l0gen <ks3913688@gmail.com>
This reverts commit d809cbe.

Signed-off-by: h4l0gen <ks3913688@gmail.com>
This reverts commit 9fec747.

Signed-off-by: h4l0gen <ks3913688@gmail.com>
@h4l0gen h4l0gen reopened this Mar 8, 2024
@poiana
Copy link

poiana commented Mar 8, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: h4l0gen
Once this PR has been reviewed and has the lgtm label, please assign jasondellaluce for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

1 similar comment
@poiana
Copy link

poiana commented Mar 8, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: h4l0gen
Once this PR has been reviewed and has the lgtm label, please assign jasondellaluce for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 poiana added size/XL and removed size/XS labels Mar 8, 2024
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
@Andreagit97
Copy link
Member

Andreagit97 commented Mar 11, 2024

I added again the commits but it seems that now the CI is broken for another reason 😮‍💨 i will take a look ASAP!

@h4l0gen h4l0gen changed the title wip: added validation function for config keys added validation function for config keys Apr 21, 2024
@FedeDP
Copy link
Contributor

FedeDP commented May 15, 2024

/milestone 0.39.0

@poiana poiana modified the milestones: 0.38.0, 0.39.0 May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Emit a warning when trying to set a non-existing config key
5 participants