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

Referencing jinja path in parent directory with tpldir and ".." gives: "relative paths are prohibited" #47452

Closed
mkotsbak opened this issue May 3, 2018 · 5 comments
Labels
expected-behavior intended functionality
Milestone

Comments

@mkotsbak
Copy link

mkotsbak commented May 3, 2018

Description of Issue/Question

Referencing parent directory of sls file not working.

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)
This like on top of a sls file:

{%- from tpldir + "/../map.jinja" import postgres with context -%}

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Run state.highstate. Then observe these log lines:

[WARNING ] Discarded template path 'formula/postgres/server/../map.jinja', relative paths are prohibited
[ERROR ] Rendering exception occurred: Jinja error: formula/postgres/server/../map.jinja

The path specified is correct from salt root directory.

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

Salt Version:
Salt: 2017.7.5

Dependency Versions:
cffi: 1.6.0
cherrypy: Not Installed
dateutil: 1.5
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.1
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.5 (default, Aug 4 2017, 00:39:18)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: centos 7.4.1708 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-693.21.1.el7.x86_64
system: Linux
version: CentOS Linux 7.4.1708 Core

@gtmanfred gtmanfred added the expected-behavior intended functionality label May 3, 2018
@gtmanfred
Copy link
Contributor

This is by design

'Discarded template path \'%s\', relative paths are '

to prevent people from being able to break out of the salt fileserver, and get to stuff on the salt master they shouldn't have access too.

If you want to go up a directory, get the dirname of the tpldir.

{{ from salt.file.dirname(tpldir) ~ 'map.jinja' import postgres with context }}

Daniel

@Ch3LL Ch3LL added this to the Blocked milestone May 3, 2018
@mkotsbak
Copy link
Author

mkotsbak commented May 4, 2018

Ah thanks for the workaround, but this should be added to the documentation, Also ":." could be supported by proper check of the path if it is safe.

Btw, correct workaround is:

{{ from salt.file.dirname(tpldir) ~ '/map.jinja' import postgres with context }}

@gtmanfred
Copy link
Contributor

gtmanfred commented May 4, 2018

We would be open if a pull request was submitted, but it would not be near the top of the list of stuff we are working on right now.

Daniel

@mkotsbak
Copy link
Author

mkotsbak commented May 4, 2018

Ok, as long as there is a workaround it is a minor issue compared to #41195 preventing creating portable formulas.

@steverweber
Copy link
Contributor

{%- from salt.file.normpath(tpldir + '/../vars.jinja') import parent_vars %}

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

No branches or pull requests

4 participants