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

Follow CLI args standards in Falco #3049

Open
Tracked by #3148
incertum opened this issue Feb 1, 2024 · 14 comments
Open
Tracked by #3148

Follow CLI args standards in Falco #3049

incertum opened this issue Feb 1, 2024 · 14 comments
Assignees
Milestone

Comments

@incertum
Copy link
Contributor

incertum commented Feb 1, 2024

Proposing to follow common and standard Program Argument Syntax Conventions for Falco's CLI options, for example see this resource. For example -pk and similar options seem to fall outside of these conventions.

@incertum incertum changed the title Follow standard CLI args standards in Falco Follow CLI args standards in Falco Feb 1, 2024
@Andreagit97 Andreagit97 added this to the 0.38.0 milestone Feb 1, 2024
@GLVSKiriti
Copy link

@Andreagit97 @incertum I am interested in this issue!
Can I work on this?

@Andreagit97
Copy link
Member

Not clear to me what was the plan @incertum had in mind when she opened this issue, so I'll let her answer here.
My 2 cents, this issue seems related to possible breaking changes in the Falco UX, maybe something that we want to tackle for Falco 1.0.0, not sure this is a "good first issue" but let's see what others think about that

@incertum
Copy link
Contributor Author

Goal is to correct the -pc, -pk or -pcontainer, -pkubernetes flags that do not conform to standard CLI practices. Usually -pc implies a combination of -p and -c.

https://falco.org/docs/outputs/formatting/

("p,print", "Print (or replace) additional information in the rule's output.\nUse -pc or -pcontainer to append container details.\nUse -pk or -pkubernetes to add both container and Kubernetes details.\nIf using gVisor, choose -pcg or -pkg variants (or -pcontainer-gvisor and -pkubernetes-gvisor, respectively).\nIf a rule's output contains %container.info, it will be replaced with the corresponding details. Otherwise, these details will be directly appended to the rule's output.\nAlternatively, use -p <output_format> for a custom format. In this case, the given <output_format> will be appended to the rule's output without any replacement.", cxxopts::value(print_additional), "<output_format>")

I would propose them being:

  • -pc -> --print-container and --print-container-gvisor or similar
  • -pk -> --print-kubernetes and --print-kubernetes-gvisor or similar

Suggesting to sync with @leogr.

@leogr
Copy link
Member

leogr commented Mar 14, 2024

Usually -pc implies a combination of -p and -c.

This is the main issue, likely.

If we follow POSIX's recommendation:

Multiple options may follow a hyphen delimiter in a single token if the options do not take arguments. Thus, ‘-abc’ is equivalent to ‘-a -b -c’.

So, -pc is not ok.

But:

An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, -o foo and -ofoo are equivalent.

So -pcontainer is equivalent to -p container and it would be ok (and it is what's happening here).

My recommendation is to reaudit all flags, and try to make them consistent with POSIX.
The cobra project may be a source of inspiration. Also, if we follow Cobra/posix recommendations, we will have consistency across all our other tools (which are implemented in Go).

Let's dig deeper into this once we have found some time.

@incertum
Copy link
Contributor Author

Agreed @leogr let's investigate more. It's something valuable for Falco 1.x.

@LucaGuerra
Copy link
Contributor

/milestone 1.0.0

@poiana
Copy link
Contributor

poiana commented Aug 14, 2024

Issues go stale after 90d of inactivity.

Mark the issue as fresh with /remove-lifecycle stale.

Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Provide feedback via https://github.com/falcosecurity/community.

/lifecycle stale

@leogr
Copy link
Member

leogr commented Aug 20, 2024

/remove-lifecycle stale

@leogr
Copy link
Member

leogr commented Aug 28, 2024

/assign @LucaGuerra

@poiana
Copy link
Contributor

poiana commented Nov 26, 2024

Issues go stale after 90d of inactivity.

Mark the issue as fresh with /remove-lifecycle stale.

Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Provide feedback via https://github.com/falcosecurity/community.

/lifecycle stale

@leogr
Copy link
Member

leogr commented Dec 10, 2024

/remove-lifecycle stale

@LucaGuerra as privately discussed we are close to finish this, keep as posted 🙏

@leogr
Copy link
Member

leogr commented Dec 10, 2024

@LucaGuerra
Copy link
Contributor

LucaGuerra commented Jan 13, 2025

So these are the potential issues that I see:

  • We introduced the possibility of adding a comma , in some options, such as -o field={"opt1": "val1", "opt2": "val2"} this is not technically compliant because according to the recommendations -o a=b,c should be the same as -o a=b -o c. I think it's convenient to have commas so it's fine if we do not follow the recommendations there. Anyone disagrees?
  • -pk and friends should go away in 1.x . In order to do this we need two separate things:
    • get rid of %container.info in the rules OR have a different way of specifying it. Note that without the effect of -pk/-pc it will become a syntax error in the rules so it will break existing behavior.
    • convert all -pk/-pc usage into appropriate configuration options or CLI flags, which we basically can already do.

@leogr
Copy link
Member

leogr commented Jan 13, 2025

So these are the potential issues that I see:

  • We introduced the possibility of adding a comma , in some options, such as -o field={"opt1": "val1", "opt2": "val2"} this is not technically compliant because according to the recommendations -o a=b,c should be the same as -o a=b -o c. I think it's convenient to have commas so it's fine if we do not follow the recommendations there. Anyone disagrees?

I believe the examples you provided can't be correlated because of a missing detail. AFAIK, the recommendation does not allow spaces in the option's value. This is particularly relevant when commas are involved.
For example, while -o a=b,c is equivalent to -o a=b -o c, -o a=b, c (note the space after the command) is not and should be considered as a="b, c" (or not allowed). Likewise, -o field={"opt1": "val1", "opt2": "val2"} may be compliant (because of the space after the comma), whereas -o field={"opt1": "val1","opt2": "val2"} is not for sure.

Helm --set command fully supports this (perhaps just by chance) as per their examples 👇

Lists can be expressed by enclosing values in { and }. For example, --set name={a, b, c} translates to:

name:
  - a
  - b
  - c

and

Multiple values can be set this way. The line --set servers[0].port=80,servers[0].host=example becomes:

servers:
  - port: 80
    host: example

So, in the end, I totally agree to support -o field={"opt1": "val1", "opt2": "val2"} (with the space after the comma), but I'm not fully convinced of the general case yet. I believe we should dig more into this and make the whole configuration system more solid.

Furthermore, what about the escaping? For example, do we support something like Helm's --set nodeSelector."kubernetes\.io/role"=master ?

  • -pk and friends should go away in 1.x . In order to do this we need two separate things:

    • get rid of %container.info in the rules OR have a different way of specifying it. Note that without the effect of -pk/-pc it will become a syntax error in the rules so it will break existing behavior.
    • convert all -pk/-pc usage into appropriate configuration options or CLI flags, which we basically can already do.

I'm in favor of getting rid of both -p* and %container.info in 1.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants