subspace 0.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +380 -0
  6. data/README.md +511 -9
  7. data/TODO +34 -0
  8. data/UPGRADING.md +10 -0
  9. data/ansible/playbooks/local_template.yml +13 -0
  10. data/ansible/playbooks/maintenance_mode.yml +5 -0
  11. data/ansible/roles/alienvault/tasks/main.yml +29 -0
  12. data/ansible/roles/apache/defaults/main.yml +2 -5
  13. data/ansible/roles/apache/handlers/main.yml +9 -1
  14. data/ansible/roles/apache/tasks/main.yml +37 -9
  15. data/ansible/roles/apache/templates/server_status.conf +6 -0
  16. data/ansible/roles/apache-rails/tasks/main.yml +26 -0
  17. data/ansible/roles/apache-rails/templates/_canonical_domain.conf +10 -0
  18. data/ansible/roles/apache-rails/templates/_rails.conf +23 -0
  19. data/ansible/roles/apache-rails/templates/project-ssl.conf +23 -0
  20. data/ansible/roles/apache-rails/templates/project.conf +5 -0
  21. data/ansible/roles/collectd/defaults/main.yml +3 -0
  22. data/ansible/roles/collectd/handlers/main.yml +3 -0
  23. data/ansible/roles/collectd/tasks/main.yml +82 -0
  24. data/ansible/roles/collectd/templates/apache2.conf +6 -0
  25. data/ansible/roles/collectd/templates/delayed_job_postgres.conf +21 -0
  26. data/ansible/roles/collectd/templates/df.conf +16 -0
  27. data/ansible/roles/collectd/templates/graphite.conf +14 -0
  28. data/ansible/roles/collectd/templates/hostname.conf +2 -0
  29. data/ansible/roles/collectd/templates/nginx.conf +28 -0
  30. data/ansible/roles/collectd/templates/nodejs-process.conf +3 -0
  31. data/ansible/roles/collectd/templates/puma-process.conf +3 -0
  32. data/ansible/roles/collectd/templates/rails_lograge.conf +31 -0
  33. data/ansible/roles/common/defaults/main.yml +2 -1
  34. data/ansible/roles/common/files/sudoers-service +1 -0
  35. data/ansible/roles/common/tasks/main.yml +307 -19
  36. data/ansible/roles/common/tasks/no_swap.yml +26 -0
  37. data/ansible/roles/common/tasks/swap.yml +34 -8
  38. data/ansible/roles/common/templates/motd +13 -0
  39. data/ansible/roles/common/templates/motd2 +24 -0
  40. data/ansible/roles/common/templates/terminalcolor +25 -0
  41. data/ansible/roles/delayed_job/README.md +2 -4
  42. data/ansible/roles/delayed_job/defaults/main.yml +0 -2
  43. data/ansible/roles/delayed_job/handlers/main.yml +1 -1
  44. data/ansible/roles/delayed_job/tasks/main.yml +22 -29
  45. data/ansible/roles/delayed_job/templates/delayed-job-monit-rc +6 -5
  46. data/ansible/roles/delayed_job/templates/delayed-job-systemd.service +33 -0
  47. data/ansible/roles/gem-patch-report/README.md +137 -0
  48. data/ansible/roles/gem-patch-report/defaults/main.yml +2 -0
  49. data/ansible/roles/gem-patch-report/tasks/main.yml +89 -0
  50. data/ansible/roles/gem-patch-report/templates/gem-patch-report.sh.j2 +114 -0
  51. data/ansible/roles/letsencrypt/defaults/main.yml +11 -1
  52. data/ansible/roles/letsencrypt/tasks/legacy.yml +44 -0
  53. data/ansible/roles/letsencrypt/tasks/main.yml +72 -76
  54. data/ansible/roles/letsencrypt/tasks/modern.yml +39 -0
  55. data/ansible/roles/logrotate/LICENSE +27 -0
  56. data/ansible/roles/logrotate/README.md +70 -0
  57. data/ansible/roles/logrotate/defaults/main.yml +2 -0
  58. data/ansible/roles/logrotate/meta/main.yml +18 -0
  59. data/ansible/roles/logrotate/tasks/main.yml +15 -0
  60. data/ansible/roles/logrotate/templates/logrotate.d.j2 +16 -0
  61. data/ansible/roles/memcache/defaults/main.yml +2 -0
  62. data/ansible/roles/memcache/tasks/main.yml +16 -1
  63. data/ansible/roles/mysql/meta/main.yml +1 -1
  64. data/ansible/roles/mysql/tasks/main.yml +2 -2
  65. data/ansible/roles/mysql2_gem/meta/main.yml +1 -1
  66. data/ansible/roles/mysql2_gem/tasks/main.yml +1 -1
  67. data/ansible/roles/newrelic/tasks/main.yml +8 -1
  68. data/ansible/roles/newrelic-infra/defaults/main.yml +2 -0
  69. data/ansible/roles/newrelic-infra/handlers/main.yml +5 -0
  70. data/ansible/roles/newrelic-infra/tasks/main.yml +38 -0
  71. data/ansible/roles/newrelic-infra/templates/logs.yml.j2 +5 -0
  72. data/ansible/roles/newrelic-infra/templates/newrelic-infra.yml.j2 +2 -0
  73. data/ansible/roles/nginx/defaults/main.yml +4 -0
  74. data/ansible/roles/nginx/handlers/main.yml +12 -0
  75. data/ansible/roles/nginx/tasks/main.yml +113 -14
  76. data/ansible/roles/nginx/templates/nginx.conf +29 -0
  77. data/ansible/roles/nginx/templates/status +10 -0
  78. data/ansible/roles/nginx-maintenance/tasks/main.yml +33 -0
  79. data/ansible/roles/nginx-rails/defaults/main.yml +6 -0
  80. data/ansible/roles/nginx-rails/tasks/main.yml +54 -0
  81. data/ansible/roles/nginx-rails/templates/_asset_cors.conf +11 -0
  82. data/ansible/roles/nginx-rails/templates/_rails.conf +35 -0
  83. data/ansible/roles/nginx-rails/templates/_upstream.conf +11 -0
  84. data/ansible/roles/nginx-rails/templates/default_server +5 -0
  85. data/ansible/roles/nginx-rails/templates/nginx-project +9 -0
  86. data/ansible/roles/nginx-rails/templates/nginx-project-ssl +23 -0
  87. data/ansible/roles/nodejs/tasks/main.yml +33 -0
  88. data/ansible/roles/papertrail/tasks/main.yml +23 -4
  89. data/ansible/roles/papertrail/templates/log_files.yml +8 -1
  90. data/ansible/roles/postgis/.gitignore +3 -0
  91. data/ansible/roles/postgis/CHANGELOG.md +24 -0
  92. data/ansible/roles/postgis/LICENSE +202 -0
  93. data/ansible/roles/postgis/README.md +12 -0
  94. data/ansible/roles/postgis/meta/main.yml +15 -0
  95. data/ansible/roles/postgis/tasks/main.yml +20 -0
  96. data/ansible/roles/postgresql/README.md +15 -0
  97. data/ansible/roles/postgresql/defaults/main.yml +3 -0
  98. data/ansible/roles/postgresql/handlers/main.yml +1 -1
  99. data/ansible/roles/postgresql/meta/main.yml +1 -6
  100. data/ansible/roles/postgresql/tasks/backups.yml +8 -6
  101. data/ansible/roles/postgresql/tasks/main.yml +89 -9
  102. data/ansible/roles/postgresql/templates/backup.sh +17 -2
  103. data/ansible/roles/postgresql-client/tasks/main.yml +91 -0
  104. data/ansible/roles/puma/tasks/main.yml +38 -19
  105. data/ansible/roles/puma/templates/puma-monit-rc +5 -0
  106. data/ansible/roles/puma/templates/puma-systemd.service +43 -0
  107. data/ansible/roles/puma/templates/puma-systemd.socket +14 -0
  108. data/ansible/roles/puma/templates/puma.rb +24 -12
  109. data/ansible/roles/rails/defaults/main.yml +1 -3
  110. data/ansible/roles/rails/tasks/main.yml +76 -18
  111. data/ansible/roles/rails/templates/application.yml +1 -1
  112. data/ansible/roles/rails/templates/database.yml +3 -3
  113. data/ansible/roles/redis/defaults/main.yml +2 -0
  114. data/ansible/roles/redis/tasks/main.yml +45 -3
  115. data/ansible/roles/resque/tasks/main.yml +14 -0
  116. data/ansible/roles/resque/templates/resque-monit-rc +4 -0
  117. data/ansible/roles/resque/templates/resque-systemd.service +54 -0
  118. data/ansible/roles/ruby-common/README.md +1 -1
  119. data/ansible/roles/ruby-common/defaults/main.yml +1 -0
  120. data/ansible/roles/ruby-common/tasks/main.yml +55 -13
  121. data/ansible/roles/sidekiq/README.md +1 -0
  122. data/ansible/roles/sidekiq/defaults/main.yml +2 -0
  123. data/ansible/roles/sidekiq/tasks/main.yml +15 -0
  124. data/ansible/roles/sidekiq/templates/sidekiq-monit-rc +4 -0
  125. data/ansible/roles/sidekiq/templates/sidekiq-systemd.service +63 -0
  126. data/ansible/roles/tailscale/defaults/main.yml +2 -0
  127. data/ansible/roles/tailscale/tasks/main.yml +40 -0
  128. data/ansible/roles/yarn/tasks/main.yml +19 -0
  129. data/ansible/roles/zenoamaro.postgresql/.gitignore +1 -0
  130. data/ansible/roles/zenoamaro.postgresql/.travis.yml +28 -0
  131. data/ansible/roles/zenoamaro.postgresql/LICENSE.md +21 -0
  132. data/ansible/roles/zenoamaro.postgresql/README.md +117 -0
  133. data/ansible/roles/zenoamaro.postgresql/Vagrantfile +62 -0
  134. data/ansible/roles/zenoamaro.postgresql/boxed.yml +26 -0
  135. data/ansible/roles/zenoamaro.postgresql/defaults/main.yml +607 -0
  136. data/ansible/roles/zenoamaro.postgresql/handlers/main.yml +8 -0
  137. data/ansible/roles/zenoamaro.postgresql/inventory +19 -0
  138. data/ansible/roles/zenoamaro.postgresql/main.yml +19 -0
  139. data/ansible/roles/zenoamaro.postgresql/meta/.galaxy_install_info +1 -0
  140. data/ansible/roles/zenoamaro.postgresql/meta/main.yml +21 -0
  141. data/ansible/roles/zenoamaro.postgresql/tasks/configure.yml +55 -0
  142. data/ansible/roles/zenoamaro.postgresql/tasks/extensions.yml +49 -0
  143. data/ansible/roles/zenoamaro.postgresql/tasks/install.yml +51 -0
  144. data/ansible/roles/zenoamaro.postgresql/tasks/main.yml +5 -0
  145. data/ansible/roles/zenoamaro.postgresql/templates/environment +11 -0
  146. data/ansible/roles/zenoamaro.postgresql/templates/pg_ctl.conf +5 -0
  147. data/ansible/roles/zenoamaro.postgresql/templates/pg_hba.conf +112 -0
  148. data/ansible/roles/zenoamaro.postgresql/templates/pg_ident.conf +46 -0
  149. data/ansible/roles/zenoamaro.postgresql/templates/postgresql.conf +536 -0
  150. data/ansible/roles/zenoamaro.postgresql/test.yml +24 -0
  151. data/bin/console +0 -4
  152. data/exe/subspace +3 -84
  153. data/lib/subspace/cli.rb +168 -0
  154. data/lib/subspace/commands/ansible.rb +35 -0
  155. data/lib/subspace/commands/base.rb +94 -0
  156. data/lib/subspace/commands/bootstrap.rb +49 -0
  157. data/lib/subspace/commands/configure.rb +27 -0
  158. data/lib/subspace/commands/exec.rb +20 -0
  159. data/lib/subspace/commands/init.rb +144 -0
  160. data/lib/subspace/commands/inventory.rb +54 -0
  161. data/lib/subspace/commands/maintain.rb +16 -0
  162. data/lib/subspace/commands/maintenance_mode.rb +16 -0
  163. data/lib/subspace/commands/override.rb +21 -0
  164. data/lib/subspace/commands/provision.rb +14 -0
  165. data/lib/subspace/commands/secrets.rb +69 -0
  166. data/lib/subspace/commands/ssh.rb +33 -0
  167. data/lib/subspace/commands/terraform.rb +89 -0
  168. data/lib/subspace/configuration.rb +71 -0
  169. data/lib/subspace/inventory.rb +144 -0
  170. data/lib/subspace/version.rb +1 -1
  171. data/lib/subspace.rb +8 -1
  172. data/subspace.gemspec +14 -3
  173. data/template/provision.rb.erb +94 -0
  174. data/template/subspace/.gitignore +6 -0
  175. data/template/subspace/ansible.cfg.erb +17 -0
  176. data/template/subspace/group_vars/all.erb +28 -0
  177. data/template/subspace/group_vars/template.erb +26 -0
  178. data/template/subspace/inventory.yml.erb +12 -0
  179. data/template/subspace/playbook.yml.erb +18 -0
  180. data/template/subspace/secrets/template.erb +5 -0
  181. data/template/subspace/templates/application.yml.template +27 -0
  182. data/template/subspace/templates/authorized_keys.erb +1 -0
  183. data/template/subspace/terraform/.gitignore +2 -0
  184. data/template/subspace/terraform/template/main-oxenwagen.tf.erb +116 -0
  185. data/template/subspace/terraform/template/main-workhorse.tf.erb +41 -0
  186. data/template/subspace/terraformrc.erb +9 -0
  187. data/terraform/modules/s3_backend/README +2 -0
  188. data/terraform/modules/s3_backend/dynamodb.tf +1 -0
  189. data/terraform/modules/s3_backend/iam_user.tf +38 -0
  190. data/terraform/modules/s3_backend/main.tf +39 -0
  191. data/terraform/modules/s3_backend/state_bucket.tf +14 -0
  192. metadata +198 -29
  193. data/ansible/roles/apache/templates/project.conf +0 -25
  194. data/ansible/roles/aws/tasks/main.yml +0 -46
  195. data/ansible/roles/delayed_job/files/deploy-service +0 -2
  196. data/ansible/roles/delayed_job/files/monit-http.conf +0 -3
  197. data/ansible/roles/letsencrypt/templates/project-le-ssl.conf +0 -31
  198. data/ansible/roles/nginx/templates/nginx-project +0 -27
  199. data/ansible/roles/puma/templates/etc-init-puma-manager.conf +0 -31
  200. data/ansible/roles/puma/templates/etc-init-puma.conf +0 -69
  201. data/lib/subspace/railtie.rb +0 -9
  202. data/lib/tasks/provision.rake +0 -12
  203. data/template/provision/.gitignore +0 -1
  204. data/template/provision/ansible.cfg.erb +0 -5
  205. data/template/provision/group_vars/all.erb +0 -12
  206. data/template/provision/group_vars/template.erb +0 -14
  207. data/template/provision/host_vars/template.erb +0 -4
  208. data/template/provision/playbook.yml.erb +0 -26
  209. data/template/provision/vars/template.erb +0 -4
  210. /data/template/{provision → subspace}/hosts.erb +0 -0
