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

feat: encrypt secrets for internal use #333

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: encrypt secrets for internal use #333

wants to merge 2 commits into from

Conversation

abc3
Copy link
Member

@abc3 abc3 commented Apr 3, 2024

To avoid logging sensitive data (passwords, secrets, etc.), we keep it internally as anonymous functions fn -> some_secret end. However, during hot upgrades, old links to these funs can become invalid, so this PR introduces a new approach by turning sensitive data into binary.

The PR also includes the HotUpgrade module, which will replace existing encoded secrets, currently cached or residing within the :poolboy supervisor, with this new method

@abc3
Copy link
Member Author

abc3 commented Apr 3, 2024

@supabase/dashbit, if there is any way to continue keeping secrets in funs across upgrades, I would be happy to hear about it, as I haven’t found any safe method

@abc3 abc3 requested review from a team, chasers and filipecabaco April 3, 2024 11:45
Copy link
Contributor

@philss philss left a comment

Choose a reason for hiding this comment

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

Hi @abc3 👋 LGTM!

if there is any way to continue keeping secrets in funs across upgrades, I would be happy to hear about it, as I haven’t found any safe method

Not that I know. I will keep investigating this, but I can only think of doing serialization/deserialization of the function term, which is similar to what you did here. But yeah, it wouldn't be safe without the encryption/decryption.

def decode_secret(fun) when is_function(fun) do
Logger.warning(
"Using deprecated function `decode_secret/1` #{inspect(Process.info(self(), :current_stacktrace), pretty: true)}"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Emitting the deprecation warning is fine, but have you considered using the @deprecated module tag - https://hexdocs.pm/elixir/Module.html#module-deprecated-since-v1-6-0 - with a different function name? This would make easier to spot the locations you are still using this, and would make easier to migrate. Of course is totally fine to keep as it is :)
WDYT?

@josevalim
Copy link
Contributor

Other approaches to consider:

  1. Put those secrets into a struct and derive the implementation of the struct to not include the field:
@derive {Inspect, only: []}
defstruct :secret
  1. Store them in the process dictionary (they will be plain but it should not show up in logs)

@supabase supabase deleted a comment from notion-workspace bot May 15, 2024
lib/supavisor/hot_upgrade.ex Outdated Show resolved Hide resolved
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.

5 participants