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

b64dec (logql template function) should automatically account for missing padding #15547

Open
dlemfh opened this issue Dec 25, 2024 · 0 comments

Comments

@dlemfh
Copy link

dlemfh commented Dec 25, 2024

Is your feature request related to a problem? Please describe.
While querying loki logs, I'd like to decode the jwt tokens written in my logs.

In my case, the base64 encoded payload of the jwt tokens do not have their padding.

This gives a illegal base64 data at input byte .. when trying to base64-decode with b64dec.

Describe the solution you'd like
The b64dec template function would be more useful if it automatically accounts for missing padding in the base64 encoded string.

Describe alternatives you've considered
I could add missing padding myself as part of the logql query like this:

| line_format `{{printf "%s%s" .payload (repeat (mod (sub 4 (mod (count "." .payload) 4)) 4 | int) "=") | b64dec}}`

But it's preferable to not have to add missing padding ourselves.

Additional context
Formula for automatically adding missing padding while decoding a base64-encoded string s: b64decode(s + b'=' * (-len(s) % 4))


I am willing to submit a PR that overrides b64dec functionality in https://github.com/grafana/loki/blob/main/pkg/logql/log/fmt.go, if it is agreed to move forward in this direction!

@dlemfh dlemfh changed the title Make the b64dec logql template function automatically account for missing padding b64dec (logql template function) should automatically account for missing padding Dec 30, 2024
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

1 participant