-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[gh-476] Sanitise HCL variables before storing on job submission #24423
base: main
Are you sure you want to change the base?
Conversation
4d40732
to
4d11ca7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if strings.Contains(v, "\n") { | ||
js.VariableFlags[k] = strings.ReplaceAll(v, "\n", "\\n") | ||
} | ||
js.VariableFlags[k] = url.QueryEscape(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the Terraform provider and the CLI, because they both use this api
package, but does the UI already have an equivalent to this fix? (cc @philrenaud )
Should we add a warning to the API documentation for the JobSubmission
field that third-party callers of the HTTP API need to perform this operation as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UI runs output here through this jsonToHcl() helper method
It adds \n
between multiple VariableFlags / Variables entries, and the codemirror editor we use for rendering generally handles them correctly. It's not perfect, though: Your example in the test,
"test": `"foo": "bar"`
renders like this:
which isn't perfect but it's probably enough of an edge case that it's been okay since we've had HCL-in-UI.
============
I'm not sure if this is what url.QueryEscape() is doing, but if we're given output like what's in the test below (%22foo%22%3A+%22bar%22), we will show that verbatim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Testing this out made me remember we have two different variable-related properties in Job submission data: Lines 978 to 984 in e206993
I think that VariableFlags are affected here, but Variables are not. I'm not sure if the bug in question could show up in that format, but wanted to mention it. ========================= All that aside, I'm also noticing some perhaps erroneous character additions. Here are screenshots showing VariableFlags and output for a job where a cli-provided multi-line variable has a command to run was:
Note the |
Description
Currently Nomad only handles HCL variables with new lines, any other non alphanumeric character is left untouched and stored unescaped, which can cause errors while re starting a stopped job, particularly from the UI.
it fixes #476
Testing & Reproduction steps
Links
Contributor Checklist
changelog entry using the
make cl
command.ensure regressions will be caught.
and job configuration, please update the Nomad website documentation to reflect this. Refer to
the website README for docs guidelines. Please also consider whether the
change requires notes within the upgrade guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.