Skip to content

Commit

Permalink
Generate JWT token from v2_key
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jun 4, 2024
1 parent 41c4a5c commit ca9adce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/before_install
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if [ -n "$CI" ]; then
echo "== Installing system packages =="
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
sudo apt-get install -y libsodium-dev
echo
fi

Expand Down
13 changes: 12 additions & 1 deletion lib/terraform/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def server_url
end

def server_token
ENV.fetch('TERRAFORM_RUNNER_TOKEN', nil)
@server_token ||= ENV.fetch('TERRAFORM_RUNNER_TOKEN', jwt_token)
end

def stack_job_interval_in_secs
Expand Down Expand Up @@ -179,6 +179,17 @@ def encoded_zip_from_directory(template_path)
Base64.encode64(File.binread(zip_file_path))
end
end

def jwt_token
require "jwt"

payload = {'Username' => 'opentofu-runner'}
JWT.encode(payload, v2_key.key, 'HS256')
end

def v2_key
ManageIQ::Password.key
end
end
end
end
2 changes: 2 additions & 0 deletions manageiq-providers-embedded_terraform.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "jwt", "~>2.2"

spec.add_development_dependency "manageiq-style"
spec.add_development_dependency "simplecov", ">= 0.21.2"
end

0 comments on commit ca9adce

Please sign in to comment.