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

Reuse cluster connection objects but only for authorized users #8

Open
ritesh089 opened this issue Jul 10, 2024 · 3 comments
Open

Reuse cluster connection objects but only for authorized users #8

ritesh089 opened this issue Jul 10, 2024 · 3 comments
Labels
enhancement New feature or request security

Comments

@ritesh089
Copy link
Collaborator

The couchbase provider for wasmcloud now stores a connection object per link in the map.
While this prevents link's from overwriting each other's connection objects, we may result in a lot of duplicates.

We will need to find a way to prevent duplicate connection object .
A duplicate connection object is created when more than one connection object (cluster) has all the same properties:
connection-string, bucketname, scope, collection, username, password.

Proposed solution 1 :
We could maintain a hash of the above properties along with the connection object in the map .
On a new link, we fetch the connection object from the map using the source id.
If found, we compare the hash values . If they match , we dont add a new entry to the map .
If they dont match, we create a new entry in the map .
Now the Map key will need to be updated to include a suffix with the source id.
Value of the suffix is TBD.

Solution 2 :
Couchbase SDK to be updated to include the option to perform authorization at a more granular level .
Eg: at a collection level or bucket level .
This will reduce the overhead of having to fetch the cluster map on every link and still authorize again while reusing the existing clouchbase cluster object.

@vados-cosmonic vados-cosmonic added enhancement New feature or request security labels Jul 11, 2024
@vados-cosmonic
Copy link
Collaborator

Proposed solution 1 should have at least two benefits:

  • Connection re-use (identical connection details could be used to de-duplicate, if sharing is reasonable)
  • Security

As far as the improvement in security -- at present if the same component connects twice, but should be authorized differently/use different authentication for the connection, then the same connection is made available.

With proposed solution 1, we would effectively index by the Source ID and effectively the hash of the configuration object, to prevent this kind of overlap.

@ritesh089 just to make sure I was understanding right -- in this case we have a single webassembly component which needs to use different connection authentication levels, correct?

If we could split the component they would have separate source IDs and not overlap in this way.

@ingenthr
Copy link

ingenthr commented Jul 12, 2024

@chvck I think we should automagically dereference to the same connection from the same process if the bucket and credentials precisely match. Am I correct for that here, or is Golang a bit different than our other SDKs?

cc/ @brett19

(aside: I know only enough about how this executes in WASM/WASI to be dangerous, so I'll be glad to be corrected if it's different)

@chvck
Copy link

chvck commented Jul 15, 2024

I think we should automagically dereference to the same connection from the same process if the bucket and credentials precisely match. Am I correct for that here, or is Golang a bit different than our other SDKs?

In Go if the same Cluster object is used for opening buckets then calling cluster.Bucket multiple times with the same bucket name will reuse the existing "agent" for that bucket name under the hood - that is basically the same set of connections. The bucket name (sort of) gets baked into each connection at connect time. At present to open the same bucket twice but with different credentials would require two Cluster instances. Scopes and collections are specified at the request level on the wire rather than connection level so do not have the same overheads/considerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security
Projects
None yet
Development

No branches or pull requests

4 participants