MatrixAI / js-encryptedfs

Encrypted Filesystem for TypeScript/JavaScript Applications
https://polykey.com
Apache License 2.0
10 stars 3 forks source link

Node process context control #18

Closed robert-cronin closed 4 years ago

robert-cronin commented 4 years ago

VFS has certain methods to control the file system context (e.g. chdir, setUid, setGid etc), but this is not exposed on the native nodejs fs module. It is instead controlled via the process module. In order to change the context on the lower fs, one would need access to the process module and this entails some extra research as to the best way to approach this. Essentially we want to be careful about tampering with the process context.

One solution to this is to ask for these methods as an additional parameter when the user passes in upperDir and lowerDir. The new constructor for EFS could look something like this:

const efs = new EncryptedFS(
  vfs,    // upperDir
  vfs,    // upperDir context control (for chdir, setUid, setGid, etc...)
  fs,     // lowerDir
  process // lowerDir context control (for chdir, setUid, setGid, etc...)
  ...
)

These context control objects have to conform to an interface to ensure that the relevant methods exist:

interface FSContextControl {
  chdir(...): void
  setUid(...): void
  setGid(...): void
}

But if we are going to use process, then we have to ensure that EFS is notified whenever the process context is changed externally to EFS (i.e. manually by user). This could be done by creating a proxy process that acts as an observer pattern and using this in EFS instead so that EFS is notified every time the cwd/gid/uid is changed in the process context. This should also go in usage notes and operator warnings to ensure correct usage by the end user.

robert-cronin commented 4 years ago

I think this issue is largely completed as the latest release includes these context control methods.