File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 5858
5959 # Key data
6060 #
61- # An array of strings, with each element of the array being
62- # a raw private key in PEM format.
63- key_data : [ "-----BEGIN OPENSSH PRIVATE KEY-----" ]
61+ # An array of strings, with each element of the array being a secret name.
62+ key_data :
63+ - SSH_PRIVATE_KEY
6464
6565 # Config
6666 #
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ class Kamal::Configuration::Ssh
33
44 include Kamal ::Configuration ::Validation
55
6- attr_reader :ssh_config
6+ attr_reader :ssh_config , :secrets
77
88 def initialize ( config :)
99 @ssh_config = config . raw_config . ssh || { }
10+ @secrets = config . secrets
1011 validate! ssh_config
1112 end
1213
@@ -35,7 +36,10 @@ def keys
3536 end
3637
3738 def key_data
38- ssh_config [ "key_data" ]
39+ key_data = ssh_config [ "key_data" ]
40+ return unless key_data
41+
42+ key_data . map { |k | k . include? ( "-----BEGIN" ) ? k : secrets [ k ] }
3943 end
4044
4145 def options
Original file line number Diff line number Diff line change @@ -37,4 +37,24 @@ class ConfigurationSshTest < ActiveSupport::TestCase
3737 config = Kamal ::
Configuration . new ( @deploy . tap { |
c |
c . merge! ( ssh :
{ "proxy" => "[email protected] " } ) } ) 3838 assert_equal "[email protected] " , config . ssh . options [ :proxy ] . jump_proxies 3939 end
40+
41+ test "ssh key_data with plain value array" do
42+ config = Kamal ::Configuration . new ( @deploy . tap { |c | c . merge! ( ssh : { "key_data" => [ "-----BEGIN OPENSSH PRIVATE KEY-----" ] } ) } )
43+ assert_equal [ "-----BEGIN OPENSSH PRIVATE KEY-----" ] , config . ssh . options [ :key_data ]
44+ end
45+
46+ test "ssh key_data with array containing one secret string" do
47+ with_test_secrets ( "secrets" => "SSH_PRIVATE_KEY=secret_ssh_key" ) do
48+ config = Kamal ::Configuration . new ( @deploy . tap { |c | c . merge! ( ssh : { "key_data" => [ "SSH_PRIVATE_KEY" ] } ) } )
49+ assert_equal [ "secret_ssh_key" ] , config . ssh . options [ :key_data ]
50+ end
51+ end
52+
53+ test "ssh key_data with array containing multiple secret strings" do
54+ with_test_secrets ( "secrets" => "SSH_PRIVATE_KEY=secret_ssh_key\n SECOND_KEY=second_secret_ssh_key" ) do
55+ config = Kamal ::Configuration . new ( @deploy . tap { |c | c . merge! ( ssh : { "key_data" => [ "SSH_PRIVATE_KEY" , "SECOND_KEY" ] } ) } )
56+ assert_equal [ "secret_ssh_key" , "second_secret_ssh_key" ] , config . ssh . options [ :key_data ]
57+ end
58+ end
59+
4060end
You can’t perform that action at this time.
0 commit comments