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

Introduce ResourceWithVault layer #6621

Merged
merged 10 commits into from
Aug 2, 2024
Merged

Introduce ResourceWithVault layer #6621

merged 10 commits into from
Aug 2, 2024

Conversation

flvndvd
Copy link
Contributor

@flvndvd flvndvd commented Aug 1, 2024

Description

This PR introduces a new ResourceWithVault layer. This addition brings in a baseFetch method, to retrieve a resource along with its associated vault. This is essential for ensuring proper permission checks before any read or write operations. While it won’t be widely used at the moment, having synchronous access to the ACL is required.

TypeScript has been pretty challenging with the Sequelize types, so I've left a few TODOs to ensure that all fetch* and list* methods accept an auth parameter.

This PR also prevent creating assistant configurations using data sources from another workspace than the current one (see thread here).

Risk

Worst case it breaks listing/editing data sources. Safe to rollback.

Deploy Plan

No migration needs to be run.

Copy link

github-actions bot commented Aug 1, 2024

Warnings
⚠️

Files in **/lib/models/ have been modified and the PR has the migration-ack label. Don't forget to run the migration from prodbox.

Generated by 🚫 dangerJS against 968546f

@flvndvd flvndvd self-assigned this Aug 1, 2024
// Authenticator is a concept that lives in front,
// but it's used when doing api calls to other services.
// This interface is a cheap way to represent the concept of an authenticator within types.
export interface BaseAuthenticator {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be used in the follow up PR.

// Although we have the capability to support multiple workspaces,
// currently, we only support one workspace, which is the one the user is in.
// This allows us to use the current authenticator to fetch resources.
const allWorkspaceIds = _.uniqBy(dataSourceConfigurations, "workspaceSId");
Copy link
Contributor

Choose a reason for hiding this comment

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

the property is workspaceId
maybe new Set(dataSourceConfigurations.map(ds => ds.workspaceId) would be more efficient than lodash ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair ... fixed.

});

return blobs.map((b) => {
const vault = new VaultResource(VaultResource.model, b.vault.get());
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 including the vault in other includedResults ? you dont need specific handling for the vault here, and that would simplify the constructors. Actually you could even have a more generic baseFetch outside of this file, which do not add vault, but just takes the list of includes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason vault is not in includedResults is because here vault is a resource whereas includedResults contains a raw model from Sequelize.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, makes sense

Comment on lines +54 to +55
blob: Omit<CreationAttributes<DataSource>, "vaultId">,
vault: VaultResource
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have added the vault in blob and destructured it inside the body, to have one single "blob" parameter containing all the attributes (so, in the end, with vault instead of vaultId).. ?

@flvndvd flvndvd marked this pull request as ready for review August 1, 2024 17:28
super(model, blob);
}

protected static async baseFetch<
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is in charge of ensuring authorization given its role in I injecting the workspace id.

So let's be more explicit about it in its name. Maybe authorizedFetch rather than baseFetch?

Also since the resource that have it are in a vault we can enforce that auth has the group that owns the vault and error otherwise no?

Copy link
Contributor Author

@flvndvd flvndvd Aug 1, 2024

Choose a reason for hiding this comment

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

I initially wanted to include a permission check, but it does not work. Today, everyone needs to be able to fetch data source to list them in various places (assistant builder, Connections, ...). Additionally, system groups are never loaded in auth, so the permissions (read and write) primarily apply to writing to and reading from the data source, but does not prevent listing these items. In the future once we will have refactored everything maybe we will have a way to make this work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that might be premature. Let's still rename the method to emphasize the fact that it plays a security role (even now with workspace filtering).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that might be premature. Let's still rename the method to emphasize the fact that it plays a security role (even now with workspace filtering).

Isn't that similar to most resources, which are always filtered based on the workspace?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but here it's particularly important :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to baseFetchWithAuthorization.

@flvndvd flvndvd added the migration-ack 📁 Label to acknowledge that a migration is required. label Aug 2, 2024
@flvndvd flvndvd merged commit f816316 into main Aug 2, 2024
5 checks passed
@flvndvd flvndvd deleted the flav/data-source-acls branch August 2, 2024 08:27
resourceName: ResourceNameType,
sId: string
): boolean {
return sId.startsWith(RESOURCES_PREFIX[resourceName]);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should test that it starts with the prefix and the underscore to remove any chance of a collision on the prefix since _ is not a valid legacy sId character 👍

albandum pushed a commit that referenced this pull request Aug 28, 2024
* Implement ACL on data source and data source views.

* Introduce ResourceWithVault

* ✨

* Add fetchDataSource on DataSourceView

* 🙈

* Address comments from review

* 🙈

* ✂️

* s/baseFetch/baseFetchWithAuthorization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migration-ack 📁 Label to acknowledge that a migration is required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants