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

Exposing some of the hidden packages behind internal folder. #1094

Closed
s3rj1k opened this issue Jul 11, 2024 · 21 comments
Closed

Exposing some of the hidden packages behind internal folder. #1094

s3rj1k opened this issue Jul 11, 2024 · 21 comments

Comments

@s3rj1k
Copy link

s3rj1k commented Jul 11, 2024

I think that this internal folder that hides most of exported modules is an unfortunate situation.

Consider a use-case when someone wants to make a rules parser to help migrate off libmodsecurity, in current state this can only be done by actually launching waf via NewWAF function, this works but is a bit uncomfortable.

Furthermore, considering the case above, when broken rule is encountered, in some cases, error message is so obscured with error wrapping and lacks the actual information that can help to find the actual broken rule as opposed to how libmodsecurity reports parse errors (with partial rule and file:linenumber).

By exposing so of the internal packages to public it will allow to reuse them more comfortably and will help improve error messaging, at least there will be no multiple/useless error wrapping for parser code.

@jptosso
Copy link
Member

jptosso commented Jul 12, 2024

Hey! The reason behind this is long-term maintenance; if you want a specific API or set of APIs, please mention them on this issue so we can review this. We don't have any problem with exposing additional APIs as long as it's safe, it doesn't break compatibility, and there is a clear use case.

There are certain limitations, for example, we cannot expose additional functions for existing immutable interfaces, as it breaks compatibility. In which case we would have to release Wrappers to access to them. Like:

tx := tx.(types.TransactionState)
tx = tx.(otherpackage.TransactionExtended)

@s3rj1k
Copy link
Author

s3rj1k commented Jul 12, 2024

In my case described above I guess I would want access to:

  • corazawaf.NewWAF()
  • seclang.NewParser()
  • parser.FromString()

@fzipi
Copy link
Member

fzipi commented Jul 12, 2024

Do you want to create a new parser, or just add some directives?

@s3rj1k
Copy link
Author

s3rj1k commented Jul 12, 2024

No, some utility that checks rules validity and has a bit more verbose error messages in regards to where the actual broken rule is (file:linenumber).

@jcchavezs
Copy link
Member

jcchavezs commented Jul 15, 2024 via email

@s3rj1k
Copy link
Author

s3rj1k commented Jul 15, 2024

@jptosso Another solution maybe just standalone CLI utility in repository that just loads ruleset and reports error if any, I am fine with doing PRs as long as there is some kind of simplified entry point for rule testing that is.

Also this will be similar to what has libmodsecurity, they ship standalone CLI to just do rule verification.

This way there is no need to wraparound into experimental API.

@jcchavezs
Copy link
Member

jcchavezs commented Jul 15, 2024 via email

@s3rj1k
Copy link
Author

s3rj1k commented Jul 15, 2024

@jptosso Yea, sounds also good

@jcchavezs
Copy link
Member

@guydc
Copy link

guydc commented Feb 4, 2025

+1 for exposing the parser.

Use cases:

  • pre-validation of rules
  • creating a manifest of ruleset contents which makes it easier to manage modifications (e.g. changes and removals by rule id)

@jcchavezs
Copy link
Member

I am inclined to export the parse but I would expect to have implementation code using this.

@guydc
Copy link

guydc commented Feb 6, 2025

I am inclined to export the parse but I would expect to have implementation code using this.

Do you mean like the example in the PR that you referred to?

BTW, the current proposal in the PR doesn't expose the rules themselves, but only a parsing error if it occurred. Exposing the rules is beneficial for users that build ruleset management systems.

@s3rj1k
Copy link
Author

s3rj1k commented Feb 6, 2025

@guydc You can just rsync the whole thing really, I don't understand all the hesitation of upstream devs about moving packages out of internal folder.

@jcchavezs
Copy link
Member

jcchavezs commented Feb 11, 2025

