Skip to content

Commit cc863c8

Browse files
committed
Disallow decrypt_kv jinja filter for fields marked as secret
This commit addresses the issue where in pack config if fields are marked as secret: true and if user specifies jinja expression with filter decrypt_kv, the values are not decrypted twice. This is due to the fact that for all fields marked as secret, the values are auto decrypted. Specifying an additional decrypt_kv filter causes issue. The commit raises exceptions if decrypt_kv is specified for any fields marked secret.
1 parent 7079635 commit cc863c8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

st2api/st2api/controllers/v1/pack_configs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def put(self, pack_config_content, pack_ref, requester_user, show_secrets=False)
107107
config_api.validate(validate_against_schema=True)
108108
except jsonschema.ValidationError as e:
109109
raise ValueValidationException(six.text_type(e))
110+
except ValueValidationException as e:
111+
raise ValueValidationException(six.text_type(e))
110112

111113
self._dump_config_to_disk(config_api)
112114

st2common/st2common/util/pack.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from st2common.constants.pack import PACK_REF_WHITELIST_REGEX
2626
from st2common.content.loader import MetaLoader
2727
from st2common.persistence.pack import Pack
28+
from st2common.exceptions.apivalidation import ValueValidationException
29+
from st2common.util import jinja as jinja_utils
2830

2931
__all__ = [
3032
'get_pack_ref_from_metadata',
@@ -102,6 +104,10 @@ def validate_config_against_schema(config_schema, config_object, config_path,
102104

103105
pack_name = pack_name or 'unknown'
104106

107+
for key in config_object:
108+
if jinja_utils.is_jinja_expression(value=config_object.get(key)) and "decrypt_kv" in config_object.get(key) and config_schema.get(key).get('secret'):
109+
raise ValueValidationException("Validation Error: decrypt_kv jinja filter specified for auto decrypted fields marked with `secret: True`")
110+
105111
schema = util_schema.get_schema_for_resource_parameters(parameters_schema=config_schema,
106112
allow_additional_properties=True)
107113
instance = config_object

0 commit comments

Comments
 (0)