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

Add strict mode to validate protocol strings #3435

Closed
v0y4g3r opened this issue Mar 5, 2024 · 14 comments
Closed

Add strict mode to validate protocol strings #3435

v0y4g3r opened this issue Mar 5, 2024 · 14 comments
Labels
good first issue Good for newcomers

Comments

@v0y4g3r
Copy link
Contributor

v0y4g3r commented Mar 5, 2024

For performance reasons, we expect requests from the remote write protocol to be valid protobuf bytes. We should provide a strict mode to perform UTF-8 validation.

Originally posted by @evenyag in #3425 (comment)

@v0y4g3r v0y4g3r changed the title For performance reasons, we expect requests from the remote write protocol to be valid protobuf bytes. We should provide a strict mode to perform UTF-8 validation. Add strict mode to validate protocol strings Mar 5, 2024
@evenyag
Copy link
Contributor

evenyag commented Mar 7, 2024

We could also use the bstr crate if possible...

@carmooo
Copy link

carmooo commented Mar 14, 2024

Hi, would be first time contributor here 👋
Is it ok if I give it a go?
Any more info you might have that would be useful?
Thanks!

@tisonkun
Copy link
Contributor

@carmooo

You may search "// safety: we expect all labels are UTF-8 encoded strings." in the code and this issue is about add a strict mode to check the value of PromLabel are valid UTF-8 strings.

It would require:

  1. Where to add the strict mode config/param? @v0y4g3r @evenyag @waynexia do you have some suggestions here?
  2. How to efficiently validate payload. @evenyag suggests you take a look at the bstr crate also.

What's your plan to handle this issue? I expect to listen to your plan; bare assignment and waiting until stale is not a good practice.

@carmooo
Copy link

carmooo commented Mar 15, 2024

Thanks for the info @tisonkun.
My plan is to check if the bstr crate is a valid option for this validation, if so I'll use it for validation. I also need to figure out where to add the strict mode configuration so as to make the validation conditional.
Does that answer your question?
Or would you like any more info?
Thanks!

@evenyag
Copy link
Contributor

evenyag commented Mar 15, 2024

We could add a strict_mode option in the HttpOptions and pass it to the prom server.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct HttpOptions {
pub addr: String,
#[serde(with = "humantime_serde")]
pub timeout: Duration,
#[serde(skip)]
pub disable_dashboard: bool,
pub body_limit: ReadableSize,
}

Using bstr might be more complicated than I expected as both rust String and arrow StringArray use utf-8 encoding.

@tisonkun
Copy link
Contributor

tisonkun commented Mar 15, 2024

@carmooo though you almost repeat my comment ... it's the way to go! Lol.

Do not hesitate to ask here if you stall by any uncertaincy. And you can send a draft PR when a rough impl is ready so that we can involve early.

@evenyag
Copy link
Contributor

evenyag commented Mar 15, 2024

My plan is to check if the bstr crate is a valid option for this validation, if so I'll use it for validation.

bstr treats byte strings as conventionally UTF-8 but doesn't speed up utf-8 validation. So we still need to convert it into utf-8 string unless we use bstr as the default string implementation.

@carmooo I'd suggest adding an option to enable the validation as it is much easier to implement. You could pass the strict mode flag to the write_fast() method.

/// Handling prometheus remote write requests
async fn write_fast(
&self,
request: RowInsertRequests,
ctx: QueryContextRef,
with_metric_engine: bool,
) -> Result<()>;

@carmooo
Copy link

carmooo commented Mar 15, 2024

@carmooo though you almost repeat my comment ... it's the way to go! Lol.

Yes, I did indeed @tisonkun 😅
I'll try to get a draft MR ready asap and will ask questions about any blockers.
@evenyag I'll follow your suggestions

@carmooo carmooo removed their assignment Mar 29, 2024
@carmooo
Copy link

carmooo commented Mar 29, 2024

Sorry for backing out but cannot take care of this right now.

@tisonkun
Copy link
Contributor

Never mind. Thanks for your time and sharing :D

@irenjj
Copy link
Contributor

irenjj commented Mar 31, 2024

can i take it?

@tisonkun
Copy link
Contributor

@irenjj Of course you can take it. But the same as above, without certain progress, bare assignment doesn't help.

You can ask any questions or submit a patch without an assignment.

@tisonkun
Copy link
Contributor

Assigned. But I'd still clarify that "Can I take it" doesn't help a lot. Everyone is welcome to take over an issue here so it's not even a question. You can ping me once a (draft) PR is available or any certain questions.

@evenyag
Copy link
Contributor

evenyag commented Apr 24, 2024

Closed by #3638

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

No branches or pull requests

5 participants