@guydc You can just rsync the whole thing really, I don't understand all the hesitation of upstream devs about moving packages out of internal folder.

Coraza is a volunteering project and more public packages mean more maintenance, more bugs and more constraints when refactoring internals hence the hesitation.

I have worked for 9 years in OSS now and if I would get a dollar every time someone said "export this internal because I need it" and then that person never came back or showed how the big refactor benefit them I would probably be able to have a nice trip to Disneyland Paris this April.

Finally I learnt from a OSS master long ago that user must "request for the feature, not for the implementation". Do you need certain functionality? bring in the use case, show us code where the API is lacking and we can discuss how to fix it, requesting a package to be exported is a not feature but an implementation detail. Do you need for us to expose the rules? fine, show us what do you need and what would be the information you need. We don't have to expose internal objects for that, we can build a new abstraction that will work for you keeping the internals internal.

You can even come up with a draft PR instead that proves value so we can support the use case. Would you spend your volunteering time reworking and API (and the future maintenance of it) just by trusting me saying "I need it"?

Don't take me wrong, I love users requesting for features but as you could imagine we would not spend our own time working for a user desire but instead a use case that can benefit the community.

So, show us the use case and we will happily lead the feature to completion.

@s3rj1k
Copy link
Author

s3rj1k commented Feb 11, 2025

Coraza is a volunteering project and more public packages mean more maintenance, more bugs and more constraints when refactoring internals hence the hesitation.

You can handle that by stating in docs that no support is given and no compatibility promises for modules in that list.

@s3rj1k
Copy link
Author

s3rj1k commented Feb 11, 2025

So, show us the use case and we will happily lead the feature to completion.

My use case was this #1094 (comment)

@jcchavezs
Copy link
Member

jcchavezs commented Feb 11, 2025

@s3rj1k you asked for a parser which would validate rules and return errors with line number and we proposed #1101 then you said you had no time to show any code consuming this parser (#1101 (comment)). Didn't we aid you with your use case? I spent time crafting the PR and you haven't show any usage on that so what is the ROI for the project?

Now @guydc is asking for exposing the rules (I assume given a string input give me the list of rules) that is a different use case (very valid IMHO) that we can also address in an experimental feature and we could even come up with such a PR but the request will be the same, with the experimental feature show us some usage code.

@s3rj1k
Copy link
Author

s3rj1k commented Feb 11, 2025

you said you had no time

#1101 (comment)

That should be read like "Project is under NDA"

@s3rj1k
Copy link
Author

s3rj1k commented Feb 11, 2025

Ok, I see no point in continuing this discussion, @guydc feel free to openup new issue if you are up for the challenge.

Closing this as I no longer work on related project.

@s3rj1k s3rj1k closed this as completed Feb 11, 2025
@guydc
Copy link

guydc commented Feb 11, 2025

Hi @jcchavezs, @s3rj1k,

Thanks for taking my interest under consideration.

The use case I had in mind for exposing the rules is to be able to allow end-users to interact with rules from a large ruleset like CRS in a user-friendly manner. For example, one could build a UI/API that allows users to:

  • Search rules, filter by categories, actions, targets, etc.
  • Allow users to define how a ruleset like CRS is used, e.g. which rules are included, which targets/actions are changed, etc.

A lot of WAF vendors offer similar capabilities. I imagine that this can help drive adoption by simplifying operations.

To achieve this, rules do not have to be entirely exposed. Some sort of limited metadata is probably sufficient. It's also possible that this sort of functionality can just be a part of Coraza that relies on internals without exposing the rules.

I'll open a follow-up issue.

@s3rj1k
Copy link
Author

s3rj1k commented Feb 11, 2025

exposing the rules is to be able to allow end-users to interact with rules from a large ruleset like CRS in a user-friendly manner

Exactly, libmodsecurity has CLI utility for interacting with ruleset that gives some usable UX to work with large amount of rules.

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

No branches or pull requests

5 participants