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

Support for policy query #143

Merged
merged 8 commits into from
Jul 1, 2020
Merged

Support for policy query #143

merged 8 commits into from
Jul 1, 2020

Conversation

AleF83
Copy link
Contributor

@AleF83 AleF83 commented Jun 25, 2020

No description provided.

@AleF83 AleF83 changed the base branch from master to authorization June 25, 2020 11:31
@@ -33,12 +33,13 @@ export class PolicyExecutor {
const policyDefinition = this.getPolicyDefinition(policy.namespace, policy.name);

const args = policyDefinition.args && this.preparePolicyArgs(policyDefinition.args, policy);
// TODO: evaluate queries

const query = policyDefinition.query && (await this.evaluatePolicyQuery(policyDefinition.query, args));
Copy link
Contributor

Choose a reason for hiding this comment

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

It should also support param injection from jwt in addition to args, though this is something I'm adding in my next PR. We should probably wait until after both PRs are merged and then add jwt injection support to queries.

Probably worth adding a TODO for it though to be safe

@@ -70,4 +71,20 @@ export class PolicyExecutor {
if (!policyDefinition) throw new Error(`The policy ${name} in namespace ${namespace} was not found`);
return policyDefinition;
}

private async evaluatePolicyQuery(query: PolicyQuery, args: PolicyArgsObject = {}): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The return value should be Promise<QueryResults> instead of Promise<any>


private async evaluatePolicyQuery(query: PolicyQuery, args: PolicyArgsObject = {}): Promise<any> {
let variableValues =
query.variables &&
Copy link
Contributor

Choose a reason for hiding this comment

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

The query definition is very different from the spec, if you make changes you should also update the spec to match this

case 'exports':
return context.exports.resolve(info.parentType, parent, propName);
return context.exports.resolve(info.parentType, parent, template);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think template is a good name for this variable after the changes, maybe propPath (and change the existing propPath to propPathArray or something)


test('Query allowed employee', async () => {
const response: AllowedEmployeeQueryResponse = await gatewayClient.request(employeeQuery('allowedEmployee'));
expect(response.allowedEmployee.address).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not check the actual value of the address? should be pretty simple here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add snapshot validation

Copy link
Contributor

@tomeresk tomeresk left a comment

Choose a reason for hiding this comment

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

Just need to update the authz spec

@AleF83 AleF83 marked this pull request as ready for review June 28, 2020 19:29
case 'jwt':
return getJwt(context)[propName];
return getJwt(context)[key];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return getJwt(context)[key];
return R.path(propPath, getJwt(context));

We can support the deep nesting here as well.
getJwt will return an empty object if there is not JWT so there is no need for an initial existence check.

@AleF83 AleF83 merged commit 6dc9682 into authorization Jul 1, 2020
@tomeresk tomeresk deleted the auth-policy-queries branch July 1, 2020 16:04
AleF83 added a commit that referenced this pull request Jul 2, 2020
* Authorization - fully implemented registry part (#133)

This includes:
Create/update policy resource
Attachments support for policy resource (with support for writing the attachment to both s3 and fs repositories)
Opa policy type implementation, including compiling rego code to wasm and adding that to the policy as an attachment

* Authorization gateway - basic features (#138)

implemented full flow with basic features
Implement local policy attachment caching for all resource repositories

* Add policy definitions and attachments to request context, change pol… (#141)

* Add policy definitions and attachments to request context, change policy executor to use them from context instead of directly from repo

* PR comments

* allow jwt in param injection (policy authorization can use it through args) (#144)

* Support for policy query (#143)

* Policy directive - accept only a single policy (#146)

* change policy directive to accept only a single policy

* Refactored PolicyExecutor API to only expose static methods

Co-authored-by: Tomer Eskenazi <tomeresk@gmail.com>
AleF83 added a commit that referenced this pull request Jul 2, 2020
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