Ensure secret envs are present

This commit is contained in:
David Heinemeier Hansson
2023-01-21 10:58:11 +01:00
parent f6ca864e06
commit dda20eec11
3 changed files with 13 additions and 1 deletions

View File

@@ -91,6 +91,8 @@ env:
The list of secret env variables will be expanded at run time from your local machine. So a reference to a secret `DATABASE_PASSWORD` will look for `ENV["DATABASE_PASSWORD"]` on the machine running MRSK. Just like with build secrets. The list of secret env variables will be expanded at run time from your local machine. So a reference to a secret `DATABASE_PASSWORD` will look for `ENV["DATABASE_PASSWORD"]` on the machine running MRSK. Just like with build secrets.
If the referenced secret ENVs are missing, the configuration will be halted with a `KeyError` exception.
Note: Marking an ENV as secret currently only redacts its value in the output for MRSK. The ENV is still injected in the clear into the container at runtime. Note: Marking an ENV as secret currently only redacts its value in the output for MRSK. The ENV is still injected in the clear into the container at runtime.

View File

@@ -140,7 +140,7 @@ class Mrsk::Configuration
end end
def expand_env_secrets def expand_env_secrets
config.env["secret"].to_h { |key| [ key, ENV[key] ] } config.env["secret"].to_h { |key| [ key, ENV.fetch(key) ] }
end end
end end

View File

@@ -113,6 +113,16 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV["PASSWORD"] = nil ENV["PASSWORD"] = nil
end end
test "env args with missing secret" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!({
env: { "secret" => [ "PASSWORD" ] }
}) })
assert_raises(KeyError) do
assert_equal [ "-e", "PASSWORD=secret123" ], config.env_args
end
end
test "ssh options" do test "ssh options" do
assert_equal "root", @config.ssh_options[:user] assert_equal "root", @config.ssh_options[:user]