-
-
Notifications
You must be signed in to change notification settings - Fork 775
Fix decrypting pack config keys under additionalProperties #5225
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
Changes from 11 commits
bffccc5
46a892c
6e864f3
44e0436
2354014
9d7c1d5
3543ad1
e1ef44b
46ce281
8bf7d2a
a2644c2
b7672ed
26741cd
e69fbae
a483888
d67b3c9
4d3be4a
574034f
d0d9924
6bfa390
532e15f
1d613bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ def test_ensure_local_pack_config_feature_removed(self): | |
|
|
||
| def test_get_config_some_values_overriden_in_datastore(self): | ||
| # Test a scenario where some values are overriden in datastore via pack | ||
| # flobal config | ||
| # global config | ||
| kvp_db = set_datastore_value_for_config_key( | ||
| pack_name="dummy_pack_5", | ||
| key_name="api_secret", | ||
|
|
@@ -518,6 +518,68 @@ def test_get_config_dynamic_config_item_nested_list(self): | |
|
|
||
| config_db.delete() | ||
|
|
||
| def test_get_config_dynamic_config_item_under_additional_properties(self): | ||
| pack_name = "dummy_pack_schema_with_additional_properties_1" | ||
| loader = ContentPackConfigLoader(pack_name=pack_name) | ||
|
|
||
| KeyValuePair.add_or_update(KeyValuePairDB(name="k0", value="v0")) | ||
| KeyValuePair.add_or_update( | ||
| KeyValuePairDB(name="k1_encrypted", value="v1_encrypted", secret=True) | ||
| ) | ||
|
|
||
| #################### | ||
| # values in objects under an object with additionalProperties | ||
| values = { | ||
| "profiles": { | ||
| "dev": { | ||
| # no host or port to test default value | ||
| "token": "hard-coded-secret", | ||
| }, | ||
| "stage": { | ||
| "host": "127.0.0.1", | ||
| "port": 8181, | ||
| # unencrypted in datastore | ||
| "token": "{{st2kv.system.k0}}", | ||
| }, | ||
| "prod": { | ||
| "host": "127.1.2.7", | ||
| "port": 8282, | ||
| # encrypted in datastore | ||
| "token": "{{st2kv.system.k1_encrypted}}", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user wants that value in the config to actually be decrypted, they still need to use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Config is automatically decrypted when the schema lists the key as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarification - I was just somewhat confused by the test case aka something didn't add up.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed a fix for this test - 574034f. That's the part which confused me a bit. I assumed we don't do decryption because the value which was stored and the one which was retrieved was supposed to be the same (but the KVP model layer doesn't perform any encryption and we need to encrypt the value ourselves when storing it).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! That's why it seemed to be working before, but wasn't. Thanks for the fix! |
||
| }, | ||
| } | ||
| } | ||
| config_db = ConfigDB(pack=pack_name, values=values) | ||
| config_db = Config.add_or_update(config_db) | ||
|
|
||
| config_rendered = loader.get_config() | ||
|
|
||
| self.assertEqual( | ||
| config_rendered, | ||
| { | ||
| "region": "us-east-1", | ||
| "profiles": { | ||
| "dev": { | ||
| "host": "127.0.0.3", | ||
| "port": 8080, | ||
| "token": "hard-coded-secret", | ||
| }, | ||
| "stage": { | ||
| "host": "127.0.0.1", | ||
| "port": 8181, | ||
| "token": "v0", | ||
| }, | ||
| "prod": { | ||
| "host": "127.1.2.7", | ||
| "port": 8282, | ||
| "token": "v1_encrypted", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| config_db.delete() | ||
|
|
||
| def test_empty_config_object_in_the_database(self): | ||
| pack_name = "dummy_pack_empty_config" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| region: | ||
| type: "string" | ||
| required: false | ||
| default: "us-east-1" | ||
| profiles: | ||
| type: "object" | ||
| required: false | ||
| additionalProperties: | ||
| type: object | ||
| additionalProperties: false | ||
| properties: | ||
| host: | ||
| type: "string" | ||
| required: false | ||
| default: "127.0.0.3" | ||
| port: | ||
| type: "integer" | ||
| required: false | ||
| default: 8080 | ||
| token: | ||
| type: "string" | ||
| required: true | ||
| secret: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| name : dummy_pack_schema_with_additional_properties_1 | ||
| description : dummy pack with nested objects under additionalProperties | ||
| version : 0.1.0 | ||
| author : st2-dev | ||
| email : [email protected] |
Uh oh!
There was an error while loading. Please reload this page.