trek 2.5.0 → 2.7.0
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.
- checksums.yaml +4 -4
- data/.node-version +1 -1
- data/AGENTS.md +18 -14
- data/CHANGELOG.md +88 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +135 -124
- data/Makefile +9 -1
- data/README.md +17 -21
- data/app/components/trek/dashboard/tile_component/tile_component.css +9 -0
- data/app/components/trek/dashboard/tile_component/tile_component.html.slim +4 -2
- data/app/components/trek/dashboard/tile_component.rb +12 -2
- data/app/components/trek/form/content_editor_component/content_editor_component.css +9 -8
- data/app/components/trek/form/content_editor_component/content_editor_component.html.slim +19 -93
- data/app/components/trek/form/content_editor_component/content_editor_component.js +94 -251
- data/app/components/trek/form/content_editor_component/extensions/block_view.js +40 -0
- data/app/components/trek/form/content_editor_component/extensions/image_block.js +28 -26
- data/app/components/trek/form/content_editor_component/extensions/prompts_block.js +15 -26
- data/app/components/trek/form/content_editor_component/extensions/table_of_contents.js +1 -3
- data/app/components/trek/form/content_editor_component.rb +15 -0
- data/app/components/trek/form/image_field_component/image_field_component.css +40 -1
- data/app/components/trek/form/image_field_component/image_field_component.html.slim +0 -9
- data/app/components/trek/form/image_field_component/image_field_component.js +1 -2
- data/app/components/trek/form/image_field_component.rb +36 -9
- data/app/components/trek/form/password_strength_component/password_strength_component.css +2 -0
- data/app/components/trek/form/sound_field_component/sound_field_component.js +1 -2
- data/app/components/trek/security_check_component/security_check_component.css +69 -0
- data/app/components/trek/security_check_component/security_check_component.html.slim +19 -0
- data/app/components/trek/security_check_component/security_check_component.js +15 -0
- data/app/components/trek/security_check_component.rb +19 -0
- data/app/content/trek/content/cleaner.rb +53 -0
- data/app/content/trek/content/document.rb +2 -2
- data/app/content/trek/content/list_item.rb +1 -1
- data/app/content/trek/content/paragraph.rb +7 -2
- data/app/content/trek/content/prompts_block.rb +1 -2
- data/app/content/trek/content.rb +6 -0
- data/app/controllers/concerns/trek/auditable.rb +5 -2
- data/app/controllers/concerns/trek/localization.rb +6 -2
- data/app/controllers/concerns/trek/reorderable.rb +24 -6
- data/app/controllers/trek/csp_reports_controller.rb +14 -1
- data/app/controllers/trek/panels/prompts_controller.rb +1 -1
- data/app/controllers/trek/resource_controller.rb +5 -5
- data/app/jobs/trek/purge_expired_sessions_job.rb +4 -3
- data/app/jobs/trek/purge_expired_sign_in_codes_job.rb +15 -0
- data/app/models/concerns/trek/contentable.rb +15 -1
- data/app/models/concerns/trek/users/sign_in_code.rb +70 -0
- data/app/models/concerns/trek/users/sign_in_lockout.rb +4 -2
- data/app/policies/trek/security_check_policy.rb +8 -0
- data/app/uploaders/image_uploader.rb +77 -15
- data/app/views/trek/panels/links/_form.html.slim +2 -4
- data/app/views/trek/panels/prompts/create.turbo_stream.slim +0 -1
- data/config/locales/trek.en.yml +97 -11
- data/config/locales/trek.fr.yml +97 -11
- data/docs/.vitepress/config.mjs +5 -1
- data/docs/background-jobs.md +74 -0
- data/docs/content-editor.md +219 -0
- data/docs/customize.md +2 -0
- data/docs/deploy.md +69 -6
- data/docs/getting-started.md +16 -18
- data/docs/index.md +2 -2
- data/docs/personal-data.md +61 -0
- data/docs/proxies.md +2 -2
- data/docs/reference/components.md +4 -4
- data/docs/reference/concerns/contentable.md +10 -4
- data/docs/reference/concerns/formattable.md +1 -1
- data/docs/reference/concerns/fragmentable.md +12 -6
- data/docs/reference/concerns/orderable.md +2 -2
- data/docs/reference/concerns/search-engine-optimizable.md +1 -1
- data/docs/reference/concerns/searchable.md +14 -1
- data/docs/reference/concerns/sectionable.md +7 -3
- data/docs/reference/concerns/versionable.md +1 -1
- data/docs/reference/controllers.md +33 -1
- data/docs/reference/environment-variables.md +3 -2
- data/docs/reference/formatters.md +4 -31
- data/docs/reference/forms.md +7 -4
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +12 -13
- data/docs/reference/generators/install.md +23 -11
- data/docs/reference/generators/public-accounts.md +159 -0
- data/docs/reference/generators/scaffold.md +28 -9
- data/docs/reference/generators/security-headers.md +5 -4
- data/docs/reference/generators/taxonomies.md +1 -1
- data/docs/reference/icons.md +5 -3
- data/docs/reference/index.md +10 -7
- data/docs/reference/models/current.md +5 -3
- data/docs/reference/models/page-version.md +1 -1
- data/docs/reference/models/user.md +7 -8
- data/docs/reference/uploaders.md +25 -0
- data/docs/reference/validators.md +1 -1
- data/docs/security.md +30 -9
- data/docs/what-is-trek.md +4 -4
- data/lib/generators/trek/USAGE +1 -1
- data/lib/generators/trek/audit_log_generator.rb +62 -0
- data/lib/generators/trek/helpers.rb +17 -0
- data/lib/generators/trek/install/admin/routes_generator.rb +2 -1
- data/lib/generators/trek/install/admin/security_check_generator.rb +36 -0
- data/lib/generators/trek/install/admin/users_generator.rb +6 -1
- data/lib/generators/trek/install/audit_log_generator.rb +9 -45
- data/lib/generators/trek/install/ci_generator.rb +19 -0
- data/lib/generators/trek/install/good_job_generator.rb +161 -0
- data/lib/generators/trek/install/model_specs_generator.rb +3 -3
- data/lib/generators/trek/install/postcss_generator.rb +1 -2
- data/lib/generators/trek/install/ruby_generator.rb +1 -1
- data/lib/generators/trek/install/scalingo_generator.rb +7 -45
- data/lib/generators/trek/install/translations_generator.rb +1 -2
- data/lib/generators/trek/install_generator.rb +18 -2
- data/lib/generators/trek/public_accounts_generator.rb +294 -0
- data/lib/generators/trek/scaffold_generator.rb +22 -21
- data/lib/generators/trek/scalingo_generator.rb +67 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +10 -1
- data/lib/generators/trek/templates/AGENTS.md +2 -2
- data/lib/generators/trek/templates/Makefile +1 -0
- data/lib/generators/trek/templates/config/i18n-tasks.yml.erb +0 -8
- data/lib/generators/trek/templates/controllers/admin/password_renewals_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/security_checks_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +1 -1
- data/lib/generators/trek/templates/controllers/admin/users_controller.rb +0 -8
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +13 -4
- data/lib/generators/trek/templates/initializers/content_security_policy.rb +3 -2
- data/lib/generators/trek/templates/initializers/good_job.rb.tt +40 -0
- data/lib/generators/trek/templates/jobs/mail_delivery_job.rb +6 -0
- data/lib/generators/trek/templates/layouts/admin.html.slim +10 -0
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +4 -2
- data/lib/generators/trek/templates/package.json.tt +1 -1
- data/lib/generators/trek/templates/policies/security_check.rb +4 -0
- data/lib/generators/trek/templates/public_accounts/api/authentication.rb.tt +76 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/accounts_controller.rb.tt +22 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/active_sessions_controller.rb.tt +21 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/base_controller.rb.tt +71 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_changes_controller.rb.tt +55 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/password_resets_controller.rb.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/passwords_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/registrations_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sessions_controller.rb.tt +57 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +20 -0
- data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/mailers/account_mailer.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/migrations/create_accounts.rb.tt +46 -0
- data/lib/generators/trek/templates/public_accounts/models/account/session.rb.tt +47 -0
- data/lib/generators/trek/templates/public_accounts/models/account/sign_in_code.rb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/models/account.rb.tt +87 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/accounts_spec.rb.tt +90 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/sign_ins_spec.rb.tt +188 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +66 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +129 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/accounts_spec.rb.tt +126 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/authentication_spec.rb.tt +43 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/sign_ins_spec.rb.tt +237 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.html.slim.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.html.slim.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.html.slim.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/web/authentication.rb.tt +97 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/accounts_controller.rb.tt +33 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/active_sessions_controller.rb.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/base_controller.rb.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_changes_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/password_resets_controller.rb.tt +41 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/passwords_controller.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/registrations_controller.rb.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sessions_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +32 -0
- data/lib/generators/trek/templates/public_accounts/web/views/_flash.html.slim.tt +5 -0
- data/lib/generators/trek/templates/public_accounts/web/views/accounts/show.html.slim.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/edit.html.slim.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/edit.html.slim.tt +29 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/passwords/edit.html.slim.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +30 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +40 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sign_in_codes/new.html.slim.tt +17 -0
- data/lib/generators/trek/templates/spec/jobs/mail_delivery_job_spec.rb +11 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +10 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/good_job_spec.rb +34 -0
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +12 -1
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +16 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +2 -2
- data/lib/generators/trek/templates/spec/requests/admin/security_checks_spec.rb +24 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +33 -0
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +2 -2
- data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin/security_checks/show.html.slim +9 -0
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +6 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +4 -1
- data/lib/generators/trek/templates/views/admin/users/index.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +1 -1
- data/lib/tasks/trek/attachments.rake +12 -0
- data/lib/tasks/trek/security.rake +10 -0
- data/lib/trek/csp_reports.rb +22 -4
- data/lib/trek/disposable_email_domains.rb +9 -20
- data/lib/trek/engine.rb +5 -0
- data/lib/trek/json_compatibility.rb +20 -0
- data/lib/trek/security_check.rb +241 -0
- data/lib/trek/stored_image_metadata.rb +88 -0
- data/lib/trek/typography_formatter.rb +35 -4
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +2 -1
- data/package.json +16 -13
- data/postcss.config.js +0 -3
- data/trek.gemspec +6 -7
- data/vitest.config.mjs +24 -0
- data/yarn.lock +1667 -1010
- metadata +122 -33
data/docs/security.md
CHANGED
|
@@ -13,15 +13,15 @@ The controls of ISO/IEC 27001:2022's Annex A that an application takes part in:
|
|
|
13
13
|
| **5.15** Access control, **8.2** Privileged access rights, **8.3** Information access restriction | Roles (`admin`, `editor`…), only `admin` and `editor` can sign in to the admin, and policies authorize each record and attribute per role, only `admin` the audit log | [User › Roles](/reference/models/user#roles), [Policies](/reference/policies) |
|
|
14
14
|
| **5.17** Authentication information | The ANSSI's password recommendations for a privileged access: 12 characters or more, no common password, sequence, name or email; the last 5 passwords refused; optional expiry; an admin can ask everyone for a new password after a suspected compromise. Password reset links last 15 minutes, invitation links a week, and no column stores them | [Password policy](/reference/models/user#password-policy), [Previous passwords](/reference/models/user#previous-passwords) |
|
|
15
15
|
| **5.18** Access rights | Each user's last activity and previous sign-in. Planned: reviewing access, and deactivating dormant accounts | [User › Sign-ins](/reference/models/user#sign-ins) |
|
|
16
|
-
| **5.34** Privacy and protection of PII | The audit log records parameter names, not their values, and the docs set out the GDPR's conditions for keeping it. The breached password check, which would send part of a password's hash to an outside service, is off by default | [Audit log › Personal data](/reference/generators/audit-log#personal-data) |
|
|
16
|
+
| **5.34** Privacy and protection of PII | The audit log records parameter names, not their values, and the docs set out the GDPR's conditions for keeping it. The breached password check, which would send part of a password's hash to an outside service, is off by default. Uploaded images lose their metadata (GPS location, camera serial number). The personal data Trek's generators create is listed, with how long it's kept and what deletes it | [Personal data](/personal-data), [Audit log › Personal data](/reference/generators/audit-log#personal-data) |
|
|
17
17
|
| **8.5** Secure authentication | Passkeys, which can't be phished and count as two factors; failed sign-ins throttled per IP address and per account, with an email to the account's user; sign-in and password reset that don't reveal whether an account exists; sessions ending after 48 hours idle and 30 days in all, listed to their user, who can end them; an email on a sign-in from a new browser. Planned: TOTP codes, and requiring a second factor | [User](/reference/models/user#sign-in-and-password-resets) |
|
|
18
|
-
| **8.8** Management of technical vulnerabilities | Generated apps' CI runs Brakeman and bundler-audit, and can make a Software Bill of Materials (SBOM) of their gems and npm packages; Trek's own CI too, and Renovate keeps its dependencies up to date. Planned: a vulnerability disclosure policy | [Installer](/reference/generators/install), [Software Bill of Materials](/reference/generators/install#software-bill-of-materials) |
|
|
19
|
-
| **8.9** Configuration management | The installer gives every app the same configuration, security headers included: a Content Security Policy, report-only at first, and a `Permissions-Policy` turning off the browser features the app doesn't use | [Installer](/reference/generators/install), [Security headers](/reference/generators/security-headers) |
|
|
18
|
+
| **8.8** Management of technical vulnerabilities | Generated apps' CI runs Brakeman and checks their gems (bundler-audit) and the npm packages they bundle (`yarn npm audit`) for known vulnerabilities, and can make a Software Bill of Materials (SBOM) of their gems and npm packages; Trek's own CI too, and Renovate keeps its dependencies up to date. Planned: a vulnerability disclosure policy | [Installer](/reference/generators/install), [Vulnerable dependencies](/reference/generators/install#vulnerable-dependencies), [Software Bill of Materials](/reference/generators/install#software-bill-of-materials) |
|
|
19
|
+
| **8.9** Configuration management | The installer gives every app the same configuration, security headers included: a Content Security Policy, report-only at first, and a `Permissions-Policy` turning off the browser features the app doesn't use. `bin/rails trek:security:check` checks a deployed app still follows the recommended settings | [Installer](/reference/generators/install), [Security headers](/reference/generators/security-headers), [Self-check](#self-check) |
|
|
20
20
|
| **8.15** Logging | An audit log of every change in the admin and every sign-in: author, request, record, status, IP address. Rows can't be changed through the app, and are deleted after 6 months, as the CNIL recommends. Planned: sending them to a store outside the app | [Audit log](/reference/generators/audit-log) |
|
|
21
21
|
| **8.16** Monitoring activities | Errors and performance reported to AppSignal, and the Content Security Policy's violations; users emailed on a sign-in from a new browser and when failed sign-ins lock their account | [Installer](/reference/generators/install) |
|
|
22
22
|
| **8.20** Networks security | The visitor's real IP address behind proxies and CDNs, which the limits and logs rely on; the admin can be restricted to IP addresses and ranges (`ADMIN_ALLOWED_IPS`) | [Proxies](/proxies), [Restricting the admin to IP addresses](/proxies#restricting-the-admin-to-ip-addresses) |
|
|
23
23
|
| **8.24** Use of cryptography | HTTPS only (`force_ssl`, with HSTS and secure cookies), bcrypt password hashes, signed session cookies, signed tokens in emailed links. Planned: encrypting sensitive columns | [Cryptography](#cryptography) |
|
|
24
|
-
| **8.25** to **8.29** Secure development | Trek's changes go through merge requests, with specs, RuboCop, Brakeman
|
|
24
|
+
| **8.25** to **8.29** Secure development | Trek's changes go through merge requests, with specs, RuboCop, Brakeman, bundler-audit and `yarn npm audit` in CI. Generated apps get the same CI, and specs checking Trek's behaviour in them | [Installer](/reference/generators/install) |
|
|
25
25
|
| **8.33** Test information | Planned: anonymized production dumps for development | |
|
|
26
26
|
|
|
27
27
|
## NIS2 measures
|
|
@@ -33,9 +33,9 @@ The measures of the directive's Article 21(2), and what Trek provides for each:
|
|
|
33
33
|
| (a) Risk analysis and security policies | — |
|
|
34
34
|
| (b) Incident handling | Evidence: the audit log, AppSignal's errors, the sign-in emails |
|
|
35
35
|
| (c) Business continuity, backups, disaster recovery | — |
|
|
36
|
-
| (d) Supply chain security | Dependencies checked for known vulnerabilities in CI (bundler-audit)
|
|
37
|
-
| (e) Secure development and maintenance, vulnerability handling and disclosure | Changes through merge requests, with specs, RuboCop, Brakeman
|
|
38
|
-
| (f) Assessing the measures' effectiveness |
|
|
36
|
+
| (d) Supply chain security | Dependencies checked for known vulnerabilities in CI: gems (bundler-audit) and the npm packages an app bundles (`yarn npm audit`, which also fails on deprecated packages), with [how to resolve one](/reference/generators/install#vulnerable-dependencies); kept up to date by Renovate. A CycloneDX [SBOM](/reference/generators/install#software-bill-of-materials) of an app, made in its CI, to hand to a client who asks. The [third parties](/personal-data#third-parties) a default app sends personal data to, and what |
|
|
37
|
+
| (e) Secure development and maintenance, vulnerability handling and disclosure | Changes through merge requests, with specs, RuboCop, Brakeman, bundler-audit and `yarn npm audit` in CI; generated apps get the same CI. Planned: a vulnerability disclosure policy |
|
|
38
|
+
| (f) Assessing the measures' effectiveness | `bin/rails trek:security:check` checks a deployed app's configuration against the recommended settings, and prints a dated report to keep as evidence (see [Self-check](#self-check)) |
|
|
39
39
|
| (g) Cyber hygiene and training | — |
|
|
40
40
|
| (h) Cryptography and encryption | HTTPS only (`force_ssl`, with HSTS and secure cookies), bcrypt password hashes, signed session cookies, signed tokens in emailed links (see [Cryptography](#cryptography)). Planned: encrypting sensitive columns |
|
|
41
41
|
| (i) Human resources security, access control, asset management | Roles, and policies authorizing each record and attribute per role; sessions that expire and that their user can end. Planned: reviewing access, and deactivating dormant accounts |
|
|
@@ -52,8 +52,8 @@ The cryptography a generated app uses, with Rails 8.1's defaults: an inventory f
|
|
|
52
52
|
| Use | Algorithm | Against a quantum computer |
|
|
53
53
|
| --- | --- | --- |
|
|
54
54
|
| Passwords | bcrypt, cost 12 | Resists |
|
|
55
|
-
| Rails' session cookie (flash messages, CSRF token) | AES-256-GCM | Resists |
|
|
56
|
-
| Signed cookies: the session id
|
|
55
|
+
| Rails' session cookie (flash messages, CSRF token), the browsers a user signed in from | AES-256-GCM | Resists |
|
|
56
|
+
| Signed cookies: the session id | HMAC-SHA1 | Resists |
|
|
57
57
|
| Password reset and invitation links (`generates_token_for`) | HMAC-SHA1 | Resists |
|
|
58
58
|
| Keys of the above, derived from `secret_key_base` | PBKDF2-HMAC-SHA256, 1,000 iterations | Resists |
|
|
59
59
|
| Passkeys (the [webauthn](https://github.com/cedarcode/webauthn-ruby) gem's defaults) | ECDSA P-256 (ES256), RSA (PS256, RS256) | Vulnerable, like all of today's public-key signatures; the move depends on browsers and authenticators |
|
|
@@ -88,3 +88,24 @@ For an app whose client is subject to ISO 27001 or NIS2:
|
|
|
88
88
|
- enforce the Content Security Policy once its reports show no violation left but noise ([Report first, then enforce](/reference/generators/security-headers#report-first-then-enforce));
|
|
89
89
|
- list the CDN's ranges in `trusted_proxies` when there is one ([Proxies](/proxies));
|
|
90
90
|
- when the admins work from known networks (an office, a VPN), restrict the admin to them with `ADMIN_ALLOWED_IPS`.
|
|
91
|
+
|
|
92
|
+
## Self-check
|
|
93
|
+
|
|
94
|
+
`bin/rails trek:security:check` checks a deployed app against the settings above, and what Trek expects from the hosting. Run it where the app runs in production, so it reads that configuration and database, e.g. from a shell on the server or through the hosting platform's command runner. It prints each check with a link to the page explaining it:
|
|
95
|
+
|
|
96
|
+
- **✓** the setting follows the recommendation;
|
|
97
|
+
- **•** a fact, for information: the number of admin users, whether `trusted_proxies` is set, `ADMIN_ALLOWED_IPS` left unset;
|
|
98
|
+
- **⚠** a recommendation not followed, e.g. admins signing in with a password only, a Content Security Policy that only reports, or the purge of expired sessions not scheduled;
|
|
99
|
+
- **✗** a setting Trek relies on: HTTPS, a Content Security Policy, a cache store shared by the app's processes, GoodJob's cron, the audit log's purge.
|
|
100
|
+
|
|
101
|
+
It checks HTTPS and HSTS, the Content Security Policy, the cache store, the proxies and `ADMIN_ALLOWED_IPS`, the audit log and the scheduled purges, the admin users (those signing in with a password only, those who haven't signed in for 6 months, password expiry), and Active Record Encryption's keys. The report starts with the date, the app, and Trek's, Rails' and Ruby's versions: keep it as evidence that the measures are in place.
|
|
102
|
+
|
|
103
|
+
The task exits with status 1 when a check fails, so a scheduled job or a deploy step can stop on it. Run it before going live, after changing the hosting or the app's configuration, and at least once a year.
|
|
104
|
+
|
|
105
|
+
### In the admin
|
|
106
|
+
|
|
107
|
+
The admin's **Settings › Security** page shows the same checks to admins (editors are turned away), dated, to print or save as evidence without access to a production shell. It also checks the request that opened it, which the task can't: that it reached the app over HTTPS, and the IP address Rails sees. A CDN that forwards another address in its own header (`CF-Connecting-IP`, `True-Client-IP`, `Fastly-Client-IP`) than the one Rails sees fails the check, as its ranges are missing from `trusted_proxies`. The page comes from `bin/rails g trek:install:admin:security_check`, which `trek:install` runs.
|
|
108
|
+
|
|
109
|
+
### Outside the app
|
|
110
|
+
|
|
111
|
+
The task reads the configuration only. Check what reaches the browser with external tools too: [Mozilla Observatory](https://developer.mozilla.org/en-US/observatory) for the security headers, [SSL Labs](https://www.ssllabs.com/ssltest/) for HTTPS, and the IP address Rails sees, as [Proxies](/proxies#checking) explains.
|
data/docs/what-is-trek.md
CHANGED
|
@@ -9,9 +9,9 @@ Trek ships as a Rails engine (a gem plus an NPM package) that integrates into yo
|
|
|
9
9
|
- **A complete admin panel** — layout, navigation, search, pagination, light & dark themes, all built with [ViewComponent](https://viewcomponent.org), [Stimulus](https://stimulus.hotwired.dev) and [Turbo](https://turbo.hotwired.dev).
|
|
10
10
|
- **Pages** — hierarchical, translatable pages with version history, SEO metadata and stable, redirect-aware URL paths.
|
|
11
11
|
- **Fragments** — reusable chunks of content (a footer text, a hero tagline…) editable from the admin and usable anywhere in your views.
|
|
12
|
-
- **A
|
|
12
|
+
- **A content editor** — based on [Tiptap](https://tiptap.dev), with image uploads (Uppy), link insertion and content stored as structured ProseMirror JSON and rendered safely to HTML (see [Content editor](/content-editor)).
|
|
13
13
|
- **Authentication & authorization** — sign in built on Rails' [`has_secure_password`](https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html) with database-backed sessions, password resets, invitations, and [ActionPolicy](https://actionpolicy.evilmartians.io) policies with `admin`, `editor`, `user`, `reader` and `guest` roles.
|
|
14
|
-
- **Internationalization** — content translations with [Mobility](https://github.com/shioyama/mobility)
|
|
14
|
+
- **Internationalization** — content translations with [Mobility](https://github.com/shioyama/mobility) and locale management with [i18n-tasks](https://github.com/glebm/i18n-tasks).
|
|
15
15
|
- **File uploads** — [Shrine](https://shrinerb.com)-backed attachments with S3 or local storage, image processing via libvips, and blurhash placeholders.
|
|
16
16
|
- **Generators** — an installer that sets up everything above, and a scaffold generator that creates a full admin panel for any model in one command.
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ Trek ships as a Rails engine (a gem plus an NPM package) that integrates into yo
|
|
|
19
19
|
|
|
20
20
|
Trek follows the Rails way:
|
|
21
21
|
|
|
22
|
-
- **Convention over configuration.** The installer makes opinionated choices (PostgreSQL, Slim, esbuild, PostCSS, RSpec,
|
|
22
|
+
- **Convention over configuration.** The installer makes opinionated choices (PostgreSQL, Slim, esbuild, PostCSS, RSpec, RuboCop with the Rails omakase rules…) so you don't have to. Every choice can be revisited afterwards — the generated code lives in your application.
|
|
23
23
|
- **Code generation over runtime magic.** Models like `User`, `Page` or `Fragment` are generated into your app with their concerns included, rather than hidden inside the engine. You can read them, edit them, and remove what you don't need.
|
|
24
24
|
- **Progressive customization.** Start with the defaults, then override views, components, policies or styles as your project grows.
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ Trek follows the Rails way:
|
|
|
28
28
|
| Dependency | Version |
|
|
29
29
|
| --- | --- |
|
|
30
30
|
| Ruby | 3.3+ |
|
|
31
|
-
| Rails | 8.0
|
|
31
|
+
| Rails | 8.0 or 8.1 (before 8.1.4, with `gem "json", "< 3"`) |
|
|
32
32
|
| PostgreSQL | 12+ |
|
|
33
33
|
| Node | 22+ |
|
|
34
34
|
| Yarn | 4.x |
|
data/lib/generators/trek/USAGE
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "rails/generators/actions"
|
|
2
|
+
require "rails/generators/migration"
|
|
3
|
+
require "generators/trek/helpers"
|
|
4
|
+
|
|
5
|
+
module Trek
|
|
6
|
+
module Generators
|
|
7
|
+
class AuditLogGenerator < Rails::Generators::Base
|
|
8
|
+
include Rails::Generators::Migration
|
|
9
|
+
include Trek::Generators::Helpers
|
|
10
|
+
|
|
11
|
+
desc "Create the AuditLog model, record the admin's requests, and list them in the admin."
|
|
12
|
+
|
|
13
|
+
source_root File.expand_path("templates", __dir__)
|
|
14
|
+
|
|
15
|
+
def copy_model
|
|
16
|
+
template "models/audit_log.rb", "app/models/audit_log.rb"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def copy_migration_file
|
|
20
|
+
return unless defined?(ActiveRecord)
|
|
21
|
+
|
|
22
|
+
migration_template("migrations/audit_logs.rb.erb",
|
|
23
|
+
"db/migrate/trek_audit_logs.rb",
|
|
24
|
+
migration_class_name:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def copy_initializer
|
|
28
|
+
template "initializers/audit_log.rb", "config/initializers/audit_log.rb"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def copy_controller
|
|
32
|
+
template "controllers/admin/audit_logs_controller.rb",
|
|
33
|
+
"app/controllers/admin/audit_logs_controller.rb"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def copy_views
|
|
37
|
+
directory "views/admin/audit_logs", "app/views/admin/audit_logs"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def copy_policy
|
|
41
|
+
template "policies/audit_log.rb", "app/policies/admin/audit_log_policy.rb"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def add_routes
|
|
45
|
+
route "resources :audit_logs, only: %i[index show]", namespace: :admin
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Rows past the retention window are deleted every night, after the sessions' purge
|
|
49
|
+
def schedule_purge
|
|
50
|
+
schedule_in_good_job_cron :purge_audit_logs,
|
|
51
|
+
job_class: "Trek::AuditLog::PurgeJob",
|
|
52
|
+
cron: "0 4 * * *",
|
|
53
|
+
description: "Delete the audit log rows past the retention window"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def copy_specs
|
|
57
|
+
template "spec/models/audit_log_spec.rb", "spec/models/audit_log_spec.rb"
|
|
58
|
+
template "spec/requests/admin/audit_logs_spec.rb", "spec/requests/admin/audit_logs_spec.rb"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -68,6 +68,23 @@ module Trek
|
|
|
68
68
|
run "#{command} #{paths}", abort_on_failure: true, verbose: false
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
GOOD_JOB_INITIALIZER = "config/initializers/good_job.rb"
|
|
72
|
+
GOOD_JOB_CRON = /^ *config\.good_job\.cron = \{\n/
|
|
73
|
+
|
|
74
|
+
# Adds a job to the cron of the initializer trek:install:good_job writes, at the top: the hash's
|
|
75
|
+
# last entry keeps its lack of trailing comma. Once: re-running a generator leaves it. Without
|
|
76
|
+
# that initializer, the app runs another backend, and is told what to schedule.
|
|
77
|
+
def schedule_in_good_job_cron(name, job_class:, cron:, description:, args: nil)
|
|
78
|
+
path = File.join(destination_root, GOOD_JOB_INITIALIZER)
|
|
79
|
+
content = File.exist?(path) ? File.read(path) : ""
|
|
80
|
+
return say_status(:schedule, "#{job_class} daily", :yellow) unless content.match?(GOOD_JOB_CRON)
|
|
81
|
+
return if behavior == :invoke && content.match?(/^ *#{name}: \{$/)
|
|
82
|
+
|
|
83
|
+
entry = { cron:, class: job_class, args:, description: }.compact
|
|
84
|
+
lines = entry.map { |key, value| " #{key}: #{value.inspect}" }
|
|
85
|
+
inject_into_file GOOD_JOB_INITIALIZER, " #{name}: {\n#{lines.join(",\n")}\n },\n", after: GOOD_JOB_CRON
|
|
86
|
+
end
|
|
87
|
+
|
|
71
88
|
def install_npm_dependencies(dependencies, dev: false)
|
|
72
89
|
run "yarn add #{dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")} #{dev ? "--dev" : ""}", abort_on_failure: true
|
|
73
90
|
end
|
|
@@ -27,8 +27,9 @@ module Trek
|
|
|
27
27
|
route 'mount Lookbook::Engine, at: "/lookbook" if Rails.env.development?'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# The thumbnails and other sizes (ImageUploader's derivations)
|
|
30
31
|
def derivation_endpoint
|
|
31
|
-
route '
|
|
32
|
+
route 'mount ImageUploader.derivation_endpoint => "derivations/image"'
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def add_panels_routes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "rails/generators/actions"
|
|
2
|
+
require "generators/trek/helpers"
|
|
3
|
+
|
|
4
|
+
module Trek
|
|
5
|
+
module Generators
|
|
6
|
+
module Install
|
|
7
|
+
module Admin
|
|
8
|
+
class SecurityCheckGenerator < Rails::Generators::Base
|
|
9
|
+
include Trek::Generators::Helpers
|
|
10
|
+
|
|
11
|
+
desc "Create the admin's Security page, for admins: Trek::SecurityCheck, on the request too."
|
|
12
|
+
|
|
13
|
+
source_root File.expand_path("../../templates", __dir__)
|
|
14
|
+
|
|
15
|
+
def add_route
|
|
16
|
+
route "resource :security_check, only: :show", namespace: :admin
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def copy_controller
|
|
20
|
+
template "controllers/admin/security_checks_controller.rb",
|
|
21
|
+
"app/controllers/admin/security_checks_controller.rb"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def copy_view
|
|
25
|
+
template "views/admin/security_checks/show.html.slim",
|
|
26
|
+
"app/views/admin/security_checks/show.html.slim"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def copy_policy
|
|
30
|
+
template "policies/security_check.rb", "app/policies/admin/security_check_policy.rb"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -25,10 +25,10 @@ module Trek
|
|
|
25
25
|
get :options, on: :collection
|
|
26
26
|
end
|
|
27
27
|
RUBY
|
|
28
|
+
route "resource :password_renewal, only: :create", namespace: :admin
|
|
28
29
|
route <<~RUBY, namespace: :admin
|
|
29
30
|
resources :users do
|
|
30
31
|
patch :theme, on: :collection
|
|
31
|
-
post :require_password_renewal, on: :collection
|
|
32
32
|
end
|
|
33
33
|
RUBY
|
|
34
34
|
end
|
|
@@ -52,6 +52,11 @@ module Trek
|
|
|
52
52
|
template "controllers/admin/passkeys_controller.rb",
|
|
53
53
|
"app/controllers/admin/passkeys_controller.rb"
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
def copy_password_renewals
|
|
57
|
+
template "controllers/admin/password_renewals_controller.rb",
|
|
58
|
+
"app/controllers/admin/password_renewals_controller.rb"
|
|
59
|
+
end
|
|
55
60
|
end
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -1,54 +1,18 @@
|
|
|
1
|
-
require "
|
|
2
|
-
require "rails/generators/migration"
|
|
3
|
-
require "generators/trek/helpers"
|
|
1
|
+
require "generators/trek/audit_log_generator"
|
|
4
2
|
|
|
5
3
|
module Trek
|
|
6
4
|
module Generators
|
|
7
5
|
module Install
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
# The audit log's generator under its former name: `trek:install` doesn't run it, so it's `trek:audit_log` now.
|
|
7
|
+
# Removed in Trek 3.
|
|
8
|
+
class AuditLogGenerator < Trek::Generators::AuditLogGenerator
|
|
9
|
+
hide!
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
# Not inherited: Rails derives it from the generator's own path.
|
|
12
|
+
source_root Trek::Generators::AuditLogGenerator.source_root
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def copy_model
|
|
17
|
-
template "models/audit_log.rb", "app/models/audit_log.rb"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def copy_migration_file
|
|
21
|
-
return unless defined?(ActiveRecord)
|
|
22
|
-
|
|
23
|
-
migration_template("migrations/audit_logs.rb.erb",
|
|
24
|
-
"db/migrate/trek_audit_logs.rb",
|
|
25
|
-
migration_class_name:)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def copy_initializer
|
|
29
|
-
template "initializers/audit_log.rb", "config/initializers/audit_log.rb"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def copy_controller
|
|
33
|
-
template "controllers/admin/audit_logs_controller.rb",
|
|
34
|
-
"app/controllers/admin/audit_logs_controller.rb"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def copy_views
|
|
38
|
-
directory "views/admin/audit_logs", "app/views/admin/audit_logs"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def copy_policy
|
|
42
|
-
template "policies/audit_log.rb", "app/policies/admin/audit_log_policy.rb"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def add_routes
|
|
46
|
-
route "resources :audit_logs, only: %i[index show]", namespace: :admin
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def copy_specs
|
|
50
|
-
template "spec/models/audit_log_spec.rb", "spec/models/audit_log_spec.rb"
|
|
51
|
-
template "spec/requests/admin/audit_logs_spec.rb", "spec/requests/admin/audit_logs_spec.rb"
|
|
14
|
+
def deprecation_warning
|
|
15
|
+
say "`trek:install:audit_log` is deprecated and will be removed in Trek 3: run `trek:audit_log`.", :yellow
|
|
52
16
|
end
|
|
53
17
|
end
|
|
54
18
|
end
|
|
@@ -5,6 +5,10 @@ module Trek
|
|
|
5
5
|
module Generators
|
|
6
6
|
module Install
|
|
7
7
|
class CiGenerator < Rails::Generators::Base
|
|
8
|
+
# The Node majors devops/ci-ruby publishes images for, and the one CI falls back to
|
|
9
|
+
NODE_MAJORS = %w[20 22 24 26].freeze
|
|
10
|
+
DEFAULT_NODE_MAJOR = "24".freeze
|
|
11
|
+
|
|
8
12
|
include Trek::Generators::Helpers
|
|
9
13
|
|
|
10
14
|
desc "Create the Gitlab CI configuration."
|
|
@@ -15,6 +19,21 @@ module Trek
|
|
|
15
19
|
template ".gitlab-ci.yml",
|
|
16
20
|
".gitlab-ci.yml"
|
|
17
21
|
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# CI builds and tests on the Node the app deploys with: the trek-buildpack reads it from the
|
|
26
|
+
# .node-version `rails new` writes.
|
|
27
|
+
def node_major
|
|
28
|
+
path = File.join(destination_root, ".node-version")
|
|
29
|
+
major = File.read(path)[/\d+/] if File.exist?(path)
|
|
30
|
+
return DEFAULT_NODE_MAJOR if major.nil?
|
|
31
|
+
return major if NODE_MAJORS.include?(major)
|
|
32
|
+
|
|
33
|
+
say_status :warning, "no ci-ruby image for Node #{major} (.node-version): CI runs on Node " \
|
|
34
|
+
"#{DEFAULT_NODE_MAJOR}", :yellow
|
|
35
|
+
DEFAULT_NODE_MAJOR
|
|
36
|
+
end
|
|
18
37
|
end
|
|
19
38
|
end
|
|
20
39
|
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
require "rails/generators/actions"
|
|
2
|
+
require "generators/trek/helpers"
|
|
3
|
+
|
|
4
|
+
module Trek
|
|
5
|
+
module Generators
|
|
6
|
+
module Install
|
|
7
|
+
# Replaces the Solid Queue backend `rails new` sets up with GoodJob: one PostgreSQL
|
|
8
|
+
# database instead of two, jobs running inside Puma, and a dashboard in the admin.
|
|
9
|
+
class GoodJobGenerator < Rails::Generators::Base
|
|
10
|
+
GOOD_JOB_VERSION = "~> 4.13".freeze
|
|
11
|
+
GEM_COMMENT = "Active Job backend on PostgreSQL, with a dashboard [https://github.com/bensheldon/good_job]".freeze
|
|
12
|
+
|
|
13
|
+
# The line `rails new` writes to size the connection pool: `max_connections` since
|
|
14
|
+
# Rails 8.1, `pool` before it. Whichever it is, it keeps its name.
|
|
15
|
+
POOL_LINE = /^(\s*)(max_connections|pool): <%= ENV\.fetch\("RAILS_MAX_THREADS"\)[^\n]*%>\n/
|
|
16
|
+
|
|
17
|
+
include Trek::Generators::Helpers
|
|
18
|
+
|
|
19
|
+
desc "Install GoodJob as the Active Job backend."
|
|
20
|
+
|
|
21
|
+
source_root File.expand_path("../templates", __dir__)
|
|
22
|
+
|
|
23
|
+
def swap_gems
|
|
24
|
+
return if in_gemfile?("good_job")
|
|
25
|
+
|
|
26
|
+
# Solid Queue wants a second database, which a Trek app does not provision (Solid
|
|
27
|
+
# Cache stays: its table lives in the primary database). GoodJob takes over its line,
|
|
28
|
+
# under the Active Job adapter comment it belongs to.
|
|
29
|
+
if in_gemfile?("solid_queue")
|
|
30
|
+
gsub_file "Gemfile", /^gem "solid_queue".*\n/,
|
|
31
|
+
%(# #{GEM_COMMENT}\ngem "good_job", "#{GOOD_JOB_VERSION}"\n)
|
|
32
|
+
else
|
|
33
|
+
gem "good_job", GOOD_JOB_VERSION, comment: GEM_COMMENT
|
|
34
|
+
end
|
|
35
|
+
bundle_install
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def remove_solid_queue_files
|
|
39
|
+
%w[config/queue.yml config/recurring.yml db/queue_schema.rb bin/jobs].each do |file|
|
|
40
|
+
remove_file file
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def remove_solid_queue_from_puma
|
|
45
|
+
gsub_file "config/puma.rb",
|
|
46
|
+
/^(?:#[^\n]*Solid Queue[^\n]*\n)?plugin :solid_queue if ENV\["SOLID_QUEUE_IN_PUMA"\]\n\n?/,
|
|
47
|
+
""
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def remove_queue_database
|
|
51
|
+
gsub_file "config/database.yml", /^ queue:\n(?: [^\n]*\n)+/, ""
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# GoodJob runs in the web container's process, so its threads need connections of their
|
|
55
|
+
# own — the pool `rails new` sizes for the web threads alone would starve them.
|
|
56
|
+
def size_connection_pool
|
|
57
|
+
gsub_file "config/database.yml", POOL_LINE, <<~'YAML'
|
|
58
|
+
\1# Web threads and job threads each check out their own connections, plus one for
|
|
59
|
+
\1# GoodJob's LISTEN/NOTIFY listener. GOOD_JOB_MAX_THREADS falls back to
|
|
60
|
+
\1# RAILS_MAX_THREADS inside GoodJob, so both shares match unless it is set.
|
|
61
|
+
\1\2: <%= web = ENV.fetch("RAILS_MAX_THREADS", 5).to_i; 1 + web + ENV.fetch("GOOD_JOB_MAX_THREADS", web).to_i %>
|
|
62
|
+
YAML
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Kamal's file is not what a Trek app deploys with, but leaving Solid Queue's variables
|
|
66
|
+
# in it would describe a backend the app no longer runs.
|
|
67
|
+
def clean_kamal_deploy_file
|
|
68
|
+
return unless File.exist?("config/deploy.yml")
|
|
69
|
+
|
|
70
|
+
gsub_file "config/deploy.yml",
|
|
71
|
+
/^(?:[ \t]*#[^\n]*\n)*([ \t]*)SOLID_QUEUE_IN_PUMA: true\n/,
|
|
72
|
+
<<~'YAML'
|
|
73
|
+
\1# Jobs run inside Puma (config.good_job.execution_mode = :async), so there is no
|
|
74
|
+
\1# separate job process to start. GOOD_JOB_MAX_THREADS sizes its thread pool.
|
|
75
|
+
\1# GOOD_JOB_MAX_THREADS: 5
|
|
76
|
+
YAML
|
|
77
|
+
gsub_file "config/deploy.yml",
|
|
78
|
+
/^[ \t]*# Set number of processes dedicated to Solid Queue[^\n]*\n[ \t]*# JOB_CONCURRENCY:[^\n]*\n\n?/,
|
|
79
|
+
""
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def configure_adapter
|
|
83
|
+
return if File.read("config/application.rb").include?("queue_adapter = :good_job")
|
|
84
|
+
|
|
85
|
+
inject_into_file "config/application.rb", adapter_configuration,
|
|
86
|
+
after: /^\s*config\.load_defaults [^\n]*\n/
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Active Job's test helper only swaps in its test adapter for a job class with no adapter
|
|
90
|
+
# configured, and config/application.rb now sets GoodJob: give the specs the test adapter
|
|
91
|
+
# back, for have_enqueued_job and the like.
|
|
92
|
+
def configure_test_adapter
|
|
93
|
+
return unless File.exist?("config/environments/test.rb")
|
|
94
|
+
return if File.read("config/environments/test.rb").include?("queue_adapter = :test")
|
|
95
|
+
|
|
96
|
+
inject_into_file "config/environments/test.rb", <<-RUBY, after: /^Rails\.application\.configure do\n/
|
|
97
|
+
# Jobs go to Active Job's test adapter, not GoodJob (config/application.rb), so specs can check
|
|
98
|
+
# what was enqueued.
|
|
99
|
+
config.active_job.queue_adapter = :test
|
|
100
|
+
|
|
101
|
+
RUBY
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def configure_production
|
|
105
|
+
gsub_file "config/environments/production.rb", /^\s*config\.solid_queue\.connects_to[^\n]*\n/, ""
|
|
106
|
+
gsub_file "config/environments/production.rb",
|
|
107
|
+
/^(\s*)(?:# )?config\.active_job\.queue_adapter\s*=[^\n]*\n/,
|
|
108
|
+
<<~'RUBY'
|
|
109
|
+
\1# Jobs run in the web container's own threads: no worker process to pay for, and a
|
|
110
|
+
\1# deploy that drains them (shutdown_timeout) rather than dropping them.
|
|
111
|
+
\1config.good_job.execution_mode = :async
|
|
112
|
+
\1config.good_job.shutdown_timeout = 25
|
|
113
|
+
RUBY
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def create_initializer
|
|
117
|
+
template "initializers/good_job.rb.tt", "config/initializers/good_job.rb"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def create_mail_delivery_job
|
|
121
|
+
copy_file "jobs/mail_delivery_job.rb", "app/jobs/mail_delivery_job.rb"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def mount_dashboard
|
|
125
|
+
route 'mount GoodJob::Engine => "good_job"', namespace: :admin
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def create_migration
|
|
129
|
+
generate "good_job:install"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def create_specs
|
|
133
|
+
return unless File.directory?("spec")
|
|
134
|
+
|
|
135
|
+
copy_file "spec/requests/admin/good_job_spec.rb", "spec/requests/admin/good_job_spec.rb"
|
|
136
|
+
copy_file "spec/jobs/mail_delivery_job_spec.rb", "spec/jobs/mail_delivery_job_spec.rb"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
# The model of a signed-in browser, which the dashboard's guard looks the session cookie up
|
|
142
|
+
# in: User::Session, or UserSession in an app generated before Trek nested it.
|
|
143
|
+
def session_model
|
|
144
|
+
File.exist?("app/models/user_session.rb") ? "UserSession" : "User::Session"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def adapter_configuration
|
|
148
|
+
<<-RUBY
|
|
149
|
+
|
|
150
|
+
# Use GoodJob as the Active Job backend (see config/initializers/good_job.rb).
|
|
151
|
+
config.active_job.queue_adapter = :good_job
|
|
152
|
+
|
|
153
|
+
# Every `deliver_later` email goes through MailDeliveryJob, which retries a failed
|
|
154
|
+
# delivery — GoodJob discards a failed job (see app/jobs/mail_delivery_job.rb).
|
|
155
|
+
config.action_mailer.delivery_job = "MailDeliveryJob"
|
|
156
|
+
RUBY
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -51,11 +51,11 @@ module Trek
|
|
|
51
51
|
directory "db/seeds", "db/seeds"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
# The audit log's specs come with it, from `trek:
|
|
55
|
-
# `trek:taxonomies`.
|
|
54
|
+
# The audit log's specs come with it, from `trek:audit_log`, the GoodJob dashboard's from
|
|
55
|
+
# `trek:install:good_job`, and the tags' (model and policies) from `trek:taxonomies`.
|
|
56
56
|
def copy_specs
|
|
57
57
|
directory "spec/models", "spec/models", exclude_pattern: /audit_log|tag_spec/
|
|
58
|
-
directory "spec/requests", "spec/requests", exclude_pattern: /audit_log/
|
|
58
|
+
directory "spec/requests", "spec/requests", exclude_pattern: /audit_log|good_job_spec/
|
|
59
59
|
directory "spec/mailers", "spec/mailers"
|
|
60
60
|
directory "spec/fixtures", "spec/fixtures"
|
|
61
61
|
directory "spec/policies", "spec/policies", exclude_pattern: /tag(_category)?_policy_spec/
|
|
@@ -9,7 +9,6 @@ module Trek
|
|
|
9
9
|
postcss: "^8.4.18",
|
|
10
10
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
11
11
|
"postcss-import": "^15.0.0",
|
|
12
|
-
"postcss-inline-svg": "^5.0.0",
|
|
13
12
|
"postcss-modules": "^5.0.0",
|
|
14
13
|
"postcss-preset-env": "^7.8.2"
|
|
15
14
|
}
|
|
@@ -21,7 +20,7 @@ module Trek
|
|
|
21
20
|
source_root File.expand_path("../../../../", __dir__)
|
|
22
21
|
|
|
23
22
|
def install_dependencies
|
|
24
|
-
install_npm_dependencies(NPM_DEPENDENCIES)
|
|
23
|
+
install_npm_dependencies(NPM_DEPENDENCIES, dev: true)
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
def copy_postcss_config
|
|
@@ -1,53 +1,15 @@
|
|
|
1
|
-
require "
|
|
2
|
-
require "generators/trek/helpers"
|
|
1
|
+
require "generators/trek/scalingo_generator"
|
|
3
2
|
|
|
4
3
|
module Trek
|
|
5
4
|
module Generators
|
|
6
5
|
module Install
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
# The Scalingo generator under its former name: `trek:install` doesn't run it, so it's `trek:scalingo` now.
|
|
7
|
+
# Removed in Trek 3.
|
|
8
|
+
class ScalingoGenerator < Trek::Generators::ScalingoGenerator
|
|
9
|
+
hide!
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
desc "Create Scalingo files."
|
|
13
|
-
|
|
14
|
-
# The trek-buildpack replaces the apt + ruby buildpack combination. It
|
|
15
|
-
# pins Node from the .node-version that `rails new` already generates.
|
|
16
|
-
def remove_buildpacks
|
|
17
|
-
remove_file ".buildpacks"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def create_aptfile
|
|
21
|
-
create_file "Aptfile" do
|
|
22
|
-
<<~TEXT
|
|
23
|
-
libjemalloc2
|
|
24
|
-
libvips-tools --no-install-recommends
|
|
25
|
-
libwebp-dev
|
|
26
|
-
TEXT
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def create_procfile
|
|
31
|
-
create_file "Procfile" do
|
|
32
|
-
<<~TEXT
|
|
33
|
-
web: bundle exec rails server -p $PORT -e $RAILS_ENV -b 0.0.0.0
|
|
34
|
-
# worker: bundle exec sidekiq -C config/sidekiq.yml
|
|
35
|
-
postdeploy: bundle exec rails db:migrate
|
|
36
|
-
TEXT
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def final_instructions
|
|
41
|
-
say ""
|
|
42
|
-
say "Configure the Scalingo app environment:"
|
|
43
|
-
say ""
|
|
44
|
-
say " scalingo --app <app> env-set BUILDPACK_URL=#{BUILDPACK_URL}"
|
|
45
|
-
say " scalingo --app <app> env-set 'DATABASE_URL=$SCALINGO_POSTGRESQL_URL'"
|
|
46
|
-
say ""
|
|
47
|
-
say "and make sure config/database.yml reads DATABASE_URL in production."
|
|
48
|
-
say ""
|
|
49
|
-
say "See https://trek.etamin.studio/deploy for details."
|
|
50
|
-
say ""
|
|
11
|
+
def deprecation_warning
|
|
12
|
+
say "`trek:install:scalingo` is deprecated and will be removed in Trek 3: run `trek:scalingo`.", :yellow
|
|
51
13
|
end
|
|
52
14
|
end
|
|
53
15
|
end
|