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

Use Jinja sandboxed environment #5359

Merged
merged 6 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Changed

Contributed by @khushboobhatia01

* Move to using Jinja sandboxed environment #5359

Contributed by Amanda McGuinness (@amanda11 Ammeon Solutions)

Fixed
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion contrib/runners/orquesta_runner/in-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
git+https://github.com/StackStorm/orquesta.git@v1.4.0#egg=orquesta
git+https://github.com/StackStorm/orquesta.git@219f00db5192321af9d29b4c51ec748846ab90c6#egg=orquesta
2 changes: 1 addition & 1 deletion contrib/runners/orquesta_runner/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# If you want to update depdencies for a single component, modify the
# in-requirements.txt for that component and then run 'make requirements' to
# update the component requirements.txt
git+https://github.com/StackStorm/orquesta.git@v1.4.0#egg=orquesta
git+https://github.com/StackStorm/orquesta.git@219f00db5192321af9d29b4c51ec748846ab90c6#egg=orquesta
3 changes: 2 additions & 1 deletion fixed-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jsonschema==2.6.0
kombu==5.0.2
lockfile==0.12.2
mongoengine==0.23.0
networkx==1.11
#Update networkx to match orquesta
networkx>=2.5.1,<3.0
# NOTE: Recent version substantially affect the performance and add big import time overhead
# See https://github.com/StackStorm/st2/issues/4160#issuecomment-394386433 for details
oslo.config>=1.12.1,<1.13
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dnspython>=1.16.0,<2.0.0
eventlet==0.30.2
flex==6.14.1
git+https://github.com/StackStorm/logshipper.git@stackstorm_patched#egg=logshipper
git+https://github.com/StackStorm/orquesta.git@v1.4.0#egg=orquesta
git+https://github.com/StackStorm/orquesta.git@219f00db5192321af9d29b4c51ec748846ab90c6#egg=orquesta
git+https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file
git+https://github.com/StackStorm/st2-auth-ldap.git@master#egg=st2-auth-ldap
git+https://github.com/StackStorm/st2-rbac-backend.git@master#egg=st2-rbac-backend
Expand All @@ -32,7 +32,7 @@ kombu==5.0.2
lockfile==0.12.2
mock==4.0.3
mongoengine==0.23.0
networkx==1.11
networkx>=2.5.1,<3.0
nose
nose-parallel==0.4.0
nose-timer==1.0.1
Expand Down
2 changes: 1 addition & 1 deletion st2common/in-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jsonschema
kombu
mongoengine
networkx
git+https://github.com/StackStorm/orquesta.git@v1.4.0#egg=orquesta
git+https://github.com/StackStorm/orquesta.git@219f00db5192321af9d29b4c51ec748846ab90c6#egg=orquesta
git+https://github.com/StackStorm/st2-rbac-backend.git@master#egg=st2-rbac-backend
oslo.config
paramiko
Expand Down
4 changes: 2 additions & 2 deletions st2common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cryptography==3.4.7
dnspython>=1.16.0,<2.0.0
eventlet==0.30.2
flex==6.14.1
git+https://github.com/StackStorm/orquesta.git@v1.4.0#egg=orquesta
git+https://github.com/StackStorm/orquesta.git@219f00db5192321af9d29b4c51ec748846ab90c6#egg=orquesta
git+https://github.com/StackStorm/st2-rbac-backend.git@master#egg=st2-rbac-backend
gitdb==4.0.2
gitpython==3.1.15
Expand All @@ -23,7 +23,7 @@ jsonschema==2.6.0
kombu==5.0.2
lockfile==0.12.2
mongoengine==0.23.0
networkx==1.11
networkx>=2.5.1,<3.0
orjson==3.5.2
oslo.config>=1.12.1,<1.13
paramiko==2.7.2
Expand Down
3 changes: 2 additions & 1 deletion st2common/st2common/util/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def get_jinja_environment(allow_undefined=False, trim_blocks=True, lstrip_blocks
# Late import to avoid very expensive in-direct import (~1 second) when this function
# is not called / used
import jinja2
import jinja2.sandbox

undefined = jinja2.Undefined if allow_undefined else jinja2.StrictUndefined
env = jinja2.Environment( # nosec
env = jinja2.sandbox.SandboxedEnvironment( # nosec
undefined=undefined, trim_blocks=trim_blocks, lstrip_blocks=lstrip_blocks
)
env.filters.update(get_filters())
Expand Down
10 changes: 5 additions & 5 deletions st2common/st2common/util/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def _process_defaults(G, schemas):
"""
for schema in schemas:
for name, value in six.iteritems(schema):
absent = name not in G.node
is_none = G.node.get(name, {}).get("value") is None
absent = name not in G.nodes
is_none = G.nodes.get(name, {}).get("value") is None
immutable = value.get("immutable", False)
if absent or is_none or immutable:
_process(G, name, value.get("default"))
Expand All @@ -167,8 +167,8 @@ def _validate(G):
"""
Validates dependency graph to ensure it has no missing or cyclic dependencies
"""
for name in G.nodes():
if "value" not in G.node[name] and "template" not in G.node[name]:
for name in G.nodes:
if "value" not in G.nodes[name] and "template" not in G.nodes[name]:
msg = 'Dependency unsatisfied in variable "%s"' % name
raise ParamException(msg)

Expand Down Expand Up @@ -232,7 +232,7 @@ def _resolve_dependencies(G):
"""
context = {}
for name in nx.topological_sort(G):
node = G.node[name]
node = G.nodes[name]
try:
context[name] = _render(node, context)

Expand Down
6 changes: 3 additions & 3 deletions tools/st2-analyze-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ def generate_graph(self, rule_links, out_file):
print(rule_link._source_action_ref)
if rule_link._source_action_ref not in nodes:
nodes.add(rule_link._source_action_ref)
dot.node(rule_link._source_action_ref, rule_link._source_action_ref)
dot.add_node(rule_link._source_action_ref)
if rule_link._dest_action_ref not in nodes:
nodes.add(rule_link._dest_action_ref)
dot.node(rule_link._dest_action_ref, rule_link._dest_action_ref)
dot.edge(
dot.add_node(rule_link._dest_action_ref)
dot.add_edge(
rule_link._source_action_ref,
rule_link._dest_action_ref,
constraint="true",
Expand Down
6 changes: 3 additions & 3 deletions tools/visualize_action_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main(metadata_path, output_path, print_source=False):
# Add all nodes
node = chain_holder.get_next_node()
while node:
dot.node(node.name, node.name)
dot.add_node(node.name)
node = chain_holder.get_next_node(curr_node_name=node.name)

# Add connections
Expand All @@ -89,7 +89,7 @@ def main(metadata_path, output_path, print_source=False):

# Add success node (if any)
if success_node:
dot.edge(
dot.add_edge(
previous_node.name,
success_node.name,
constraint="true",
Expand All @@ -102,7 +102,7 @@ def main(metadata_path, output_path, print_source=False):

# Add failure node (if any)
if failure_node:
dot.edge(
dot.add_edge(
previous_node.name,
failure_node.name,
constraint="true",
Expand Down