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

[DPLT-1042] Add support for backend only mutations from Runner #109

Merged
merged 3 commits into from
Jun 28, 2023

Conversation

morgsmccauley
Copy link
Collaborator

@morgsmccauley morgsmccauley commented Jun 26, 2023

This PR adds support for Backend Only Mutations in the Lambda Runner.

To mark a mutation as Backend Only, the flag must be set for the relevant Role. This makes the mutation hidden by default, and only accessible when the X-Hasura-Use-Backend-Only-Permissions, relevant X-Hasura-Role, and X-Hasura-Admin-Secret headers are present on the request. As the secret is secret, the mutation is mostly inaccessible to frontends, but not it is still possible to call it if you have the secret.

Backend Only Mutations are only hidden for the relevant role. So if another role has unrestricted access to the mutation it will be able to execute it. This means that supplying the X-Hasura-Admin-Secret alone, therefore assuming the admin role which has access to everything, is enough to call the 'Backend Only Mutation'. This shouldn't be a concern as we are only ones with the secret.

@morgsmccauley morgsmccauley force-pushed the DPLT-1042-add-support-for-backend-only-mutations branch from 40c9b8f to 331d8d2 Compare June 27, 2023 02:10
@@ -13,5 +13,9 @@ pub(crate) async fn auth(req: HttpRequest) -> impl Responder {
None => std::env::var("DEFAULT_HASURA_ROLE").unwrap(),
};

if role_header == "admin" {
Copy link
Collaborator Author

@morgsmccauley morgsmccauley Jun 27, 2023

Choose a reason for hiding this comment

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

Prior to this, it was possible to assume the admin role by specifying it on the headers. This disables that functionality so that it is not possible to workaround the Backend Only Mutations.

Note that assuming admin is still possible by passing the specifying the X-Hasura-Admin-Secret header.

'X-Hasura-Use-Backend-Only-Permissions': 'true',
...(hasuraRoleName && {
'X-Hasura-Role': hasuraRoleName,
'X-Hasura-Admin-Secret': process.env.HASURA_ADMIN_SECRET
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only attach the admin secret if a role is specified - if this were attached without specifying a role, admin would be used, granting the request access to everything.

@@ -354,7 +354,12 @@ export default class Indexer {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(hasuraRoleName && { 'X-Hasura-Role': hasuraRoleName })
'X-Hasura-Use-Backend-Only-Permissions': 'true',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This won't affect requests to tables without this flag enabled on the role.

@morgsmccauley morgsmccauley marked this pull request as ready for review June 27, 2023 02:47
@morgsmccauley morgsmccauley changed the title feat: Add support for backend only mutations from Runner [DPLT-1042] Add support for backend only mutations from Runner Jun 27, 2023
Copy link
Contributor

@roshaans roshaans left a comment

Choose a reason for hiding this comment

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

lgtm

@morgsmccauley morgsmccauley merged commit a717804 into main Jun 28, 2023
@morgsmccauley morgsmccauley deleted the DPLT-1042-add-support-for-backend-only-mutations branch June 28, 2023 19:43
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