Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

API RFC #2

Open
alexng353 opened this issue May 22, 2023 · 7 comments
Open

API RFC #2

alexng353 opened this issue May 22, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed security Something from the bad place

Comments

@alexng353
Copy link
Member

alexng353 commented May 22, 2023

  • organizations
  • teams
  • services
  • sharing between teams, organizations and users
  • Server side multi-party encryption

structure

  • organizations
    • teams
      • users
      • services
    • services
  • users
    • services
    • sharing to other users
@ImLunaHey ImLunaHey added enhancement New feature or request help wanted Extra attention is needed security Something from the bad place labels May 22, 2023
@ImLunaHey
Copy link
Member

ImLunaHey commented May 22, 2023

Thoughts on moving the endspoints to something like this?

/envs/:namespace/:id/:key

Where these could be the namespace + id.

service/c7001d79-9803-448e-af21-bee8b494d9e6
user/c7001d79-9803-448e-af21-bee8b494d9e6
team/c7001d79-9803-448e-af21-bee8b494d9e6
org/c7001d79-9803-448e-af21-bee8b494d9e6

This would allow access to either a user's personal keys, a single services, a teams or org wide envs.

@ImLunaHey
Copy link
Member

When a user authenticates let's use the user's ID + password for the auth via basic auth header.

When we get the userId + password use them to lookup the encrypted password for the namespace + key they're accessing.

Something like this.

const userId = '123';
const password = '123';
const namespace = 'service';
const namespaceId = 'c7001d79-9803-448e-af21-bee8b494d9e6';
const key = 'NODE_ENV';

const namespacePassword = db
    .selectFrom('namespace_passwords')
    .select('iv')
    .select('salt')
    .select('data')
    .where('userId', '=', userId)
    .where('namespace', '=', namespace)
    .where('namespaceId', '=', namespaceId)
    .executeTakeFirst();

// Now that we have the password for the service we can decrypt it.

const encryptedEnv = await db
    .selectFrom('envs')
    .select('iv')
    .select('salt')
    .select('data')
    .where('namespace', '=', namespace)
    .where('namespaceId', '=', namespaceId)
    .where('key', '=', key)
    .executeTakeFirst();

if (!encryptedEnv) throw new Error('Not found');

const decryptedEnv = {
    key,
    value: decryptEnv(encryptedEnv, namespacePassword),
};

@ImLunaHey
Copy link
Member

Hmm, issue with the above is how do we share keys to the other user without knowing their password in advance. 🤔

@ImLunaHey
Copy link
Member

Okay, new plan.

image

@ImLunaHey
Copy link
Member

@alexng353

image

@ImLunaHey
Copy link
Member

ImLunaHey commented May 22, 2023

Thoughts? 🤔

I haven't added anything about encryption since it's all client side now.

// Create user[body:username] -> { username, password }
// Create token[body:username,body:password]  -> { token }
// Create namespace[header:username,header:token] -> { namespaceId }
// Create env[header:username,header:token,param:namespace,param:namespaceId,param:key,body:value] -> 201
// Get env[header:username,header:token,param:namespace,param:namespaceId,param:key] -> { [key]: { namespaceKey, encryptedValue } }
// Create org[header:username,header:token] -> { namespaceId }
// Create team[header:username,header:token] -> { namespaceId }
// Add team to org[header:username,header:token,body:username] -> 201
// Add user to org[header:username,header:token,body:username] -> 201
// Add user to team[header:username,header:token,body:username] -> 201

@alexng353
Copy link
Member Author

// Create token[body:username,body:password] -> { token }
Should this not be header as well? What's different about this route?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed security Something from the bad place
Projects
None yet
Development

No branches or pull requests

2 participants