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

update: print JSON version output by using json_output config field #2351

Merged
merged 12 commits into from
Jan 15, 2023

Conversation

jasondellaluce
Copy link
Contributor

@jasondellaluce jasondellaluce commented Jan 12, 2023

What type of PR is this?

/kind cleanup

/kind feature

Any specific area of the project related to this PR?

/area engine

/area tests

What this PR does / why we need it:

This PR proposes removing the recently-introduced version-json CLI option and makes Falco print a JSON version output depending on the json_output configuration field such as follows:

# userspace/falco/falco --version 
Falco version: 0.33.1-111+faa878d
Libs version:  0.10.0
Plugin API:    2.0.0
Engine:        15
Driver:
  API version:    3.0.0
  Schema version: 3.0.0
  Default driver: 4.0.0+driver
# userspace/falco/falco --version -o json_output=true
{"default_driver_version":"4.0.0+driver","driver_api_version":"3.0.0","driver_schema_version":"2.0.0","engine_version":"15","falco_version":"0.33.1-111+faa878d","libs_version":"0.10.0","plugin_api_version":"2.0.0"}

The goal here is to avoid duplication of UX elements, since json_output is already used other Falco features to control whether the output is in plain text of JSON format.

Which issue(s) this PR fixes:

Special notes for your reviewer:

This PR can be the first of a series where we make every Falco output support a JSON format depending on the json_output configuration. In the past, that field was only used to control the JSON formatting of the alert outputs, and it recently was also used to output the result of rule files validation in JSON format. Since we now have a third use case, I think in the future we might use json_output to make every Falco output formatted as JSON and thus machine-readable.

Also, this PR refactors a little bit the falco_configuration class (responsible of ~250 LOC to preserve the git blame), which can not be initialized and supports a more explicit default state. Moreover, loading the configuration has been moved as the first action performed by Falco, so that all actions can rely on configuration fields (such as json_output). Accordingly, blocking validation checks (such as requiring at least one enabled output or at least one rules file) are moved in their own action, so that early actions such as print_version are not blocked and can proceed even with an empty configuration.

Does this PR introduce a user-facing change?:

update: print JSON version output when json_output is enabled

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

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>
…zation

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

/milestone 0.34.0

@poiana poiana added this to the 0.34.0 milestone Jan 12, 2023
@jasondellaluce jasondellaluce changed the title wip: update: print JSON version output by using json_output config field update: print JSON version output by using json_output config field Jan 12, 2023
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Minor comments/questions aside, LGTM!

userspace/falco/app_actions/init_outputs.cpp Outdated Show resolved Hide resolved
userspace/falco/app_actions/load_config.cpp Show resolved Hide resolved
userspace/falco/application.cpp Show resolved Hide resolved
@FedeDP
Copy link
Contributor

FedeDP commented Jan 13, 2023

Perhaps @LucaGuerra is interested, because he made the version-json change ;)

…gured

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

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jan 13, 2023

LGTM label has been added.

Git tree hash: a2a250a200f96d737b0ec0a5f650b234c7aedab8

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jan 15, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, jasondellaluce

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:
  • OWNERS [Andreagit97,FedeDP,jasondellaluce]

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

@poiana poiana merged commit c69b198 into master Jan 15, 2023
@poiana poiana deleted the update/json-outputs branch January 15, 2023 17:30
@happy-dude
Copy link
Contributor

happy-dude commented Jan 19, 2023

Can there be an additional documentation update that makes it clear that json_output influences the --version flag? ref: https://falco.org/docs/reference/daemon/config-options/

This was surprising to me initially when pulling in the latest upstream changes because I expected json_output to only influence the output of the falco_events / alerts / logs; I did not expect this option to influence the output of --version.

(My confusion was also compounded a user runs falco --version and doesn't have permissions to read /etc/falco/falco.yaml, so their output appeared as what I was familiar with whereas a script executing w/ the right context/permissions had the output in JSON.)

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.

5 participants