-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
abc3
wants to merge
2
commits into
main
Choose a base branch
from
feat/enc_secrets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.47 | ||
1.1.50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
alias Supavisor.Helpers, as: H | ||
|
||
map = %{:a => 1, "key" => "value", "ключ" => "значення"} | ||
text = "big_secret" | ||
map_enc = <<1, 10, 65, 69, 83, 46, 71, 67, 77, 46, 86, 49, 187, 130, 166, 189, 94, 38, 109, 83, 9, 109, 228, 202, 104, 33, 49, 31, 105, 142, 219, 106, 114, 21, 167, 60, 192, 204, 56, 9, 111, 223, 208, 47, 247, 74, 178, 192, 209, 153, 54, 23, 150, 155, 82, 180, 188, 2, 87, 189, 180, 225, 66, 243, 111, 73, 73, 199, 2, 240, 51, 227, 168, 202, 197, 247, 210, 197, 100, 67, 230, 32, 175, 110, 173, 21, 219, 110, 244, 166, 79, 70, 200, 75, 206, 222, 116, 177, 243, 239, 141, 80, 6, 33, 250, 188, 92, 73>> | ||
text_enc = <<1, 10, 65, 69, 83, 46, 71, 67, 77, 46, 86, 49, 79, 49, 25, 197, 18, 255, 27, 3, 45, 198, 65, 15, 230, 155, 246, 84, 13, 125, 122, 178, 51, 203, 103, 149, 86, 117, 61, 106, 220, 97, 155, 204, 118, 20, 217, 71, 15, 250, 43, 171, 6, 68, 250, 58, 215, 45, 0, 60>> | ||
|
||
Benchee.run(%{ | ||
"encode_secret map" => fn -> | ||
H.encode_secret(map) | ||
end, | ||
"encode_secret text" => fn -> | ||
H.encode_secret(text) | ||
end, | ||
"decode_secret map" => fn -> | ||
H.decode_secret(map_enc) | ||
end, | ||
"decode_secret text" => fn -> | ||
H.decode_secret(text_enc) | ||
end | ||
}) | ||
|
||
|
||
# $ VAULT_ENC_KEY="aHD8DZRdk2emnkdktFZRh3E9RNg4aOY7" mix run bench/enc_dec.exs | ||
|
||
# Operating System: macOS | ||
# CPU Information: Apple M1 Pro | ||
# Number of Available Cores: 10 | ||
# Available memory: 16 GB | ||
# Elixir 1.14.3 | ||
# Erlang 24.3.4 | ||
|
||
# Benchmark suite executing with the following configuration: | ||
# warmup: 2 s | ||
# time: 5 s | ||
# memory time: 0 ns | ||
# reduction time: 0 ns | ||
# parallel: 1 | ||
# inputs: none specified | ||
# Estimated total run time: 28 s | ||
|
||
# Benchmarking decode_secret map ... | ||
# Benchmarking decode_secret text ... | ||
# Benchmarking encode_secret map ... | ||
# Benchmarking encode_secret text ... | ||
|
||
# Name ips average deviation median 99th % | ||
# decode_secret text 753.68 K 1.33 μs ±1293.76% 1.25 μs 1.50 μs | ||
# encode_secret text 708.57 K 1.41 μs ±453.06% 1.33 μs 1.88 μs | ||
# decode_secret map 692.11 K 1.44 μs ±945.34% 1.33 μs 1.67 μs | ||
# encode_secret map 671.23 K 1.49 μs ±414.54% 1.42 μs 1.96 μs | ||
|
||
# Comparison: | ||
# decode_secret text 753.68 K | ||
# encode_secret text 708.57 K - 1.06x slower +0.0845 μs | ||
# decode_secret map 692.11 K - 1.09x slower +0.118 μs | ||
# encode_secret map 671.23 K - 1.12x slower +0.163 μs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,15 @@ defmodule Supavisor.SynHandlerTest do | |
import ExUnit.CaptureLog | ||
require Logger | ||
alias Ecto.Adapters.SQL.Sandbox | ||
alias Supavisor.Helpers, as: H | ||
|
||
@id {{:single, "syn_tenant"}, "postgres", :session, "postgres"} | ||
|
||
test "resolving conflict" do | ||
node2 = :"[email protected]" | ||
|
||
secret = %{alias: "postgres"} | ||
auth_secret = {:password, fn -> secret end} | ||
auth_secret = {:password, H.encode_secret(secret)} | ||
{:ok, pid2} = :erpc.call(node2, Supavisor.FixturesHelpers, :start_pool, [@id, secret]) | ||
Process.sleep(500) | ||
assert pid2 == Supavisor.get_global_sup(@id) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
defmodule Supavisor.FixturesHelpers do | ||
@moduledoc false | ||
|
||
alias Supavisor.Helpers, as: H | ||
|
||
def start_pool(id, secret) do | ||
secret = {:password, fn -> secret end} | ||
secret = {:password, H.encode_secret(secret)} | ||
Supavisor.start(id, secret) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?