-
Notifications
You must be signed in to change notification settings - Fork 2k
add input validation and path traversal protections #26241
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
base: NMD-760-nomad-secrets-block
Are you sure you want to change the base?
add input validation and path traversal protections #26241
Conversation
@@ -59,22 +62,38 @@ func (n *NomadProvider) BuildTemplate() *structs.Template { | |||
|
|||
return &structs.Template{ | |||
EmbeddedTmpl: data, | |||
DestPath: n.tmplPath, | |||
DestPath: filepath.Join(n.secretDir, n.tmplFile), |
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.
I'm not excited about doing multiple filepath.Join()
's but it's nice having the directory and filename separate for os.OpenInRoot
. We could store this on the struct but that also feels like unnecessary duplication.
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.
We could clean up some path traversals here:
DestPath: filepath.Join(n.secretDir, n.tmplFile), | |
DestPath: filepath.Clean(filepath.Join(n.secretDir, n.tmplFile)), |
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.
I added Deniz for review, to see if he had any thoughts. Also, I'm not sure we need it, but we could also validate the namespace using our existing regex for namespace upsert if we felt it would be useful.
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.
Thanks for looking into it and very cool use of os.Root 🙌 Small recommendation about filepath.Clean()
but the rest LGTM
@@ -59,22 +62,38 @@ func (n *NomadProvider) BuildTemplate() *structs.Template { | |||
|
|||
return &structs.Template{ | |||
EmbeddedTmpl: data, | |||
DestPath: n.tmplPath, | |||
DestPath: filepath.Join(n.secretDir, n.tmplFile), |
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.
We could clean up some path traversals here:
DestPath: filepath.Join(n.secretDir, n.tmplFile), | |
DestPath: filepath.Clean(filepath.Join(n.secretDir, n.tmplFile)), |
@@ -69,22 +73,26 @@ func (v *VaultProvider) BuildTemplate() *structs.Template { | |||
|
|||
return &structs.Template{ | |||
EmbeddedTmpl: data, | |||
DestPath: v.tmplPath, | |||
DestPath: filepath.Join(v.secretDir, v.tmplFile), |
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.
DestPath: filepath.Join(v.secretDir, v.tmplFile), | |
DestPath: filepath.Clean(filepath.Join(v.secretDir, v.tmplFile)), |
Description
Adds
OpenRoot
for accessing rendered template, and user input validation so users cannot inject template functions into secret block parameters.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.