simp-rake-helpers 5.11.2 → 5.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -1
- data/README.md +1 -1
- data/lib/simp/command_utils.rb +21 -0
- data/lib/simp/componentinfo.rb +17 -0
- data/lib/simp/local_gpg_signing_key.rb +184 -81
- data/lib/simp/rake.rb +3 -10
- data/lib/simp/rake/build/build.rb +43 -27
- data/lib/simp/rake/build/constants.rb +5 -1
- data/lib/simp/rake/build/pkg.rb +167 -51
- data/lib/simp/rake/build/tar.rb +1 -1
- data/lib/simp/rake/helpers/version.rb +1 -1
- data/lib/simp/rake/pkg.rb +5 -1
- data/lib/simp/rake/pupmod/helpers.rb +2 -0
- data/lib/simp/rake/rubygem.rb +5 -1
- data/lib/simp/relchecks.rb +1 -1
- data/lib/simp/rpm.rb +13 -125
- data/lib/simp/rpm_signer.rb +321 -0
- data/spec/acceptance/00_pkg_rpm_custom_scriptlets_spec.rb +18 -19
- data/spec/acceptance/10_pkg_rpm_spec.rb +46 -48
- data/spec/acceptance/50_local_gpg_signing_key_spec.rb +7 -3
- data/spec/acceptance/55_build_pkg_signing_spec.rb +293 -42
- data/spec/acceptance/files/testpackage/README +8 -0
- data/spec/acceptance/files/testpackage/spec/classes/init_spec.rb +1 -0
- data/spec/acceptance/files/testpackage/spec/files/mock_something.rb +3 -0
- data/spec/acceptance/files/testpackage/utils/convert_v1_to_v2.rb +3 -0
- data/spec/acceptance/nodesets/default.yml +34 -109
- data/spec/acceptance/support/build_project_helpers.rb +32 -8
- data/spec/lib/simp/ci/gitlab_spec.rb +12 -13
- data/spec/lib/simp/command_utils_spec.rb +29 -0
- data/spec/lib/simp/componentinfo_spec.rb +10 -4
- data/spec/lib/simp/local_gpg_signing_key_spec.rb.beaker-only +115 -18
- data/spec/lib/simp/rake/build/helpers_spec.rb +3 -0
- data/spec/lib/simp/rake/build/rpmdeps_spec.rb +1 -2
- data/spec/lib/simp/rake/pupmod/fixtures/othermod/Gemfile +1 -10
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/README.md +2 -2
- data/spec/lib/simp/rake_spec.rb +2 -1
- data/spec/lib/simp/relchecks_check_rpm_changelog_spec.rb +20 -10
- data/spec/lib/simp/relchecks_compare_latest_tag_spec.rb +18 -18
- data/spec/lib/simp/rpm_signer_spec.rb +98 -0
- data/spec/lib/simp/rpm_spec.rb +1 -7
- data/spec/spec_helper.rb +1 -1
- data/spec/spec_helper_acceptance.rb +16 -3
- metadata +13 -69
- data/.travis.yml +0 -60
- data/spec/acceptance/20_pkg_rpm_upgrade_spec.rb +0 -236
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/metadata.json +0 -33
- data/spec/acceptance/files/mock_packages/pupmod-puppetlabs-stdlib.spec +0 -32
- data/spec/acceptance/files/mock_packages/pupmod-simp-foo.spec +0 -32
- data/spec/acceptance/files/mock_packages/pupmod-simp-simplib.spec +0 -32
- data/spec/acceptance/files/mock_packages/rpmbuild.sh +0 -25
- data/spec/acceptance/files/mock_packages/simp-adapter.spec +0 -43
- data/spec/acceptance/files/mock_packages/simp-adapter/etc/simp/adapter_config.yaml +0 -3
- data/spec/acceptance/files/mock_packages/simp-adapter/usr/local/sbin/simp_rpm_helper +0 -495
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/CHANGELOG +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/Rakefile +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/build/rpm_metadata/requires +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/CentOS.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/RedHat.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/hiera.yaml +0 -14
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/manifests/init.pp +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/metadata.json +0 -37
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/CHANGELOG +0 -5
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/Rakefile +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/build/rpm_metadata/requires +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/CentOS.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/RedHat.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/hiera.yaml +0 -14
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/manifests/init.pp +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/metadata.json +0 -37
- data/spec/lib/simp/ci/files/job_broken_link_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_invalid_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_invalid_suite/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_missing_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_missing_suite_and_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/no_gitlab_config_with_tests/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/no_gitlab_config_without_tests/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/nodesets/default.yml +0 -1
- data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/valid_job_nodeset_dir_link/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/valid_job_nodeset_link/spec/acceptance/suites/default/nodesets/default.yml +0 -1
- data/spec/lib/simp/files/build/testpackage.spec +0 -1
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/acceptance/nodesets/default.yml +0 -1
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/acceptance/suites/default/nodesets +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d979c12113e415884ec44b2880134bde9e20a3efc99495520e3518a994118f6
|
4
|
+
data.tar.gz: f9da255f0c077f662f00757ca2428b9375b1b4bd2d39de1b484c1a047d87c1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 493c503f1ead3608b3718e113188ef08af8905d96fd7297f439adc4809c44e70f4ec6b1c3d08c1eb09458ef4ab1499db61ec3519f1d18ab297e1b8812c5620d1
|
7
|
+
data.tar.gz: bf8bd8cbbf5c36ac268a23e346554a6f7132523f5f32a3f76162fdc8d77dd01898362d51dadd6012e2e07efb08e61737c1398c123e09092b422b94e631a0b43a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,46 @@
|
|
1
|
+
### 5.12.0 / 2021-02-16
|
2
|
+
- Ensure that pkg:install_gem uses the correct documentation options for the
|
3
|
+
version of Ruby in use.
|
4
|
+
- Disable brp-mangle-shebangs when building RPMs.
|
5
|
+
- Mitigated problem where gpg-agent daemon fails to start because
|
6
|
+
its socket path is longer than 108 characters.
|
7
|
+
- Changed the default location of the GPG keys directory used in the
|
8
|
+
pkg:key_prep and pkg:signrpms Rake tasks to <base_dir>/.dev_gpgkeys.
|
9
|
+
- Added a SIMP_PKG_build_keys_dir environment variable that overrides
|
10
|
+
the default location of the GPG keys directory used in the
|
11
|
+
pkg:key_prep and pkg:signrpms Rake tasks.
|
12
|
+
- Added SIMP_PKG_rpmsign_timeout environment variable that overrides
|
13
|
+
default timeout in seconds to wait for an individual RPM signing
|
14
|
+
operation to complete.
|
15
|
+
- Default timeout is 30 seconds.
|
16
|
+
- Most relevant when signing on RPMs on EL8 and the gpg-agent
|
17
|
+
started by rpmsign fails to start, but rpmsign does not detect
|
18
|
+
the failure and hangs.
|
19
|
+
- Improved pkg:signrpms error handling and reporting.
|
20
|
+
- Fixed bug in GPG handling for GPG 2.1+ in which an existing
|
21
|
+
GPG key that was not cached internally was not detected.
|
22
|
+
- Fixed bug where pkg:signrpms failed to sign RPMs on EL8.
|
23
|
+
- Fixed bug where pkg:checksig reported failure on EL8, even when
|
24
|
+
the signatures were valid.
|
25
|
+
- Deprecated the following top-level Rake tasks for Puppet modules:
|
26
|
+
- compare_latest_tag: use pkg:compare_latest_tag instead
|
27
|
+
- changelog_annotation: use pkg:create_tag_changelog instead
|
28
|
+
|
29
|
+
### 5.11.6 / 2021-02-03
|
30
|
+
* Fix GPG handling for GPG 2.1+
|
31
|
+
|
32
|
+
### 5.11.5 / 2020-12-02
|
33
|
+
* Add support for Puppet 7
|
34
|
+
* Work around issues with querying RPM spec file changelogs using RPM version 4.15.0+
|
35
|
+
* Switch between 'with_unbundled_env' and 'with_clean_env' based on which one
|
36
|
+
Bundler supports.
|
37
|
+
|
38
|
+
### 5.11.4 / 2020-08-03
|
39
|
+
* Permit *.md files in `rake pkg:compare_latest_tag`
|
40
|
+
|
41
|
+
### 5.11.3 / 2020-05-19
|
42
|
+
* Fix automatically added dependencies for SIMP 6.4+
|
43
|
+
|
1
44
|
### 5.11.2 / 2020-04-08
|
2
45
|
* Version information should not be required on dependencies in metadata.json
|
3
46
|
|
data/CONTRIBUTING.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
## Contributing
|
2
2
|
|
3
|
-
Please refer to the main [SIMP Project Contributing Guide](https://
|
3
|
+
Please refer to the main [SIMP Project Contributing Guide](https://simp-doc.readthedocs.io/en/stable/contributors_guide/index.html)
|
4
4
|
for details on contributing to this project.
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# SIMP_GEM_SERVERS | a space/comma delimited list of rubygem servers
|
4
4
|
# PUPPET_VERSION | specifies the version of the puppet gem to load
|
5
|
-
puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : '~>
|
5
|
+
puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : '~> 6'
|
6
6
|
gem_sources = ENV.key?('SIMP_GEM_SERVERS') ? ENV['SIMP_GEM_SERVERS'].split(/[, ]+/) : ['https://rubygems.org']
|
7
7
|
|
8
8
|
gem_sources.each { |gem_source| source gem_source }
|
@@ -13,6 +13,10 @@ gem 'simp-build-helpers'
|
|
13
13
|
gem 'simp-beaker-helpers'
|
14
14
|
gem 'beaker-puppet_install_helper'
|
15
15
|
gem 'rake', '>= 12.3.3'
|
16
|
+
# You'll need the following if using podman until they are released upstream
|
17
|
+
#gem 'beaker-docker', :git => 'https://github.com/trevor-vaughan/beaker-docker', :branch => 'support_rootless_podman'
|
18
|
+
#gem 'docker-api', :git => 'https://github.com/trevor-vaughan/docker-api', :branch => 'podman-compat'
|
19
|
+
gem 'beaker-docker'
|
16
20
|
|
17
21
|
if puppetversion
|
18
22
|
gem 'puppet', puppetversion
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ The `simp-rake-helpers` gem provides common Rake tasks to support the SIMP build
|
|
39
39
|
|
40
40
|
### This gem is part of SIMP
|
41
41
|
|
42
|
-
This gem is part of (the build tooling for) the [System Integrity Management Platform](https://
|
42
|
+
This gem is part of (the build tooling for) the [System Integrity Management Platform](https://simp-project.com), a compliance-management framework built on [Puppet](https://puppetlabs.com/).
|
43
43
|
|
44
44
|
|
45
45
|
### Features
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Simp; end
|
2
|
+
module Simp::CommandUtils
|
3
|
+
require 'facter'
|
4
|
+
|
5
|
+
def which(cmd, fail=false)
|
6
|
+
@which_cache ||= {}
|
7
|
+
|
8
|
+
if @which_cache.has_key?(cmd)
|
9
|
+
command = @which_cache[cmd]
|
10
|
+
else
|
11
|
+
command = Facter::Core::Execution.which(cmd)
|
12
|
+
@which_cache[cmd] = command
|
13
|
+
end
|
14
|
+
|
15
|
+
msg = "Warning: Command #{cmd} not found on the system."
|
16
|
+
|
17
|
+
( fail ? raise(msg) : warn(msg) ) unless command
|
18
|
+
|
19
|
+
command
|
20
|
+
end
|
21
|
+
end
|
data/lib/simp/componentinfo.rb
CHANGED
@@ -139,6 +139,23 @@ class Simp::ComponentInfo
|
|
139
139
|
if $?.exitstatus != 0
|
140
140
|
fail("Could not extract changelog from #{rpm_spec_files[0]}." +
|
141
141
|
" To debug, execute:\n #{changelog_query}")
|
142
|
+
elsif raw_changelog.strip.empty?
|
143
|
+
changelog_lines = []
|
144
|
+
|
145
|
+
in_changelog = false
|
146
|
+
File.read(rpm_spec_files[0]).lines.each do |line|
|
147
|
+
changelog_lines << line if in_changelog
|
148
|
+
|
149
|
+
if line.start_with?('%')
|
150
|
+
if line.start_with?('%changelog')
|
151
|
+
in_changelog = true
|
152
|
+
else
|
153
|
+
in_changelog = false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
raw_changelog = changelog_lines.join
|
142
159
|
end
|
143
160
|
@changelog = parse_changelog(raw_changelog, latest_version_only, verbose)
|
144
161
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'rake'
|
3
|
+
require 'simp/command_utils'
|
3
4
|
|
4
5
|
module Simp
|
5
6
|
# Ensure that a valid GPG signing key exists in a local directory
|
@@ -14,49 +15,52 @@ module Simp
|
|
14
15
|
# - New keys are generated using a temporary GPG agent with its own
|
15
16
|
# settings and socket.
|
16
17
|
#
|
17
|
-
# The local signing key's directory
|
18
|
+
# The local signing key's directory includes the following:
|
19
|
+
# gpg < 2.1.0 (EL7):
|
18
20
|
#
|
19
21
|
# ```
|
20
22
|
# #{key_name}/ # key directory
|
21
23
|
# +-- RPM-GPG-KEY-SIMP-#{key_name} # key file
|
22
24
|
# +-- gengpgkey # --gen-key params file **
|
25
|
+
# +-- gpg-agent-info.env # Lists location of gpg-agent socket + pid
|
26
|
+
# +-- run_gpg_agnet # Script used to start gpg-agent
|
23
27
|
# +-- pubring.gpg
|
24
28
|
# +-- secring.gpg
|
25
|
-
# +--
|
29
|
+
# +-- trustdb.gpg
|
26
30
|
# ```
|
27
31
|
#
|
28
|
-
#
|
32
|
+
# gpg >= 2.1.0 (EL8):
|
33
|
+
# ```
|
34
|
+
# #{key_name}/ # key directory
|
35
|
+
# +-- RPM-GPG-KEY-SIMP-#{key_name} # key file
|
36
|
+
# +-- gengpgkey # --gen-key params file **
|
37
|
+
# +-- openpgp-revocs.d/<fingerprint id>.rev
|
38
|
+
# +-- private-keys-v1.d/<user id>.key
|
39
|
+
# +-- pubring.kbx
|
40
|
+
# +-- trustdb.gpg
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
# `**` = `SIMP::RpmSigner.sign_rpms` will use the values in the `gengpgkey` file
|
29
44
|
# for the GPG signing key's email and passphrase
|
30
45
|
#
|
31
46
|
# If a new key is required, a project-only `gpg-agent` daemon is momentarily
|
32
47
|
# created to generate it, and destroyed after this is done. The daemon does
|
33
|
-
# not interact with any other `gpg-agent` daemons on the system
|
34
|
-
# launched on
|
35
|
-
# #{key_name/} directory.
|
36
|
-
#
|
37
|
-
# When instantiated, the daemon writes an "env-file" to the #{key_name}
|
38
|
-
# directory. This file specifies the location of the daemon's socket and
|
39
|
-
# pid.
|
48
|
+
# not interact with any other `gpg-agent` daemons on the system. It is
|
49
|
+
# launched on random socket(s) whose socket file(s) can be found as follows:
|
40
50
|
#
|
41
|
-
#
|
51
|
+
# Location Environment
|
52
|
+
# #{key_name} dir Docker container for EL8
|
53
|
+
# temp dir in /run/user/<uid>/gnupg EL8
|
54
|
+
# temp dir in /tmp EL7
|
42
55
|
#
|
43
|
-
# ```sh
|
44
|
-
# GPG_AGENT_INFO=/tmp/gpg-4yhfOB/S.gpg-agent:15495:1
|
45
|
-
# ```
|
46
|
-
#
|
47
|
-
# A brand-new gpg-agent daemon will output similar information, with an
|
48
|
-
# additional export:
|
49
|
-
#
|
50
|
-
# ```sh
|
51
|
-
# GPG_AGENT_INFO=/tmp/gpg-4yhfOB/S.gpg-agent:15495:1; export GPG_AGENT_INFO;\n"
|
52
|
-
# ```
|
53
56
|
class LocalGpgSigningKey
|
54
57
|
include FileUtils
|
58
|
+
include Simp::CommandUtils
|
55
59
|
|
56
|
-
# `SIMP::
|
60
|
+
# `SIMP::RpmSigner.sign_rpms` will look for a 'gengpgkey' file to
|
57
61
|
# non-interactively sign packages.
|
58
62
|
#
|
59
|
-
# @see SIMP::
|
63
|
+
# @see SIMP::RpmSigner.sign_rpms
|
60
64
|
GPG_GENKEY_PARAMS_FILENAME = 'gengpgkey'.freeze
|
61
65
|
|
62
66
|
# @param dir [String] path to gpg-agent / key directory
|
@@ -74,10 +78,27 @@ module Simp
|
|
74
78
|
@key_file = opts[:file] || "RPM-GPG-KEY-SIMP-#{@label.capitalize}"
|
75
79
|
@verbose = opts[:verbose] || false
|
76
80
|
|
81
|
+
# for EL7 only
|
77
82
|
@gpg_agent_env_file = 'gpg-agent-info.env'
|
78
83
|
@gpg_agent_script = 'run_gpg_agent'
|
79
84
|
end
|
80
85
|
|
86
|
+
# Return the version of GPG installed on the system
|
87
|
+
#
|
88
|
+
# @return [Gem::Version]
|
89
|
+
def gpg_version
|
90
|
+
return @gpg_version if @gpg_version
|
91
|
+
|
92
|
+
which('gpg', true)
|
93
|
+
@gpg_version = %x{gpg --version}.lines.first.split(/\s+/).last
|
94
|
+
|
95
|
+
unless @gpg_version.nil? || @gpg_version.empty?
|
96
|
+
@gpg_version = Gem::Version.new(@gpg_version)
|
97
|
+
end
|
98
|
+
|
99
|
+
@gpg_version
|
100
|
+
end
|
101
|
+
|
81
102
|
# Returns a gpg-agent's env string, if it can be detected from the
|
82
103
|
# gpg-agent-info file
|
83
104
|
#
|
@@ -95,15 +116,45 @@ module Simp
|
|
95
116
|
info
|
96
117
|
end
|
97
118
|
|
98
|
-
# Return the number of days left before the GPG signing key expires
|
119
|
+
# Return the number of days left before the GPG signing key expires or
|
120
|
+
# 0 if the key does not exist or the key is missing an expiration date.
|
99
121
|
def dev_key_days_left
|
122
|
+
which('gpg', true)
|
100
123
|
ensure_gpg_directory
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
124
|
+
|
125
|
+
days_left = 0
|
126
|
+
cmd = "gpg --with-colons --homedir=#{@dir} --list-keys '<#{@key_email}>' 2>&1"
|
127
|
+
puts "Executing: #{cmd}" if @verbose
|
128
|
+
%x(#{cmd}).each_line do |line|
|
129
|
+
# See https://github.com/CSNW/gnupg/blob/master/doc/DETAILS
|
130
|
+
# Index Content
|
131
|
+
# 0 record type
|
132
|
+
# 6 expiration date
|
133
|
+
#
|
134
|
+
# If expiration date contains a 'T', it is in an ISO 8601 format
|
135
|
+
# (e.g., 20210223T091500). Otherwise it is seconds since the epoch.
|
136
|
+
#
|
137
|
+
fields = line.split(':')
|
138
|
+
if fields[0] && (fields[0] == 'pub')
|
139
|
+
raw_exp_date = fields[6]
|
140
|
+
unless raw_exp_date.nil? || raw_exp_date.strip.empty?
|
141
|
+
require 'date'
|
142
|
+
|
143
|
+
exp_date = nil
|
144
|
+
if raw_exp_date.include?('T')
|
145
|
+
exp_date = DateTime.parse(raw_exp_date).to_date
|
146
|
+
else
|
147
|
+
exp_date = Time.at(raw_exp_date.to_i).to_date
|
148
|
+
end
|
149
|
+
|
150
|
+
days_left = (exp_date - Date.today).to_i
|
151
|
+
days_left = 0 if days_left < 0
|
152
|
+
end
|
153
|
+
|
154
|
+
break
|
155
|
+
end
|
106
156
|
end
|
157
|
+
|
107
158
|
days_left
|
108
159
|
end
|
109
160
|
|
@@ -135,36 +186,18 @@ module Simp
|
|
135
186
|
|
136
187
|
clean_gpg_agent_directory
|
137
188
|
write_genkey_parameter_file
|
138
|
-
write_gpg_agent_startup_script
|
139
189
|
|
190
|
+
agent_info = nil
|
140
191
|
begin
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
local_socket = File.join(Dir.pwd, 'S.gpg-agent')
|
146
|
-
|
147
|
-
# This condition was handled differently in previous logic.
|
148
|
-
#
|
149
|
-
# a.) As the surrounding logic works now, it will _always_ be a new
|
150
|
-
# agent by this point, because the directory is cleaned out
|
151
|
-
# b.) The agent's information will be read from the env-file it
|
152
|
-
# writes at startup
|
153
|
-
# c.) The old command `gpg-agent --homedir=#{Dir.pwd} /get serverpid`
|
154
|
-
# did not work on EL6 or EL7.
|
155
|
-
#
|
156
|
-
warn(empty_gpg_agent_message) if gpg_agent_output.empty?
|
157
|
-
|
158
|
-
agent_info = gpg_agent_info
|
159
|
-
|
160
|
-
# The socket is useful to get back info on the command line.
|
161
|
-
unless File.exist?(File.join(Dir.pwd, File.basename(agent_info[:socket])))
|
162
|
-
ln_s(agent_info[:socket], local_socket, :verbose => @verbose)
|
192
|
+
if gpg_version < Gem::Version.new('2.1')
|
193
|
+
agent_info = start_gpg_agent_old
|
194
|
+
else
|
195
|
+
agent_info = start_gpg_agent
|
163
196
|
end
|
164
|
-
generate_key(agent_info[:info])
|
165
197
|
ensure
|
166
|
-
kill_agent(agent_info[:pid])
|
198
|
+
kill_agent(agent_info[:pid]) if agent_info
|
167
199
|
end
|
200
|
+
|
168
201
|
agent_info
|
169
202
|
end
|
170
203
|
end
|
@@ -174,7 +207,7 @@ module Simp
|
|
174
207
|
#
|
175
208
|
# @return [String] Warning message
|
176
209
|
def empty_gpg_agent_message
|
177
|
-
|
210
|
+
<<~WARNING
|
178
211
|
WARNING: Tried to start an project-only gpg-agent daemon on a random socket by
|
179
212
|
running the script:
|
180
213
|
|
@@ -195,7 +228,6 @@ module Simp
|
|
195
228
|
#
|
196
229
|
# @param pid [String] The GPG Agent PID to kill
|
197
230
|
def kill_agent(pid)
|
198
|
-
rm('S.gpg-agent') if File.symlink?('S.gpg-agent')
|
199
231
|
if pid
|
200
232
|
Process.kill(0, pid)
|
201
233
|
Process.kill(15, pid)
|
@@ -209,11 +241,18 @@ module Simp
|
|
209
241
|
# @param gpg_agent_info_str [String] value to set the GPG_AGENT_INFO
|
210
242
|
# environment variable to use in order to use the correct `gpg-agent`.
|
211
243
|
def generate_key(gpg_agent_info_str)
|
244
|
+
which('gpg', true)
|
245
|
+
|
212
246
|
puts "Generating new GPG key#{@verbose ? " under '#{@dir}'" : ''}..."
|
213
247
|
gpg_cmd = %(GPG_AGENT_INFO=#{gpg_agent_info_str} gpg --homedir="#{@dir}")
|
248
|
+
|
214
249
|
pipe = @verbose ? '| tee' : '>'
|
215
|
-
|
216
|
-
|
250
|
+
%x(#{gpg_cmd} --batch --gen-key #{GPG_GENKEY_PARAMS_FILENAME})
|
251
|
+
%x(#{gpg_cmd} --armor --export '<#{@key_email}>' #{pipe} "#{@key_file}")
|
252
|
+
|
253
|
+
if File.stat(@key_file).size == 0
|
254
|
+
fail "Error: Something went wrong generating #{@key_file}"
|
255
|
+
end
|
217
256
|
end
|
218
257
|
|
219
258
|
# Return a data structure from a gpg-agent env-file formatted string.
|
@@ -225,6 +264,62 @@ module Simp
|
|
225
264
|
{ info: info.strip, socket: matches[:socket], pid: matches[:pid].to_i }
|
226
265
|
end
|
227
266
|
|
267
|
+
# Start the gpg-agent
|
268
|
+
# @return Hash of agent info
|
269
|
+
# @raise if gpg-agent fails to start
|
270
|
+
def start_gpg_agent
|
271
|
+
which('gpg', true)
|
272
|
+
which('gpg-agent', true)
|
273
|
+
which('gpg-connect-agent', true)
|
274
|
+
|
275
|
+
# Start the GPG agent, if it is not already running
|
276
|
+
check_agent = "gpg-agent -q --homedir=#{Dir.pwd} >&/dev/null"
|
277
|
+
start_agent = "gpg-agent --homedir=#{Dir.pwd} --daemon >&/dev/null"
|
278
|
+
cmd = "#{check_agent} || #{start_agent}"
|
279
|
+
puts "Executing: #{cmd}" if @verbose
|
280
|
+
%x(#{cmd})
|
281
|
+
if $? && ($?.exitstatus != 0)
|
282
|
+
err_msg = [
|
283
|
+
'Failed to start gpg-agent during key creation.',
|
284
|
+
" Execute '#{start_agent.gsub(' >&/dev/null','')}' to debug."
|
285
|
+
].join("\n")
|
286
|
+
raise(err_msg)
|
287
|
+
end
|
288
|
+
|
289
|
+
agent_info = {}
|
290
|
+
|
291
|
+
# Provide a local socket (needed by the `gpg` command when
|
292
|
+
agent_info[:socket] = %x{echo 'GETINFO socket_name' | gpg-connect-agent --homedir=#{Dir.pwd}}.lines.first[1..-1].strip
|
293
|
+
|
294
|
+
# Get the pid
|
295
|
+
agent_info[:pid] = %x{echo 'GETINFO pid' | gpg-connect-agent --homedir=#{Dir.pwd}}.lines.first[1..-1].strip.to_i
|
296
|
+
|
297
|
+
generate_key(%{#{agent_info[:socket]}:#{agent_info[:pid]}:1})
|
298
|
+
|
299
|
+
agent_info
|
300
|
+
end
|
301
|
+
|
302
|
+
# Start the gpg-agent with options suitable for gpg version < 2.1
|
303
|
+
# @return Hash of agent info
|
304
|
+
def start_gpg_agent_old
|
305
|
+
write_gpg_agent_startup_script
|
306
|
+
gpg_agent_output = %x(./#{@gpg_agent_script}).strip
|
307
|
+
|
308
|
+
# By the time we get here, we can be assured we will be starting a
|
309
|
+
# new agent, because the directory is cleaned out.
|
310
|
+
#
|
311
|
+
# Follow-on gpg actions will read the agent's information from
|
312
|
+
# the env-file the agent writes at startup.
|
313
|
+
|
314
|
+
# We're using the --sh option which will spew out the agent config
|
315
|
+
# when the agent starts. If it is empty, this is a problem.
|
316
|
+
warn(empty_gpg_agent_message) if gpg_agent_output.empty?
|
317
|
+
|
318
|
+
agent_info = gpg_agent_info
|
319
|
+
generate_key(agent_info[:info])
|
320
|
+
agent_info
|
321
|
+
end
|
322
|
+
|
228
323
|
# Write the `gpg --genkey --batch` control parameter file
|
229
324
|
#
|
230
325
|
# @see "Unattended key generation" in /usr/share/doc/gnupg2-*/DETAILS for
|
@@ -232,38 +327,46 @@ module Simp
|
|
232
327
|
def write_genkey_parameter_file
|
233
328
|
now = Time.now.to_i.to_s
|
234
329
|
expire_date = Date.today + 14
|
235
|
-
passphrase = SecureRandom.base64(
|
236
|
-
genkey_parameters =
|
237
|
-
%echo Generating Development GPG Key
|
238
|
-
%echo
|
239
|
-
%echo This key will expire on #{expire_date}
|
240
|
-
%echo
|
241
|
-
Key-Type: RSA
|
242
|
-
Key-Length: 4096
|
243
|
-
Key-Usage: sign
|
244
|
-
Name-Real: SIMP Development
|
245
|
-
Name-Comment: Development key #{now}
|
246
|
-
Name-Email: #{@key_email}
|
247
|
-
Expire-Date: 2w
|
248
|
-
Passphrase: #{passphrase}
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
%
|
253
|
-
|
254
|
-
|
255
|
-
|
330
|
+
passphrase = SecureRandom.base64(100)
|
331
|
+
genkey_parameters = [
|
332
|
+
'%echo Generating Development GPG Key',
|
333
|
+
'%echo',
|
334
|
+
"%echo This key will expire on #{expire_date}",
|
335
|
+
'%echo',
|
336
|
+
'Key-Type: RSA',
|
337
|
+
'Key-Length: 4096',
|
338
|
+
'Key-Usage: sign',
|
339
|
+
'Name-Real: SIMP Development',
|
340
|
+
"Name-Comment: Development key #{now}",
|
341
|
+
"Name-Email: #{@key_email}",
|
342
|
+
'Expire-Date: 2w',
|
343
|
+
"Passphrase: #{passphrase}",
|
344
|
+
]
|
345
|
+
|
346
|
+
if gpg_version < Gem::Version.new('2.1')
|
347
|
+
genkey_parameters << '%pubring pubring.gpg'
|
348
|
+
genkey_parameters << '%secring secring.gpg'
|
349
|
+
end
|
350
|
+
|
351
|
+
genkey_parameters << '# The following creates the key, so we can print "Done!" afterwards'
|
352
|
+
genkey_parameters << '%commit'
|
353
|
+
genkey_parameters << '%echo New GPG Development Key Created'
|
354
|
+
|
355
|
+
File.open(GPG_GENKEY_PARAMS_FILENAME, 'w') { |fh| fh.puts(genkey_parameters.join("\n")) }
|
256
356
|
end
|
257
357
|
|
258
358
|
# Write a local gpg-agent daemon script file
|
259
359
|
def write_gpg_agent_startup_script
|
260
|
-
|
360
|
+
which('gpg-agent', true)
|
361
|
+
pinentry_cmd = which('pinentry-curses', true)
|
362
|
+
|
363
|
+
gpg_agent_script = <<~AGENT_SCRIPT
|
261
364
|
#!/bin/sh
|
262
365
|
|
263
366
|
gpg-agent --homedir=#{Dir.pwd} --daemon \
|
264
367
|
--no-use-standard-socket --sh --batch \
|
265
368
|
--write-env-file "#{@gpg_agent_env_file}" \
|
266
|
-
--pinentry-program
|
369
|
+
--pinentry-program #{pinentry_cmd} < /dev/null &
|
267
370
|
AGENT_SCRIPT
|
268
371
|
|
269
372
|
File.open(@gpg_agent_script, 'w') { |fh| fh.puts(gpg_agent_script) }
|