You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NH-155201: restrict the config file permission - #322
Removed Dir.pwd auto-discovery: Config files are no longer searched for relative to the current working directory. Instead, at most one config file is loaded per process.
Strict SW_APM_CONFIG_RUBY rules & precedence: When set, SW_APM_CONFIG_RUBY takes precedence over Rails initializers and must point to an absolute path to a file. Relative paths, directories, and missing files log a warning without falling back to other paths.
Rails & non-Rails behavior: When SW_APM_CONFIG_RUBY is unset, only Rails apps load <Rails root>/config/initializers/solarwinds_apm.rb. Non-Rails apps no longer load a config file automatically and must explicitly set SW_APM_CONFIG_RUBY=/absolute/path/to/solarwinds_apm_config.rb (a warning is logged if a legacy solarwinds_apm_config.rb is found in the working directory).
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The permission check misses replaceable symlink targets in world-writable directories, while documentation overstates enforcement and tests do not assert the required warnings.
This PR updates how the SolarWinds APM Ruby agent selects configuration files and introduces permission warnings ahead of planned enforcement in the next release.
Changes:
Gives SW_APM_CONFIG_RUBY exclusive precedence and resolves default paths relative to the application root.
Warns about world-writable configuration files and non-sticky world-writable directories while continuing to load them.
Adds selection and permission tests, plus configuration documentation.
File
Description
test/solarwinds_apm/config_test.rb
Adds configuration precedence, root resolution, and permission scenarios.
lib/solarwinds_apm/config.rb
Refactors file selection and adds permission warnings.
CONFIGURATION.md
Documents selection precedence and configuration permission policy.
Update configuration handling to warn instead of refuse loading world-writable files and directories. Adjust tests to reflect the new behavior.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
I suggest we stop access to world-writable config files immediately and make it a breaking release, but maybe there is a key use Ruby case for step-wise? cc @cheempz
I suggest we stop access to world-writable config files immediately and make it a breaking release, but maybe there is a key use Ruby case for step-wise? cc @cheempz
Agree. Also, similar to Python the permission check will not work on Windows (and would involve implementing a native extension to check the ACL). AI output:
Ruby’s world_writable? does not inspect Windows ACLs, and sticky-bit semantics are unsupported. Configuration loading should still work, but the checks cannot reliably identify insecure permissions.
I think it would be fair enough to highlight the permission check will not apply on Windows.
The reason will be displayed to describe this comment to others. Learn more.
More changes please. Also, do we know what happens when world_writable? is called for a file on Windows, meaning could it cause the trusted config check to return false? IMHO safer to check if system is posix and explicitly exclude (or ensure returns true) on Windows.
ruby world_writable? will return nil for all the file it checks, which make the function trusted_config_file? always return true.
Is python trying to implement native check like checking from cmd output like out, status = Open3.capture2e('icacls', config_file)
@tammy-baylis-swi made a POC PR that that checked for effective user id of the file, it is not supported on Windows so we decided to not make the effective user id check at all, since her other changes addressed the security concerns. I think this check for permissions is a good idea--what i'm trying to point out is we don't know the behaviour of world_writeable? on all versions of Windows, so why not make this more deterministic--detect if on posix system, if so, go ahead with check. else skip check.
detect if on posix system, if so, go ahead with check. else skip check.
Do we allow this risk on windows? Does python have an approach to remove this kind of risk completely?
For Python, the risk of maliciously crafted config that allowed writing a privileged file was removed via tighter sanitation of input/output so we decided there was no need to check the config file ownership agains effective user id of the application. Implementing it for Python on Windows would require either a subprocess that runs Powershell/CMD or dragging in native extension code dependency, neither seem worth it for the added security.
For Ruby, if you find that implementing the check on Windows is rather lightweight (doesn't require native extension or dependencies in the runtime), then it's worth doing. Otherwise i'm fine with allowing this risk on Windows if the changes in this and other PRs address the original issue posted in the PSIRT report.
I see, I think to sanitize the config file makes more sense. For ruby, I was also thinking the subprocess (e.g. Open3.capture2e), but yeah, it seems not ideal
Ruby uses .rb files to load configuration, which is very hard to sanitize. Unlike other languages that use JSON or YAML (such as OTel config files) which are easier to sanitize, loading an .rb file requires executing the code inside it.
I am thinking of changing the apm-ruby config file from an .rb file to a YAML or JSON file, aligning it with other languages and complying with the OTel specification.
For Rails, even though an .rb file is more favored because it loads from config/initializers/*.rb, I am thinking we could keep that .rb file without any default values and comment out all the options—while changing the gem defaults (solarwinds_apm_config.rb and ENV['SW_APM_CONFIG_RUBY']) to JSON or YAML.
Alternatively, we could completely drop the Rails initializer generator (for example, installing config via rails solarwinds_apm:install).
no autodiscovery of the config file--for Rails it's already prescribed path. for non-Rails, require the absolute path to be explicitly given (not whatever is in instrumented process's current dir)
on POSIX system, verify not world writable and (bonus points) that the file is owned by root or by same effective user of the instrumented process
on non-POSIX system log an info message about skipping permission checks
add tests
make corresponding documentation changes
And agree we should switch the non-Rails SWO config to YAML or JSON to align with upstream esp. future declarative config--but let's do that in a separate PR.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical path-validation gaps allow attackers to replace unchecked ancestor directories or retarget symlinks between validation and loading, enabling execution of untrusted Ruby code.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Permission checks allow untrusted group members to modify root-owned configuration files or replace entries in group-writable ancestor directories, enabling Ruby code execution with the application's privileges.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Reject group-writable configs and non-sticky ancestor directories
lib/solarwinds_apm/support/secure_path.rb:75
The permission checks accept root-owned 0664 files and 0775 directories even when their groups include untrusted users. Those users can modify the config in place or replace entries in a non-sticky ancestor directory before loading, causing Ruby code to execute with the application's privileges. Reject group-writable files and group-writable non-sticky directories throughout the ancestor walk (also at line 75), unless an explicit trusted-group policy is enforced.
The reason will be displayed to describe this comment to others. Learn more.
@xuan-cao-swi this seems very strongly worded and potentially misleading for what we're trying to achieve. We can only minimize risk by checking obviously bad permissions, not guarantee that a file is safe to execute. Can this module be somehing like PosixPermissionCheck instead?
The reason will be displayed to describe this comment to others. Learn more.
@xuan-cao-swi sorry, i suggested the euid check, but from more research this could be an issue in containers if the config file is mounted from the host. Depending on the OS and container runtime, the mounted file's UID may or may not be remapped to a UID in the container (and even if remapped, it could very well be different from EUID of the application process). The remapping typically is enabled in Docker Desktop (which would mask this problem) but not in Linux. How about let's remove this check?
The reason will be displayed to describe this comment to others. Learn more.
@xuan-cao-swi i only looked at the secure_path.rb and CONFIGURATION, but wanted to get you this feedback first. Happy to go over together too if you'd like.
Configuration files are not auto-discovered for non-Rails applications. A `solarwinds_apm_config.rb` in the current working directory isn't loaded; the agent logs a warning instead.
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
Configuration files are not auto-discovered for non-Rails applications. A `solarwinds_apm_config.rb` in the current working directory isn't loaded; the agent logs a warning instead.
> [!NOTE]
> Starting with version 8.0.0, the configuration file is no longer auto-discovered; a warning is logged for the deprecated behavior where `solarwinds_apm_config.rb` was loaded from the current working directory.
- **PostgreSQL**: the "[exec-ish](https://github.com/solarwinds/apm-ruby/blob/main/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb#L15)" operations like `exec` and `query` are supported.
> **⚠️ Limitation:** Currently does not support prepared statements.
These checks don't apply to the Rails initializer `config/initializers/solarwinds_apm.rb`, because Rails loads every file in `config/initializers` regardless. Protect it like the rest of your application code.
> **Note:** On non-POSIX systems (Windows), file permission bits aren't meaningful, so the agent skips these checks. Secure the configuration file with Windows ACLs instead.
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
> **Note:** On non-POSIX systems (Windows), file permission bits aren't meaningful, so the agent skips these checks. Secure the configuration file with Windows ACLs instead.
> [!NOTE]
> File permissions is only checked on POSIX systems.
The reason will be displayed to describe this comment to others. Learn more.
This part is now making me think:
Rails loads every file in config/initializers regardless.
in line 54 we're calling load(config_file) if config_file. Does that mean if APM Ruby config is given as a Rails initializer, it ends up being loaded twice?
The reason will be displayed to describe this comment to others. Learn more.
Can you add a rule in the AGENTS file to standardize docs on github markdown alerts and get it to update all instances? i've made some comment suggestions based on spot checking but there's probably more.
Configuration files are not auto-discovered for non-Rails applications. A `solarwinds_apm_config.rb` in the current working directory isn't loaded; the agent logs a warning instead.
1. If `SW_APM_CONFIG_RUBY` is set, only that file is used. It must be an absolute path to a file. A relative path, a directory, or a missing file means no configuration file is loaded, and the agent doesn't fall back to the Rails initializer.
1. If `SW_APM_CONFIG_RUBY` is set, only that file is used. It must be an absolute path to a file. A relative path, a directory, or a missing file means no configuration file is loaded, and the agent doesn't fall back to the Rails initializer.
2. Otherwise, for Rails applications only, the agent loads `config/initializers/solarwinds_apm.rb` from the Rails application root. The root is `Rails.root` when it's available, or the directory of the absolute `BUNDLE_GEMFILE` set by the Rails `config/boot.rb`. The current working directory is never searched.
Permission checks allow untrusted group members to modify root-owned configuration files or replace entries in group-writable ancestor directories, enabling Ruby code execution with the application's privileges.
This seems too restrictive, there could be valid use case (like CI/CD or infra-as-code) where the config file should be group writable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Dir.pwdauto-discovery: Config files are no longer searched for relative to the current working directory. Instead, at most one config file is loaded per process.SW_APM_CONFIG_RUBYrules & precedence: When set,SW_APM_CONFIG_RUBYtakes precedence over Rails initializers and must point to an absolute path to a file. Relative paths, directories, and missing files log a warning without falling back to other paths.SW_APM_CONFIG_RUBYis unset, only Rails apps load<Rails root>/config/initializers/solarwinds_apm.rb. Non-Rails apps no longer load a config file automatically and must explicitly setSW_APM_CONFIG_RUBY=/absolute/path/to/solarwinds_apm_config.rb(a warning is logged if a legacysolarwinds_apm_config.rbis found in the working directory).Test (if applicable)