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

Secret masking in output_schema feature is added #5250

Merged
merged 44 commits into from
May 21, 2021

Conversation

mahesh-orch
Copy link
Contributor

With this implementation, action responses marked as secret in output schema are masked in CLI and UI.

@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label Apr 29, 2021
@CLAassistant
Copy link

CLAassistant commented Apr 29, 2021

CLA assistant check
All committers have signed the CLA.

adding a missed import
@m4dcoder m4dcoder added this to the 3.5.0 milestone Apr 30, 2021
Copy link
Contributor

@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

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

This is a good start. But from the current PR, I don't see how this is wired to the API and CLI masking the result in the output on execution get. Can you write a unit test that can show this is working for GET method of action execution in the API? Also, the secret masking of action execution output shouldn't affect action execution in a workflow, can you also add a test case for workflow execution where the output of an action execution of a task isn't masked?

@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels May 10, 2021
@pull-request-size pull-request-size bot added size/XS PR that changes 0-9 lines. Quick fix/merge. and removed size/M PR that changes 30-99 lines. Good size to review. labels May 10, 2021
@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/XS PR that changes 0-9 lines. Quick fix/merge. labels May 10, 2021
@mahesh-orch
Copy link
Contributor Author

mahesh-orch commented May 10, 2021

Thanks @m4dcoder for the comments. I have pushed the new changes in /st2common/models/api/execution.py and they are wired to the API and CLI masking the result in the output on execution get. Please review the changes.

:rtype: class: ``ActionExecutionAPI``
"""

doc = cls._from_model(model, mask_secrets=mask_secrets)
Copy link
Contributor

Choose a reason for hiding this comment

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

@mahesh-orch If you follow _from_model, you'll see that there is already a line that mask secrets at https://github.com/StackStorm/st2/blob/master/st2common/st2common/models/api/base.py#L118. This calls a model specific function to mask secrets. The specific function for ActionExecutionDB is at https://github.com/StackStorm/st2/blob/master/st2common/st2common/models/db/execution.py#L107. Can you move the logic for output schema into this function?

@pull-request-size pull-request-size bot added size/XS PR that changes 0-9 lines. Quick fix/merge. and removed size/M PR that changes 30-99 lines. Good size to review. labels May 12, 2021
@pull-request-size pull-request-size bot added size/M PR that changes 30-99 lines. Good size to review. and removed size/XS PR that changes 0-9 lines. Quick fix/merge. labels May 12, 2021
@mahesh-orch
Copy link
Contributor Author

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

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

Nice! This is coming along, and I'm really looking forward to using it.

Some whitespace needs to be cleaned up.

@m4dcoder Can you enable running tests on this PR? This is @mahesh-orch's first PR on st2, so github is blocking running actions until someone with write access enables them.

st2common/st2common/models/api/execution.py Outdated Show resolved Hide resolved
st2common/st2common/models/api/execution.py Outdated Show resolved Hide resolved
mahesh-orch and others added 2 commits May 12, 2021 17:47
Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>
Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>
@cognifloyd
Copy link
Member

I have to mention orquesta runner_type also in condition because it was masking secret parameters in output of the task in workflow.

What do you mean? Can you share an example of what was getting masked when masking the output of an orquesta workflow?

The current mask_secret_output function in the output_schema util module
is too fragile with the multiple if else on checking runner type to
determine if there is an output schema defined. For example, orquesta
runner has an output_schema and output_key defined but then the if else
already introduced a bug. The function is refactored to evaluate if
output key and output schema is defined and then proceed to masking
secret value if an output parameter is marked as secret in the output
schema. Additional unit test is added to cover orquesta runner. The unit
tests for the mask_secret_output function is also simplified.
New actions were added to dummy_pack_1. The number of actions have
changed in some of the checks in tests.
Copy link
Contributor

@m4dcoder m4dcoder left a comment

Choose a reason for hiding this comment

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

@mahesh-orch

I have refactored your PR please review my changes. The if/else check on runner type is too fragile and again is bug prone if someone goes and change the schema for the runner type of add new runner types. Your change already introduced a bug for the orquesta runner (workflow). I refactored it and also added a unit test for orquesta runner in st2actions/tests/unit/test_output_schema.py to catch that. There are other changes I did to simplify the PR. Also, I've fixed tests so CI succeeded now.

There are a still open items in that PR you should follow up on. 1) Please add a test for workflow. Add a task with secrets in the output schema, publish the result of the task to the workflow output and make sure the value is not masked in the task. You can add this test at https://github.com/StackStorm/st2/blob/master/contrib/runners/orquesta_runner/tests/unit/test_data_flow.py. 2) Please add a unit test in the API to make sure output with secrets is masked at https://github.com/StackStorm/st2/blob/master/st2api/tests/unit/controllers/v1/test_executions.py.

@mahesh-orch
Copy link
Contributor Author

What do you mean? Can you share an example of what was getting masked when masking the output of an orquesta workflow?

@cognifloyd Thank you for the comments and inputs. Previous my changes without if condition to orquesta runner were causing masking the secret parameter in workflow task output but @m4dcoder had improved that piece of code and now it is working fine.

@pull-request-size pull-request-size bot added size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review. and removed size/L PR that changes 100-499 lines. Requires some effort to review. labels May 18, 2021
@mahesh-orch
Copy link
Contributor Author

@m4dcoder, @cognifloyd Hi, I am pushing code of unit test to show in workflow secret parameters in output_schema in action should not be masked in task output. I need help as unit test is failing at the task which contain python action.
Unit test is in https://github.com/StackStorm/st2/blob/master/contrib/runners/orquesta_runner/tests/unit/test_data_flow.py. Test is failing at L262 as tk3_ac_ex_db object having result with error named unrecognized arguments and status as failed. Thanks.

@mahesh-orch
Copy link
Contributor Author

Hi @m4dcoder, I have added unit test for testing GET APIs containing output schema secret parameters as masked. Please review changes.

Add the action.output_schema and runner.output_key to attributes to be
included in the API query otherwise secrets are not masked in the output
of workflow action. Update the output schema util to be more robust in
terms of handling result that is either empty, wrong type, or missing
output key.
@m4dcoder m4dcoder merged commit fb2d1b3 into StackStorm:master May 21, 2021
@m4dcoder m4dcoder deleted the secret_masking branch May 21, 2021 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants