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

Fix decrypting pack config keys under additionalProperties #5225

Merged
merged 22 commits into from
Apr 10, 2021

Conversation

cognifloyd
Copy link
Member

The pack config loader uses "secret: true" in a schema to trigger decrypting a key from the datastore. However, it does not look at the schema under additionalProperties, so those properties can't use encrypted keys.

This issue was first documented in StackStorm-Exchange/stackstorm-jira#19 (comment)

This PR fixes that so that the pack config loader handles additionalProperties when defined.

@pull-request-size pull-request-size bot added the size/S PR that changes 10-29 lines. Very easy to review. label Apr 8, 2021
@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 09b104b to bffccc5 Compare April 8, 2021 18:24
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/S PR that changes 10-29 lines. Very easy to review. labels Apr 8, 2021
@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 9378252 to e1ef44b Compare April 9, 2021 00:14
@cognifloyd cognifloyd added this to the 3.5.0 milestone Apr 9, 2021
@cognifloyd cognifloyd requested a review from blag April 9, 2021 00:39
@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 585fa46 to 8bf7d2a Compare April 9, 2021 02:01
@cognifloyd

This comment has been minimized.

@cognifloyd
Copy link
Member Author

All GHA tests are passing. CircleCI tests are broken due to a pbr+logshipper issue (known based on conversation in slack).

@Kami
Copy link
Member

Kami commented Apr 9, 2021

Nice work 👍

I will have a more detailed look later this week.

@cognifloyd cognifloyd requested a review from Kami April 9, 2021 16:14
@cognifloyd
Copy link
Member Author

Weird. I'm patching a v3.2 StackStorm running python2.7 and this delta was insufficient. afaik, the behavior of defaultdict should be the same under python3, so I'm not sure why the unit test is passing. In any case, I will push a commit with the fix momentarily.

@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 1bafc58 to a2644c2 Compare April 9, 2021 20:22
CHANGELOG.rst Show resolved Hide resolved
"host": "127.1.2.7",
"port": 8282,
# encrypted in datastore
"token": "{{st2kv.system.k1_encrypted}}",
Copy link
Member

Choose a reason for hiding this comment

The 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 decrypt_kv Jinja filter, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Config is automatically decrypted when the schema lists the key as secret: true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See _get_datastore_value_for_expression() in config_loader.py

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Member Author

Choose a reason for hiding this comment

The 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!

@Kami
Copy link
Member

Kami commented Apr 9, 2021

Overall LGTM, just had some questions / comments on internal implementation details.

for key in init_additional_properties:
property_schema.__missing__(key)
# ensure that these keys are present in the object
for key in additional_properties_keys:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, if that works it should be much more straight forward to understand the code now - well, at least for me :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And re - using copy - I actually verified, if we didn't use copy with defaultdict version, we also don't need to use it here - it's returning by reference version in both scenarios.

And since I believe we indeed never manipulate those values, only read / access them, copy is probably not needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We modify the config object, but we don't modify (and probably should not modify) the schema itself. So, references are perfect in this case.

@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 408e14f to e69fbae Compare April 10, 2021 01:12
@copart-jafloyd copart-jafloyd force-pushed the pack-config-additionalproperties branch from 7bd6933 to d67b3c9 Compare April 10, 2021 01:50
@Kami
Copy link
Member

Kami commented Apr 10, 2021

Some of those integration tests still seem to be failing quite often due to race / similar, quite annoying.

We should probably modify that job step to try to retry up to 2-3 times on failure to avoid annoying and manual re-run of the complete workflow.

@cognifloyd
Copy link
Member Author

@cognifloyd
Copy link
Member Author

All tests are green. Quick, let's merge before anything else gets merged into master. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement size/L PR that changes 100-499 lines. Requires some effort to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants