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

Refactor vault access handling in event command #1478

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

saksham-postman
Copy link
Collaborator

This PR refactors how vault access is handled in the event command extension:

Renames allowVaultAccess to isVaultAccessInScriptsAllowed for clarity
Moves vault access check and tracking enablement into the vault execution handler
Adds support for isVaultAccessInScriptsAllowed to be either a boolean or an async function
Updates vault access check to use the new isVaultAccessInScriptsAllowed approach

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.65%. Comparing base (f06a951) to head (a42c65b).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1478      +/-   ##
===========================================
+ Coverage    73.63%   73.65%   +0.01%     
===========================================
  Files           45       45              
  Lines         3414     3416       +2     
  Branches       986      986              
===========================================
+ Hits          2514     2516       +2     
  Misses         701      701              
  Partials       199      199              
Flag Coverage Δ
integration 63.72% <100.00%> (+0.02%) ⬆️
legacy 39.08% <12.50%> (-0.06%) ⬇️
unit 39.54% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@saksham-postman saksham-postman marked this pull request as draft October 18, 2024 07:14
@saksham-postman
Copy link
Collaborator Author

Browser tests are failing consistently across other merged PR's too : https://github.com/postmanlabs/postman-runtime/actions/runs/10701761076/job/29668418235?pr=1452

@saksham-postman saksham-postman marked this pull request as ready for review October 18, 2024 11:26
if (typeof isVaultAccessInScriptsAllowed === 'function') {
isVaultAccessAllowed = await isVaultAccessInScriptsAllowed(item.id);
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

We do not need to support this.

}
}
catch (error) {
console.error(error.message);
Copy link
Member

Choose a reason for hiding this comment

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

Not required

});
});

describe('should handle _allowScriptAccess as undefined for backward compatibility', function () {
Copy link
Member

Choose a reason for hiding this comment

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

this also looks redundant

else {
isVaultAccessAllowed = isVaultAccessInScriptsAllowed;
}
if (isVaultAccessAllowed) {
Copy link
Member

Choose a reason for hiding this comment

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

why is this part of try catch?

isVaultAccessInScriptsAllowed = _.get(vaultSecrets, '_.allowScriptAccess'),
packageResolver = _.get(this, 'options.script.packageResolver'),
events,
isVaultAccessAllowed;

// Explicitly enable tracking for vault secrets here as this will
// not be sent to sandbox who otherwise takes care of mutation tracking
Copy link
Member

Choose a reason for hiding this comment

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

the comment also needs to be moved along with the code

test/integration/sanity/vaultSecrets.test.js Show resolved Hide resolved
this.host.on(EXECUTION_VAULT_BASE + executionId, async function (id, cmd, ...args) {
try {
if (typeof isVaultAccessInScriptsAllowed === 'function') {
isVaultAccessAllowed = await isVaultAccessInScriptsAllowed(item.id);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
isVaultAccessAllowed = await isVaultAccessInScriptsAllowed(item.id);
isVaultAccessAllowed = Boolean(await _.get(vaultSecrets, '_.allowScriptAccess', _.noop)(item.id));

Copy link
Member

Choose a reason for hiding this comment

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

You can clean up the code above (remove if condition and unused vars) accrodingly.

Copy link
Member

Choose a reason for hiding this comment

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

Also, we don't need to run the consent check everytime there is get/set/unset on vault secrets. It should just be done for the first time in that execution, unless we are allowing the conset to be changed mid-execution (IMO that would be just confusing for users)?

@appurva21 appurva21 merged commit ec6c130 into develop Oct 28, 2024
13 of 14 checks passed
@appurva21 appurva21 deleted the feature/vault-consent-security branch October 28, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants