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

Make sure encrypted file env variable names are unique per filename #678

Merged
merged 3 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ os:

rvm:
- jruby
- 1.9.2
- 1.9.3
- 2.2.7
- 2.3.8
- 2.4.5
- 2.5.5
- 2.6.3

Expand Down
12 changes: 6 additions & 6 deletions lib/travis/cli/encrypt_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(input_path, output_path = nil)

error "requires --decrypt-to option when reading from stdin" unless decrypt_to?

set_env_vars
set_env_vars(input_path)

command = decrypt_command(output_path)
stage ? store_command(command) : print_command(command)
Expand Down Expand Up @@ -70,14 +70,14 @@ def decrypt_command(path)
"openssl aes-256-cbc -K $#{env_name(:key)} -iv $#{env_name(:iv)} -in #{escape_path(path)} -out #{escape_path(decrypt_to)} -d"
end

def set_env_vars
def set_env_vars(input_path)
say "storing secure env variables for decryption"
repository.env_vars.upsert env_name(:key), key, :public => false
repository.env_vars.upsert env_name(:iv), iv, :public => false
repository.env_vars.upsert env_name(input_path, :key), key, :public => false
repository.env_vars.upsert env_name(input_path, :iv), iv, :public => false
end

def env_name(name)
@env_prefix ||= "encrypted_#{Digest.hexencode(Digest::SHA1.digest(Dir.pwd)[0..5])}"
def env_name(input_path, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny caveat here is that, as it was before, this command is context dependent. If we execute travis encrypt-file from a different directory, even if the command is invoked on the same file, we will compute a different hash. This is not documented anywhere, but it is worth pointing it out.

Copy link
Contributor Author

@svenfuchs svenfuchs Aug 5, 2019

Choose a reason for hiding this comment

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

@BanzaiMan without having verified it, i believe that input_path is whatever path is passed to travis encrypt path/to/file (i.e. it would be path/to/file). so yes, i guess that counts as context dependent, but it kinda makes sense to me, as such paths would be considered unique per repo, too (and so would the resulting env vars)?

@env_prefix ||= "encrypted_#{Digest.hexencode(Digest::SHA1.digest(input_path)[0..5])}"
"#{@env_prefix}_#{name}"
end

Expand Down
4 changes: 2 additions & 2 deletions spec/cli/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

shared_examples_for 'travis init' do |language|
example "travis init #{language} (empty directory)" do
File.exist?('.travis.yml').should be_false
File.exist?('.travis.yml').should be false
run_cli('init', language, '--skip-enable', '-r', 'travis-ci/travis.rb').should be_success
stdout.should be == ".travis.yml file created!\n"
File.exist?('.travis.yml').should be_true
File.exist?('.travis.yml').should be true
File.read('.travis.yml').should include("language: #{language}")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/client/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
its(:email) { should be == 'konstantin.haase@gmail.com' }
its(:gravatar_id) { should be == '5c2b452f6eea4a6d84c105ebd971d2a4' }
its(:locale) { should be == 'en' }
its(:is_syncing) { should be_false }
its(:is_syncing) { should be false }
its(:synced_at) { should be_a(Time) }

it { should_not be_syncing }
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'travis'
require 'highline'
require 'tmpdir'
require 'rspec/its'

temp_dir = nil

Expand Down
1 change: 1 addition & 0 deletions travis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ Gem::Specification.new do |s|
s.add_dependency "json", "~> 1.8" if RUBY_VERSION < "2.0"
s.add_dependency "pusher-client", "~> 0.4"
s.add_development_dependency "rspec", "~> 2.12"
s.add_development_dependency "rspec-its"
s.add_development_dependency "sinatra", "~> 1.3"
s.add_development_dependency "rack-test", "~> 0.6"

Expand Down