@@ -0,0 +1,137 @@
1
+ # Gem Patch Report Role
2
+
3
+ This Ansible role generates reports on Ruby gems that had security vulnerabilities at the beginning of the current month and have since been patched. It compares the Gemfile.lock from the start of the month (retrieved from the Capistrano git repo) against the current Gemfile.lock using bundle-audit, and reports only the gems that have been fixed.
4
+
5
+ ## Requirements
6
+
7
+ - Ruby application deployed with Capistrano (requires the `repo/` directory)
8
+ - bundler-audit gem (automatically installed if missing)
9
+ - Stats server configuration (same as other subspace roles)
10
+
11
+ ## Role Variables
12
+
13
+ Available variables with their default values:
14
+
15
+ ```yaml
16
+ # Path to the Rails/Ruby application (Capistrano current symlink)
17
+ gem_patch_report_app_path: "/u/apps/{{project_name}}/current"
18
+
19
+ # Required for stats reporting (inherited from other roles)
20
+ send_stats: false
21
+ stats_url: ""
22
+ stats_api_key: ""
23
+ hostname: ""
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ 1. Enable the role in your playbook:
29
+ ```yaml
30
+ roles:
31
+ - gem-patch-report
32
+ ```
33
+
34
+ 2. Configure the required variables:
35
+ ```yaml
36
+ send_stats: true
37
+ stats_url: "https://your-stats-server.com/api/stats"
38
+ stats_api_key: "your-api-key"
39
+ ```
40
+
41
+ ## How It Works
42
+
43
+ 1. Retrieves the Gemfile.lock from the last commit before the 1st of the current month using the Capistrano bare git repo at `<deploy_to>/repo/`
44
+ 2. Runs `bundle-audit` against both the old and current Gemfile.lock
45
+ 3. Compares the results to identify vulnerabilities that existed at the start of the month but are no longer present (i.e. patched)
46
+ 4. Outputs a report containing only the patched gems
47
+
48
+ ## Bundle-Audit Input Format
49
+
50
+ The role processes JSON output from `bundle-audit check --format json`. Here's the simplified structure:
51
+
52
+ ```json
53
+ {
54
+ "version": "0.9.2",
55
+ "created_at": "2026-03-06 12:16:58 -0600",
56
+ "results": [
57
+ {
58
+ "type": "unpatched_gem",
59
+ "gem": {
60
+ "name": "nokogiri",
61
+ "version": "1.18.9"
62
+ },
63
+ "advisory": {
64
+ "id": "GHSA-wx95-c6cv-8532",
65
+ "title": "Nokogiri does not check the return value from xmlC14NExecute",
66
+ "criticality": "medium",
67
+ "cve": null,
68
+ "patched_versions": [">= 1.19.1"]
69
+ }
70
+ }
71
+ ]
72
+ }
73
+ ```
74
+
75
+ ### Key Fields Used
76
+
77
+ The role extracts data from these fields:
78
+ - `results[].type` - Filters for `"unpatched_gem"`
79
+ - `results[].gem.name` - Gem name
80
+ - `results[].gem.version` - Vulnerable version
81
+ - `results[].advisory.id` - Advisory ID (CVE, GHSA, etc.)
82
+ - `results[].advisory.criticality` - Severity level
83
+
84
+ ## Report Format
85
+
86
+ The role generates a JSON array of gems that were patched during the current month. If a gem had multiple advisories that were all fixed, each advisory appears as its own entry.
87
+
88
+ ```json
89
+ [
90
+ {
91
+ "name": "activestorage",
92
+ "version": "8.0.2.1",
93
+ "current_version": "8.0.4.1",
94
+ "advisory_id": "CVE-2026-33658",
95
+ "criticality": null
96
+ },
97
+ {
98
+ "name": "bcrypt",
99
+ "version": "3.1.20",
100
+ "current_version": "3.1.22",
101
+ "advisory_id": "CVE-2026-33306",
102
+ "criticality": null
103
+ },
104
+ {
105
+ "name": "devise",
106
+ "version": "4.9.4",
107
+ "current_version": "5.0.3",
108
+ "advisory_id": "CVE-2026-32700",
109
+ "criticality": null
110
+ }
111
+ ]
112
+ ```
113
+
114
+ ### Gem Objects
115
+
116
+ Each gem object contains:
117
+ - `name`: The gem name
118
+ - `version`: The vulnerable version from the start of the month
119
+ - `current_version`: The current patched version (parsed from the current Gemfile.lock)
120
+ - `advisory_id`: The security advisory ID (CVE, GHSA, etc.)
121
+ - `criticality`: The severity level (low, medium, high, critical, or null if not specified)
122
+
123
+ ## Tags
124
+
125
+ This role supports the following tags:
126
+ - `maintenance`
127
+ - `stats`
128
+ - `gem-patch-report`
129
+
130
+ ## Error Handling
131
+
132
+ The role includes error handling for common scenarios:
133
+ - Missing Gemfile.lock
134
+ - No git history before the current month
135
+ - bundle-audit execution failures
136
+
137
+ Errors are logged but don't fail the entire playbook execution. If no patched gems are found, an empty array `[]` is reported.
@@ -0,0 +1,2 @@
1
+ ---
2
+ gem_patch_report_app_path: "/u/apps/{{project_name}}/current"
@@ -0,0 +1,89 @@
1
+ ---
2
+ - name: Check if gem patch reporting is enabled and required variables are set
3
+ debug:
4
+ msg: "Gem patch reporting is enabled"
5
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
6
+ tags:
7
+ - maintenance
8
+ - stats
9
+ - gem-patch-report
10
+
11
+ - name: Install bundler-audit gem globally
12
+ gem:
13
+ name: bundler-audit
14
+ state: present
15
+ user_install: false
16
+ become: true
17
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
18
+ tags:
19
+ - maintenance
20
+ - stats
21
+ - gem-patch-report
22
+
23
+ - name: Generate gem patch report script
24
+ template:
25
+ src: gem-patch-report.sh.j2
26
+ dest: /tmp/gem-patch-report.sh
27
+ mode: '0755'
28
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
29
+ tags:
30
+ - maintenance
31
+ - stats
32
+ - gem-patch-report
33
+
34
+ - name: Run gem patch report script
35
+ shell: /tmp/gem-patch-report.sh
36
+ register: gem_patch_report_result
37
+ become: true
38
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
39
+ tags:
40
+ - maintenance
41
+ - stats
42
+ - gem-patch-report
43
+ ignore_errors: yes
44
+
45
+ - name: Read gem patch report file
46
+ slurp:
47
+ src: /tmp/gem-patch-report.json
48
+ register: gem_patch_report_file
49
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
50
+ tags:
51
+ - maintenance
52
+ - stats
53
+ - gem-patch-report
54
+ ignore_errors: yes
55
+
56
+ - name: Send gem patch report to stats server
57
+ uri:
58
+ url: "{{ stats_url }}"
59
+ method: POST
60
+ headers:
61
+ X-API-Version: 1
62
+ X-Client-Api-key: "{{ stats_api_key }}"
63
+ body_format: json
64
+ body:
65
+ client_stat:
66
+ stat_type: gem_patch_report
67
+ value: "{{ (gem_patch_report_file.content | b64decode) | from_json }}"
68
+ hostname: "{{ hostname }}"
69
+ when: send_stats == true and stats_url is defined and stats_api_key is defined and gem_patch_report_file is defined and gem_patch_report_file is not failed
70
+ tags:
71
+ - maintenance
72
+ - stats
73
+ - gem-patch-report
74
+ ignore_errors: yes
75
+
76
+ - name: Clean up temporary gem patch report files
77
+ file:
78
+ path: "{{ item }}"
79
+ state: absent
80
+ become: true
81
+ loop:
82
+ - /tmp/gem-patch-report.sh
83
+ - /tmp/gem-patch-report.json
84
+ when: send_stats == true and stats_url is defined and stats_api_key is defined
85
+ tags:
86
+ - maintenance
87
+ - stats
88
+ - gem-patch-report
89
+ ignore_errors: yes
@@ -0,0 +1,114 @@
1
+ #!/bin/bash
2
+
3
+ APP_PATH="{{ gem_patch_report_app_path }}"
4
+ DEPLOY_DIR=$(cd "$APP_PATH" && cd .. && pwd)
5
+ REPO_DIR="$DEPLOY_DIR/repo"
6
+ TEMP_DIR="/tmp/gem-patch-report-$$"
7
+ REPORT_FILE="$TEMP_DIR/report.json"
8
+ OLD_AUDIT_FILE="$TEMP_DIR/audit_old.json"
9
+ CURRENT_AUDIT_FILE="$TEMP_DIR/audit_current.json"
10
+ OLD_GEMFILE_LOCK="$APP_PATH/Gemfile.lock.old"
11
+
12
+ # Create temp directory
13
+ mkdir -p "$TEMP_DIR"
14
+
15
+ # Check if current Gemfile.lock exists
16
+ if [ ! -f "$APP_PATH/Gemfile.lock" ]; then
17
+ echo '[]' > /tmp/gem-patch-report.json
18
+ rm -rf "$TEMP_DIR"
19
+ exit 0
20
+ fi
21
+
22
+ # Update bundle-audit advisory database
23
+ cd "$APP_PATH"
24
+ bundle exec bundle-audit update 2>/dev/null || true
25
+
26
+ # Get old Gemfile.lock from the beginning of the month
27
+ FIRST_OF_MONTH=$(date +"%Y-%m-01")
28
+ OLD_COMMIT=$(git -c safe.directory="$REPO_DIR" --git-dir="$REPO_DIR" log --all --before="$FIRST_OF_MONTH" -1 --format="%H" -- Gemfile.lock 2>/dev/null)
29
+
30
+ if [ -z "$OLD_COMMIT" ]; then
31
+ # No commit before this month, nothing to compare
32
+ echo '[]' > /tmp/gem-patch-report.json
33
+ rm -rf "$TEMP_DIR"
34
+ exit 0
35
+ fi
36
+
37
+ git -c safe.directory="$REPO_DIR" --git-dir="$REPO_DIR" show "${OLD_COMMIT}:Gemfile.lock" > "$OLD_GEMFILE_LOCK"
38
+
39
+ # Run bundle-audit on the old Gemfile.lock
40
+ # bundle-audit exits non-zero when vulnerabilities are found, so ignore the exit code
41
+ bundle exec bundle-audit check --gemfile-lock Gemfile.lock.old --format json > "$OLD_AUDIT_FILE" 2>/dev/null || true
42
+
43
+ # Run bundle-audit on current Gemfile.lock
44
+ bundle exec bundle-audit check --format json > "$CURRENT_AUDIT_FILE" 2>/dev/null || true
45
+
46
+ # Set environment variables for Ruby script
47
+ export OLD_AUDIT_FILE="$OLD_AUDIT_FILE"
48
+ export CURRENT_AUDIT_FILE="$CURRENT_AUDIT_FILE"
49
+ export CURRENT_GEMFILE_LOCK="$APP_PATH/Gemfile.lock"
50
+
51
+ # Generate patch report using Ruby
52
+ ruby << 'RUBY' > "$REPORT_FILE"
53
+ require 'json'
54
+ require 'set'
55
+
56
+ begin
57
+ old_audit = JSON.parse(File.read(ENV['OLD_AUDIT_FILE']))
58
+ current_audit = JSON.parse(File.read(ENV['CURRENT_AUDIT_FILE']))
59
+
60
+ old_results = old_audit['results'] || []
61
+ current_results = current_audit['results'] || []
62
+
63
+ # Build a set of current vulnerability keys (gem name + advisory id)
64
+ current_vuln_keys = current_results
65
+ .select { |r| r['type'] == 'unpatched_gem' && r['gem'] && r['advisory'] }
66
+ .map { |r| "#{r['gem']['name']}:#{r['advisory']['id']}" }
67
+ .to_set
68
+
69
+ # Parse current Gemfile.lock to get current gem versions
70
+ current_versions = {}
71
+ gemfile_lock = File.read(ENV['CURRENT_GEMFILE_LOCK']) rescue ''
72
+ in_specs = false
73
+ gemfile_lock.each_line do |line|
74
+ if line.strip == 'specs:'
75
+ in_specs = true
76
+ next
77
+ end
78
+ if in_specs
79
+ if line =~ /^\s{4}(\S+)\s+\(([^)]+)\)/
80
+ current_versions[$1] = $2
81
+ elsif line !~ /^\s/
82
+ in_specs = false
83
+ end
84
+ end
85
+ end
86
+
87
+ # Only include gems that were vulnerable at start of month but are now patched
88
+ patched_gems = old_results
89
+ .select { |r| r['type'] == 'unpatched_gem' && r['gem'] && r['advisory'] }
90
+ .reject { |r| current_vuln_keys.include?("#{r['gem']['name']}:#{r['advisory']['id']}") }
91
+ .map { |r|
92
+ {
93
+ 'name' => r['gem']['name'],
94
+ 'version' => r['gem']['version'],
95
+ 'current_version' => current_versions[r['gem']['name']] || 'unknown',
96
+ 'advisory_id' => r['advisory']['id'],
97
+ 'criticality' => r['advisory']['criticality']
98
+ }
99
+ }
100
+ .sort_by { |g| [g['name'], g['advisory_id']] }
101
+
102
+ puts JSON.pretty_generate(patched_gems)
103
+
104
+ rescue JSON::ParserError => e
105
+ puts '[]'
106
+ rescue => e
107
+ puts '[]'
108
+ end
109
+ RUBY
110
+
111
+ # Copy report to known location and clean up
112
+ cp "$REPORT_FILE" /tmp/gem-patch-report.json
113
+ rm -rf "$TEMP_DIR"
114
+ rm -f "$OLD_GEMFILE_LOCK"
@@ -1,2 +1,12 @@
1
1
  ---
2
- certbot_dir: "/home/ubuntu"
2
+ certbot_dir: "/opt/certbot"
3
+ le_ssl_cert:
4
+ cert_name: "{{server_name}}"
5
+ preferred_challenges: "http"
6
+ plugin: standalone
7
+ domains: "{{ [server_name] + server_aliases }}"
8
+
9
+ nginx_ssl_config: |
10
+ ssl_certificate /etc/letsencrypt/live/{{le_ssl_cert.cert_name}}/fullchain.pem;
11
+ ssl_certificate_key /etc/letsencrypt/live/{{le_ssl_cert.cert_name}}/privkey.pem;
12
+ include /etc/letsencrypt/options-ssl-nginx.conf;
@@ -0,0 +1,44 @@
1
+ ---
2
+ - name: Install certbot dependencies
3
+ become: true
4
+ apt:
5
+ pkg: "{{item}}"
6
+ state: present
7
+ with_items:
8
+ - augeas-lenses
9
+ - ca-certificates
10
+ - dialog
11
+ - gcc
12
+ - libaugeas0
13
+ - libffi-dev
14
+ - libpython-dev
15
+ - libpython2.7-dev
16
+ - libssl-dev
17
+ - python
18
+ - python-dev
19
+ - python-setuptools
20
+ - python-virtualenv
21
+ - python2.7
22
+ - python2.7-dev
23
+
24
+ - name: "Create certbot dir"
25
+ become: true
26
+ file:
27
+ path: "{{certbot_dir}}"
28
+ state: directory
29
+ mode: 0755
30
+
31
+ - name: "Set certbot binary"
32
+ set_fact:
33
+ certbot_bin: "{{certbot_dir}}/certbot_auto"
34
+
35
+ - name: Get certbot
36
+ become: true
37
+ get_url:
38
+ url: "https://dl.eff.org/certbot-auto"
39
+ dest: "{{certbot_bin}}"
40
+ mode: a+x
41
+
42
+
43
+
44
+
@@ -1,93 +1,89 @@
1
1
  ---
2
- - name: Install certbot dependencies
2
+ - name: Ensure nginx is installed (first time)
3
+ become: true
3
4
  apt:
4
- pkg: "{{item}}"
5
+ pkg: nginx
5
6
  state: present
6
- with_items:
7
- - augeas-lenses
8
- - ca-certificates
9
- - dialog
10
- - gcc
11
- - libaugeas0
12
- - libffi-dev
13
- - libpython-dev
14
- - libpython2.7-dev
15
- - libssl-dev
16
- - python
17
- - python-dev
18
- - python-setuptools
19
- - python-virtualenv
20
- - python2.7-dev
7
+ when: "'nginx' in role_names"
21
8
 
22
- - name: Get certbot
23
- get_url:
24
- url: "https://dl.eff.org/certbot-auto"
25
- dest: "{{certbot_dir}}"
26
- mode: a+x
9
+ - name: Attempt to install certbot from APT
10
+ become: true
11
+ ignore_errors: true
12
+ apt:
13
+ pkg: certbot
14
+ state: present
27
15
 
28
- - name: Run certbot
29
- command: "{{certbot_dir}}/certbot-auto certonly --email {{letsencrypt_email}} --domains {{([server_name] + server_aliases) | join(',')}} --apache --agree-tos"
30
- args:
31
- creates: /etc/letsencrypt/live/{{server_name}}/cert.pem
16
+ - name: "Detect if certbot was installed via APT"
17
+ shell: dpkg-query -W 'certbot'
18
+ ignore_errors: true
19
+ register: apt_certbot
32
20
 
33
- - name: Enable mod_rewrite
34
- apache2_module:
35
- name: rewrite
36
- state: present
37
- sudo: true
21
+ - name: "Modern Letsencrypt Installation (py3, apt version)"
22
+ include_tasks: modern.yml
23
+ when: apt_certbot is succeeded
38
24
 
39
- - name: Enable mod_ssl
40
- apache2_module:
41
- name: ssl
42
- state: present
43
- sudo: true
25
+ - name: "Legacy Letsencrypt Installation (py2, from source)"
26
+ include_tasks: legacy.yml
27
+ when: apt_certbot is failed
44
28
 
45
- - name: Create SSL Apache config
46
- template:
47
- src: project-le-ssl.conf
48
- dest: /etc/apache2/sites-available/{{project_name}}-le-ssl.conf
49
- sudo: true
50
- notify: apache restart
29
+ # Post install configuration
51
30
 
52
- - name: Symlink {{project_name}}-le-ssl.conf to sites-enabled
53
- file:
54
- src: /etc/apache2/sites-available/{{project_name}}-le-ssl.conf
55
- dest: /etc/apache2/sites-enabled/{{project_name}}-le-ssl.conf
56
- state: link
57
- sudo: true
58
- notify: apache restart
31
+ - name: shutdown webserver for standalone mode
32
+ debug: msg="Shutdown webserver"
33
+ notify: stop webserver
34
+ changed_when: true
59
35
 
60
- - name: Force redirect to https (1/3)
61
- lineinfile:
62
- dest: /etc/apache2/sites-available/{{project_name}}.conf
63
- line: "RewriteEngine on"
64
- state: present
65
- insertbefore: "</VirtualHost>"
66
- sudo: true
67
- notify: apache restart
36
+ - meta: flush_handlers
68
37
 
69
- - name: Force redirect to https (2/3)
70
- lineinfile:
71
- dest: /etc/apache2/sites-available/{{project_name}}.conf
72
- line: "RewriteCond %{SERVER_NAME} ={{server_name}}"
73
- state: present
74
- insertbefore: "</VirtualHost>"
75
- sudo: true
76
- notify: apache restart
38
+ - name: "wait for webserver to stop"
39
+ wait_for:
40
+ port: 80
41
+ delay: 1
42
+ state: stopped
77
43
 
78
- - name: Force redirect to https (3/3)
79
- lineinfile:
80
- dest: /etc/apache2/sites-available/{{project_name}}.conf
81
- line: "RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]"
82
- state: present
83
- insertbefore: "</VirtualHost>"
84
- sudo: true
85
- notify: apache restart
44
+ - name: Generate SSL Certificate
45
+ become: true
46
+ command:
47
+ argv:
48
+ - "{{ certbot_bin }}"
49
+ - certonly
50
+ - "--email"
51
+ - "{{ letsencrypt_email }}"
52
+ - "--domains"
53
+ - "{{ le_ssl_cert.domains | join(',') }}"
54
+ - "--preferred-challenges"
55
+ - "{{ le_ssl_cert.preferred_challenges }}"
56
+ - "--cert-name"
57
+ - "{{ le_ssl_cert.cert_name }}"
58
+ - "--{{ le_ssl_cert.plugin }}"
59
+ - "--manual-auth-hook=/bin/yes"
60
+ - "--agree-tos"
61
+ - "--expand"
62
+ - "--non-interactive"
63
+
64
+ - name: Update nginx default options
65
+ when: "'nginx' in role_names"
66
+ get_url:
67
+ url: https://raw.githubusercontent.com/certbot/certbot/main/certbot/src/certbot/_internal/plugins/nginx/tls_configs/options-ssl-nginx.conf
68
+ dest: /etc/letsencrypt/options-ssl-nginx.conf
69
+
70
+ - name: start webserver after standalone mode
71
+ debug: msg="Startup webserver"
72
+ notify: start webserver
73
+ changed_when: true
74
+
75
+ - name: Set path at top of crontab
76
+ cron:
77
+ name: PATH
78
+ env: yes
79
+ job: /usr/bin:/bin:/usr/sbin
86
80
 
87
81
  - name: Setup cron job to auto renew
82
+ become: true
83
+ when: "'nginx' in role_names"
88
84
  cron:
89
85
  name: Auto-renew SSL
90
- job: "{{certbot_dir}}/certbot-auto renew --quiet --no-self-upgrade"
91
- minute: 30
92
- hour: "0,12"
86
+ job: "{{certbot_bin}} renew --no-self-upgrade --nginx >> /var/log/cron.log 2>&1"
87
+ hour: "0"
88
+ minute: "33"
93
89
  state: present
@@ -0,0 +1,39 @@
1
+ ---
2
+ - name: Install ca-certificates
3
+ become: true
4
+ apt:
5
+ pkg: "{{item}}"
6
+ state: present
7
+ with_items:
8
+ - ca-certificates
9
+
10
+ - name: Install certbot-nginx
11
+ become: true
12
+ when: "'nginx' in role_names"
13
+ apt:
14
+ pkg: python3-certbot-nginx
15
+ state: present
16
+
17
+ - name: "Set certbot binary"
18
+ set_fact:
19
+ certbot_bin: "certbot"
20
+
21
+ - name: "Check for certbot-auto"
22
+ stat:
23
+ path: /opt/certbot/certbot-auto
24
+ register: certbot_auto_exists
25
+
26
+ - name: "Remove certbot-auto"
27
+ file:
28
+ path: /opt/certbot/certbot-auto
29
+ state: absent
30
+ when: certbot_auto_exists.stat.exists
31
+
32
+ - name: "Remove certbot-auto cron task"
33
+ cron:
34
+ name: Auto-renew SSL
35
+ job: "{{certbot_bin}} renew --no-self-upgrade --nginx >> /var/log/cron.log 2>&1"
36
+ hour: "0"
37
+ minute: "33"
38
+ state: absent
39
+ when: certbot_auto_exists.stat.exists
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2016-14, Nick Hammond
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of ansiblebit nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.