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

feat(runtime): enhance the access protection security model #452

Merged
merged 14 commits into from
Jan 27, 2024

Conversation

basmasking
Copy link
Member

Fixes #448

Changes proposed in this pull request:

  • added option to created trusted clients
  • added protected access for procedures
  • updated documentation
  • updated example to reflect the change

@MaskingTechnology/jitar

@basmasking basmasking linked an issue Jan 26, 2024 that may be closed by this pull request
@basmasking basmasking marked this pull request as ready for review January 26, 2024 14:21

When building a distributed application, you don't want all functions to be available by the outside world. Some functions are only used internally by other segments. To protect the access to these functions, Jitar provides a `secret` property in the [runtime services](../fundamentals/runtime-services#node). This secret is used to create trusted clients. Trusted clients can access functions with the `protected` access level.

Any client that wants to access a protected function must provide a valid access key. The access key needs to be added to the http header `x-access-key`. Any node that has a valid access key is considered a trusted client, and automatically adds the access key to the http header of outgoing requests. Any node that doesn't have a valid access key is considered an untrusted client and can only access `public` functions.
Copy link
Member

Choose a reason for hiding this comment

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

The header X-Access-Key is, in a security context, generic enough to conflict with other systems (I know systems that use this header too). My suggestion would be to make it more jitar specific, like: X-Jitar-Protected-Access-Key.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion, I changed the header key.

@@ -115,6 +115,7 @@ The following configuration properties are available:
* repository - url of the repository (required).
* segments - list of segment names to load (optional, loads all segments by default).
* middlewares - list of [middleware modules](../develop/middleware.md) to load (optional).
* secret - shared secret for creating trusted clients (optional).
Copy link
Member

Choose a reason for hiding this comment

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

How do the terms secret and access key relate to each other? Can we use a singe term for both to make things more clear?

Copy link
Member Author

@basmasking basmasking Jan 26, 2024

Choose a reason for hiding this comment

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

The string I've used is trustKey, because the key builds trust between the nodes and the gateway, allowing them to access protected procedures.

Copy link
Member

Choose a reason for hiding this comment

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

Is it more clear to rename this segment to protected.segment.json?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is also a private procedure in there, and it's still related to the game folder in the source. This keeps everything aligned, just as it is in the other examples.

Copy link
Member

Choose a reason for hiding this comment

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

Is it more clear to rename this segment to public.segment.json

@@ -25,6 +25,22 @@ export default class Procedure
return implementations.some(implementation => implementation.public);
}

get protected()
{
Copy link
Member

Choose a reason for hiding this comment

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

Should we mention this in the docs?


return this.#gateway.run(request);
}

async #runProcedure(procedure: Procedure, request: Request): Promise<Response>
{
const secret = request.headers.get('x-access-key');
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
const secret = request.headers.get('x-access-key');
const secret = request.getHeader('x-access-key');

Copy link
Member

Choose a reason for hiding this comment

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

I'm missing a test for a failing registration of a node, and protected related test in the local node spec.

Copy link
Member

@petermasking petermasking left a comment

Choose a reason for hiding this comment

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

Besides the other review comments I'm still missing the tests for the local node. At least for running a protected procedure with a key, with an invalid key and a valid key.


When building a distributed application, you don't want all functions to be available by the outside world. Some functions are only used internally by other segments. To protect the access to these functions, Jitar provides a `trustKey` property in the [runtime services](../fundamentals/runtime-services#node). This key is used to create trusted clients. Trusted clients can access functions with the `protected` access level.

Any client that wants to access a protected function must provide a valid key. It needs to be added to the http header `X-Jitar-Protected-Access-Key`. Any node that has a valid key is automatically considered a trusted client, and adds the access key to the http header of outgoing requests. Any node that doesn't have a valid access key is considered an untrusted client and can only access `public` functions.
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, we'll use X-Jitar-Trust-Key to make it consistent with the used property.

Copy link
Member

Choose a reason for hiding this comment

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

The key has been changed in the code, but not in the docs yet.

@@ -3,5 +3,5 @@ import ProcedureRuntime from './ProcedureRuntime.js';

export default abstract class Node extends ProcedureRuntime
{
get trustKey(): string | undefined { return undefined; }
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this property abstract, so the remote node also gets an explicit implementation?


// Run the protected function with key (succeeds)
GET http://localhost:3000/rpc/game/checkSecret?secret=123 HTTP/1.1
X-Jitar-Protected-Access-Key: VERY_SECRET_KEY
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
X-Jitar-Protected-Access-Key: VERY_SECRET_KEY
X-Jitar-Trust-Key: VERY_SECRET_KEY


When building a distributed application, you don't want all functions to be available by the outside world. Some functions are only used internally by other segments. To protect the access to these functions, Jitar provides a `trustKey` property in the [runtime services](../fundamentals/runtime-services#node). This key is used to create trusted clients. Trusted clients can access functions with the `protected` access level.

Any client that wants to access a protected function must provide a valid key. It needs to be added to the http header `X-Jitar-Protected-Access-Key`. Any node that has a valid key is automatically considered a trusted client, and adds the access key to the http header of outgoing requests. Any node that doesn't have a valid access key is considered an untrusted client and can only access `public` functions.
Copy link
Member

Choose a reason for hiding this comment

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

The key has been changed in the code, but not in the docs yet.

@petermasking petermasking merged commit eb35499 into main Jan 27, 2024
7 checks passed
@petermasking petermasking deleted the 448-enhance-the-access-protection-security-model branch January 27, 2024 19:32
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.

Enhance the access protection security model
2 participants