Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retest with connection pool changes #19667

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
89dc901
MS-9682 Upgrade to Ruby on Rails 7.1
adeherdt-r7 Nov 11, 2024
6fa94bb
Fix platform
adeherdt-r7 Nov 11, 2024
2f7a2da
explicitly specify port
adeherdt-r7 Nov 11, 2024
1788b05
Fix rspec versions
adeherdt-r7 Nov 11, 2024
25c2626
don't upgrade zeitwerk
adeherdt-r7 Nov 11, 2024
051638f
Force `ActiveRecord::Base` to reconnect to the database.
adeherdt-r7 Nov 12, 2024
2e33402
Force `ActiveRecord::Base` to reconnect to the database when using `R…
adeherdt-r7 Nov 12, 2024
daa63e9
testing a hack to see if it solves the problem
adeherdt-r7 Nov 12, 2024
9d2c2d8
revert hack
adeherdt-r7 Nov 12, 2024
602cde5
Throw in some Rails 7.1 configuration.
adeherdt-r7 Nov 12, 2024
59ec25f
fix configuration
adeherdt-r7 Nov 12, 2024
f4338cb
Rails 7.1: Set the default column serialization coder.
adeherdt-r7 Nov 12, 2024
b9a9ee0
Rails 7.1: active_record is not loaded in all code paths
adeherdt-r7 Nov 12, 2024
285e69f
Rails 7.1: more configuration
adeherdt-r7 Nov 12, 2024
bda8128
Rails 7.1: update tests to account for timezone.
adeherdt-r7 Nov 12, 2024
e7c2f0b
undo connection magic
adeherdt-r7 Nov 12, 2024
a3b4498
Bug in Rails 7.1, disabling to verify the behavior.
adeherdt-r7 Nov 12, 2024
880448c
revert
adeherdt-r7 Nov 12, 2024
e52c7f9
revert date changes to match CI
adeherdt-r7 Nov 12, 2024
eda6de4
revert remaining date specs
adeherdt-r7 Nov 12, 2024
0476b4e
Timezone shennagings
adeherdt-r7 Nov 12, 2024
348dca3
More Rails 7.1 behavior changes and timezone
adeherdt-r7 Nov 12, 2024
088a61c
revert
adeherdt-r7 Nov 13, 2024
1272d5c
update specs based on CI output
adeherdt-r7 Nov 13, 2024
b77a9a7
update specs based on CI
adeherdt-r7 Nov 13, 2024
9cd7ef6
Use a modern postgres to resolve segfault and openSSL issues
adeherdt-r7 Nov 13, 2024
7f55a28
disable transactional features for now
adeherdt-r7 Nov 13, 2024
13fce28
verifying if this is a Ruby 3.1 problem
adeherdt-r7 Nov 13, 2024
49585be
happens on all versions
adeherdt-r7 Nov 13, 2024
0ef8e4a
undo changes in workflow, issue is not postgres version bound.
adeherdt-r7 Nov 14, 2024
2146cc5
Undo code change
adeherdt-r7 Nov 15, 2024
f797c45
try to resolve the timezone issue
adeherdt-r7 Nov 15, 2024
b2c74aa
Revert time adjustments
adeherdt-r7 Nov 15, 2024
25f8592
revert unneeded change
adeherdt-r7 Nov 15, 2024
240351d
Remove calls to `ApplicationRecord.establish_connection`
adeherdt-r7 Nov 15, 2024
2904443
code cleanup
adeherdt-r7 Nov 15, 2024
ec22067
more timezone stuff
adeherdt-r7 Nov 15, 2024
bd92428
set a sane DB pool size
adeherdt-r7 Nov 15, 2024
dbd0013
keep activerecord as UTC
adeherdt-r7 Nov 15, 2024
3b8ea42
Remove connection pool patch
adfoster-r7 Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ group :development, :test do
gem 'rake'
# Define `rake spec`. Must be in development AND test so that its available by default as a rake test when the
# environment is development
gem 'rspec-rails'
gem 'rspec-rails', '~> 7.0'
gem 'rspec-rerun'
# Required during CI as well local development
gem 'rubocop'
Expand Down
83 changes: 52 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ PATH
metasploit-framework (6.4.37)
aarch64
abbrev
actionpack (~> 7.0.0)
activerecord (~> 7.0.0)
activesupport (~> 7.0.0)
actionpack (~> 7.1.0)
activerecord (~> 7.1.0)
activesupport (~> 7.1.0)
aws-sdk-ec2
aws-sdk-ec2instanceconnect
aws-sdk-iam
Expand Down Expand Up @@ -95,7 +95,7 @@ PATH
ruby_smb (~> 3.3.3)
rubyntlm
rubyzip
sinatra
sinatra (~> 3)
sqlite3 (= 1.7.3)
sshkey
swagger-blocks
Expand All @@ -118,28 +118,40 @@ GEM
aarch64 (2.1.0)
racc (~> 1.6)
abbrev (0.1.2)
actionpack (7.0.8.6)
actionview (= 7.0.8.6)
activesupport (= 7.0.8.6)
rack (~> 2.0, >= 2.2.4)
actionpack (7.1.5)
actionview (= 7.1.5)
activesupport (= 7.1.5)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionview (7.0.8.6)
activesupport (= 7.0.8.6)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview (7.1.5)
activesupport (= 7.1.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.8.6)
activesupport (= 7.0.8.6)
activerecord (7.0.8.6)
activemodel (= 7.0.8.6)
activesupport (= 7.0.8.6)
activesupport (7.0.8.6)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activemodel (7.1.5)
activesupport (= 7.1.5)
activerecord (7.1.5)
activemodel (= 7.1.5)
activesupport (= 7.1.5)
timeout (>= 0.4.0)
activesupport (7.1.5)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
Expand Down Expand Up @@ -186,6 +198,7 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.1)
benchmark (0.4.0)
bigdecimal (3.1.8)
bindata (2.4.15)
bootsnap (1.18.4)
Expand All @@ -196,6 +209,7 @@ GEM
chunky_png (1.4.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
cookiejar (0.3.4)
crass (1.0.6)
csv (3.3.0)
Expand Down Expand Up @@ -380,22 +394,28 @@ GEM
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
rackup (1.0.1)
rack (< 3)
webrick
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.8.6)
actionpack (= 7.0.8.6)
activesupport (= 7.0.8.6)
method_source
railties (7.1.5)
actionpack (= 7.1.5)
activesupport (= 7.1.5)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rasn1 (0.13.0)
Expand All @@ -405,7 +425,7 @@ GEM
nokogiri
redcarpet (3.6.0)
regexp_parser (2.9.2)
reline (0.5.10)
reline (0.5.11)
io-console (~> 0.5)
require_all (3.0.0)
rex-arch (0.1.16)
Expand Down Expand Up @@ -470,7 +490,7 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.0.1)
rspec-rails (7.1.0)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
Expand Down Expand Up @@ -511,6 +531,7 @@ GEM
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
securerandom (0.3.2)
simplecov (0.18.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -548,7 +569,7 @@ GEM
macaddr (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
webrick (1.8.2)
webrick (1.9.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -586,7 +607,7 @@ DEPENDENCIES
pry-byebug
rake
redcarpet
rspec-rails
rspec-rails (~> 7.0)
rspec-rerun
rubocop
ruby-prof (= 1.4.2)
Expand Down
11 changes: 10 additions & 1 deletion config/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Metasploit Framework Config Folder

Contains various files that help configure Metasploit. Most files here you'll never have to deal with, though
`database.yml.example` might be useful for those looking to configure their database, and `openssl.conf`
might be helpful for those trying to troubleshoot OpenSSL issues in Metasploit.
might be helpful for those trying to troubleshoot OpenSSL issues in Metasploit.

> [!IMPORTANT]
> Because the behavior of Ruby on Rails changes between versions,
> and code needs to be considered thread-safe when dealing with Ruby on Rails,
> we ensure that the `reconnect: true` property is configured for our database
> connection. This allows the console/framework to reconnect when a thread messes
> up the connection pool.
53 changes: 42 additions & 11 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,53 @@ module Framework
class Application < Rails::Application
include Metasploit::Framework::CommonEngine

config.paths['log'] = "#{Msf::Config.log_directory}/#{Rails.env}.log"
config.paths['log'] = "#{Msf::Config.log_directory}/#{Rails.env}.log"
config.paths['config/database'] = [Metasploit::Framework::Database.configurations_pathname.try(:to_path)]

config.autoloader = :zeitwerk

case Rails.env
when "development"
config.eager_load = false
when "test"
config.eager_load = false
when "production"
config.eager_load = false
end
# Load the Rails 7.1 defaults.
config.load_defaults 7.1

# The cache behavior changed with Rails 7.1, and requires the desired version to be set.
config.active_support.cache_format_version = 7.1

# Timezone shenanigans
config.time_zone = 'UTC'

if config.respond_to?(:active_record)
# The default column serializer was YAML prior to Rails 7.1
config.active_record.default_column_serializer = ::YAML

# Timezone settings
config.active_record.default_timezone = :utc

if ActiveRecord.respond_to?(:legacy_connection_handling=)
ActiveRecord.legacy_connection_handling = false
# Partials inserts are disabled by default in Rails 7
# This only writes attributes that changed.
config.active_record.partial_inserts = true

# Foreign Key Validation - Belongs-to
# Was not enabled by default
config.active_record.belongs_to_required_validates_foreign_key = true

# This behavior changed in 7.1
config.active_record.commit_transaction_on_non_local_return = false

# Originally allowed but silently ignored, raises in 7.1
config.active_record.raise_on_assign_to_attr_readonly = false

# Rails originally ran the callbacks on the first commit change.
# In Rails 7.1 this is done on all models, so we need to retain the behavior for now.
config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = true

# Rails 7.1 will execute after commit callbacks in order they are defined.
# Originally it was in reverse order.
config.active_record.run_after_transaction_callbacks_in_order_defined = false
end

# We never eager load files.
config.eager_load = false
config.enable_reloading = ::Rails.env.test?
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion config/database.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
# managing your database, which may be more convenient than rolling your own.

development: &pgsql
allow_concurrency: true
adapter: postgresql
database: metasploit_framework_development
username: metasploit_framework_development
password: __________________________________
host: localhost
port: 5432
pool: 200
pool: 10
timeout: 5
reconnect: true

# You will often want to seperate your databases between dev
# mode and prod mode. Absent a production db, though, defaulting
Expand Down
5 changes: 4 additions & 1 deletion config/database.yml.github_actions
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
# # update password fields for each environment's user

development: &pgsql
allow_concurrency: true
adapter: postgresql
database: metasploit_framework_development
port: 5432
host: localhost
username: postgres
password: postgres
pool: 25
pool: 10
timeout: 5
reconnect: true

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
Expand Down
4 changes: 3 additions & 1 deletion config/database.yml.vagrant
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
development: &pgsql
allow_concurrency: true
adapter: postgresql
database: msf_dev_db
username: vagrant
password: vagrant
host: localhost
port: 5432
pool: 200
pool: 10
timeout: 5
reconnect: true

production: &production
<<: *pgsql
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_12_09_005658) do
ActiveRecord::Schema[7.1].define(version: 2022_12_09_005658) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ services:
BUNDLER_ARGS: --jobs=8
image: metasploit:dev
environment:
DATABASE_URL: postgres://postgres@db:5432/msf_dev?pool=200&timeout=5
DATABASE_URL: postgres://postgres@db:5432/msf_dev?pool=100&timeout=5&reconnect=true&allow_concurrency=true
volumes:
- .:/usr/src/metasploit-framework
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
ms:
image: metasploitframework/metasploit-framework:latest
environment:
DATABASE_URL: postgres://postgres@db:5432/msf?pool=200&timeout=5
DATABASE_URL: postgres://postgres@db:5432/msf?pool=10&timeout=5&reconnect=true&allow_concurrency=true
links:
- db
ports:
Expand All @@ -11,7 +11,7 @@ services:
- $HOME/.msf4:/home/msf/.msf4

db:
image: postgres:10-alpine
image: postgres:14-alpine
volumes:
- pg_data:/var/lib/postgresql/data
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ development: &pgsql
password: Password123
host: 127.0.0.1
port: 5433
pool: 200
pool: 10

production: &production
<<: *pgsql
Expand Down
4 changes: 0 additions & 4 deletions lib/metasploit/framework/common_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ module Metasploit::Framework::CommonEngine

config.active_support.deprecation = :stderr

if ActiveRecord.respond_to?(:legacy_connection_handling=)
ActiveRecord.legacy_connection_handling = false
end

# @see https://github.com/rapid7/metasploit_data_models/blob/54a17149d5ccd0830db742d14c4987b48399ceb7/lib/metasploit_data_models/yaml.rb#L10
# @see https://github.com/rapid7/metasploit_data_models/blob/54a17149d5ccd0830db742d14c4987b48399ceb7/lib/metasploit_data_models/base64_serializer.rb#L28-L31
ActiveRecord.yaml_column_permitted_classes = (ActiveRecord.yaml_column_permitted_classes + MetasploitDataModels::YAML::PERMITTED_CLASSES).uniq
Expand Down
2 changes: 1 addition & 1 deletion lib/metasploit/framework/rails_version_constraint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Metasploit
module Framework
module RailsVersionConstraint
RAILS_VERSION = '~> 7.0.0'
RAILS_VERSION = '~> 7.1.0'
end
end
end
Loading
Loading