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

Encrypt Variables securely #8

Merged
merged 10 commits into from
Aug 5, 2024
Merged

Encrypt Variables securely #8

merged 10 commits into from
Aug 5, 2024

Conversation

ZIJ
Copy link
Contributor

@ZIJ ZIJ commented Aug 2, 2024

Goal

  • Variables of type Secret are encrypted using the public secrets key (stored in the db, implemented in Add org-level secrets key #7)
  • If the org has no secrets key, user should not be able to create secrets. Show a warning message "To enable secrets creation, configure secrets key in settings"
Screenshot 2024-08-02 at 20 24 58

Notes

  • src/data/admin/env-vars.ts is mostly a copy of encryption.ts with some functions removed, others renamed

Copy link

vercel bot commented Aug 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2024 10:34am

@ZIJ ZIJ changed the title [WIP] Encrypt Variables securely Encrypt Variables securely Aug 2, 2024
setCanCreateSecrets(false);
}
})
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can use the fetched key and check if it's null, as it is a nullable field. If the key is null, the button that triggers the key creation will remain enabled. Otherwise, if the key exists, the button will be disabled. This approach allows us to avoid using useEffect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it's only 2 levels down (page > TFVarDetails > TFVarTable), we can fetch the value of getProjectKey(projectId) and check if it's null. As an alternative, we can return a boolean from a function called isProjectPublicKeyCreated and pass that value as true. Since we are anyway not using the key within the client components and are just checking the boolean value, there's no need to fetch the actual value, and this approach is a bit more secure, I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, done

import { EnvVar } from '@/types/userTypes';
import { constants, publicEncrypt } from 'crypto';

export async function encryptSecretWithPublicKey(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better if we directly pass the value to this function, as it is the primary basis for this action, rather than fetching it within it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

truth, done

return encrypted.toString('base64');
}

export async function getProjectPublicKey(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we choose not to fetch from useEffect (mentioned earlier), we already have the organizationId when we fetch the slim project on the parent page. This allows us to refactor the function to getOrganizationPublicKey(organizationId).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

merge main into feat/encrypt-variables
@motatoes motatoes merged commit cd57480 into main Aug 5, 2024
6 checks passed
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.

3 participants