Problem/Motivation

Some of the tests are slow, and it's an hypothesis that avoiding running the audit part of certain composer commands might speed up the tests.

https://getcomposer.org/doc/03-cli.md#composer-no-audit

Theoretically we might even want this to be this way in the actual package manager module?

Steps to reproduce

Proposed resolution

Either pass --no-audit or use the environment variable COMPOSER_NO_AUDIT

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3491268

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

eiriksm created an issue. See original summary.

eiriksm’s picture

Issue summary: View changes
eiriksm’s picture

catch’s picture

I would imagine we will never show the results of the audit directly in the composer UI, it would be an explicit operation, so we should probably look into passing --no-audit both inside and outside of tests, although this could be two separate issues.

eiriksm’s picture

Status: Active » Needs review

Well here is at least an attempt. I don't know the package manager codebase intimately, but this seems to be a common code path for the tests at least.

I also verified that the output before adding the flag included the string "No security vulnerability advisories found." (which comes from when composer is doing audits) and after I added it, it no longer was part of the output.

The result for me for running just one specific test was no actual gain in speed, but that was a relatively simple and fast kernel test. Let's rather see what the full run says

eiriksm’s picture

Hm this makes me a bit unsure if I am reading this correctly. Or even how consistent timings are across test runs or test runners. So I hope you will forgive me if I am completely misunderstanding and off track here... But...

https://git.drupalcode.org/issue/drupal-3491268/-/pipelines/357608 first full pipeline with fix. 7 mins 29 secs

https://git.drupalcode.org/issue/drupal-3491268/-/pipelines/357625 second run. Fix reverted for comparison. 9 mins 43 secs.

https://git.drupalcode.org/issue/drupal-3491268/-/pipelines/357678 third run, fix added back. 4 mins 45 secs.

Sounds kind of promising?

catch’s picture

So the way I compare run times on gitlab is to click into the individual job, and look at the run-tests.sh summary.

e.g.

Run 1 https://git.drupalcode.org/issue/drupal-3491268/-/jobs/3571254

Drupal\Tests\package_manager\Kernel\PhpTufValidatorTest       13 passes  216s  

Run 2
https://git.drupalcode.org/issue/drupal-3491268/-/jobs/3571532

Drupal\Tests\package_manager\Kernel\PhpTufValidatorTest       13 passes  129s  

Run 3 https://git.drupalcode.org/issue/drupal-3491268/-/jobs/3572029

Drupal\Tests\package_manager\Kernel\PhpTufValidatorTest       13 passes  149s   

However the times are so variable on gitlab at the moment that this is very inconclusive. Also possible it looks different for a different package_manager test.

I think running one of the package_manager tests with a lot of methods/data providers locally before/after is probably a better bet for comparison at the moment.

eiriksm’s picture

Ah, makes much more sense. Thanks!

I'll produce some comparisons locally instead then ✌️

quietone’s picture

Version: 11.1.x-dev » 11.x-dev

Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

tedbow’s picture

First want to say I am so glad Package Manager is in core so we can get more eyes on it to make improvements.

Theoretically we might even want this to be this way in the actual package manager module?

Just want to say that we did the audit in package manager because we were a bit paranoid that our test setup can only test so much and there might be many many differences among real composer projects. So we thought it safest to use audit to hopefully at least ensure the projects are the way composer expects or would want things set up.

I think running composer operations on live site, even though we do it in sandbox first, is potentially dangerous so I think being paranoid and trying to ensure setting up things the *right* way, as much as possible, is warranted.

eiriksm’s picture

That's a very valid reason. However, I want to offer another view at it.

I think running composer operations on live site, even though we do it in sandbox first, is potentially dangerous so I think being paranoid and trying to ensure setting up things the *right* way, as much as possible, is warranted.

Ideally one would of course not want to run composer on a live site. But we know that will be the case already for many, plus using package manager is in practice exactly that. But personally, I would for sure turn off auditing on a live site. The auditing should occur other places than on prod while building your site. But yeah, that ideal scenario is not what we are catering with package manager for sure :)

In addition, I would argue it's less robust, especially in the package manager setting. Doing a require with audit takes longer time, and increases the chance of different forms of timeout. In addition it opens up for the scenario where the composer require (or other commands) could exit with exit code 1, even if the install was succesful. In a programmatic way, this will for sure create confusion. Here is an example where I am faking an exception, to illustrate the state of it:

$ composer require psr/log                                                                                                        
./composer.json has been updated
Running composer update psr/log
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking psr/log (3.0.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing psr/log (3.0.2): Extracting archive
Generating autoload files

In Installer.php line 430:
                  
  some exception  
                  

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-m|--minimal-changes] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]

$ echo $?
1
$ ls vendor
autoload.php  composer  psr

So I would argue using no audit is more robust, and more "right way". My personal opinion and 2 cents though :D

Still have not had time to produce any good results on test runs, but it seems the gain is small but consistent. Will try to post some results at some point :)

catch’s picture

Doing a require with audit takes longer time, and increases the chance of different forms of timeout.

We also have additional overhead (quite a lot at the moment, hopefully it will improve) from PHP-TUF, so the chances of timeouts are non-zero and agreed that the theoretical chance of a timeout seems more likely than the theoretical chance of composer audit finding a mistake.

smustgrave’s picture

What's a good way to test this one?

catch’s picture

It can be manually tested with project_browser via contrib. There's no way to manually test it with just core.

catch’s picture

Rebased on 11.x

Just one run, but https://git.drupalcode.org/project/drupal/-/pipelines/445049 the build tests, usually the slowest due to package_manager, finished faster than some functional and functional js tests, so this may be bringing the relative time down a bit?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a small change to a test class, so why not?

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs subsystem maintainer review

Given @tedbow's comment, I'd prefer to have subsystem maintainer review here.

Also I think we should skip the audit operation in regular package_manager operations too - even with php-tuf performance improvements recently there is still a lot of additional http requests etc.

cmlara’s picture

I want to re-afirm @tedbow comments from #11 Generally with testing you want to test "worst case" in this case that means Audit On as it will likely be enabled on sites.

could exit with exit code 1, even if the install was succesful. In a programmatic way, this will for sure create confusion

Arguably an error has occurred and package_manager does need to deal with it.

I would imagine we will never show the results of the audit directly in the composer UI, it would be an explicit operation,

Also I think we should skip the audit operation in regular package_manager operations too -

I can understand not displaying, however silently allowing a 'known vulnerable' package to be installed? To my knowledge php-tuf will not be replacement for composer audit(security advisory parsing).

Large commercial sites are much less likely to use Package Manager, they are going to run controlled labs with dev environments. Tooling like this is really an advantage for the SMB/Home User market. Both of these are signifcantly more likely to run in production. Home users have much less concern, the SMB market however, their insurance agent will look for any reason to reject a claim, intentionally ignoring/not processing AUDIT results may make a very good reason to reject.

Even just having the code on the server may be enough for an auditor to flag a concern. From an audit standpoint it would likely be better to encourage users to set the COMPOSER_NO_AUDIT environment variable through settings.php to disable processing so that it does not impact more secure sites and is not enabled by default.

Is #18 a formal Security Review or should this issue be flagged for that as well?

catch’s picture

Issue tags: +Needs security review

I can understand not displaying, however silently allowing a 'known vulnerable' package to be installed?

Currently any potential output from composer --audit is discarded by package_manager, so "silently allowing a 'known vulnerable' package to be installed" is the status quo.

The --audit flag is enabled for every package manager operation - this includes unattended automatic updates which could be run via a cli cron job. Possibly the output could be logged there, but logs are ephemeral (especially on smaller sites) so it could easily be missed even if it was logged. Also don't think the output is useful to show people if they're e.g. updating a specific contrib module and the CVE is for a completely different dependency of a different module.

So if we want to alert site admins to known security vulnerabilities in non-Drupal dependencies, then I don't think running with --audit and then throwing the results away is useful at all, it would be better to try to incorporate an explicit composer audit call into update status somewhere (e.g. only when package_manager is enabled) - then it would be available in admin/reports, integrated with e-mail notifications etc. It's pretty unusual to newly install or update a package that has a known CVE, much more likely a package that is already installed has a CVE issued for it and needs update.

Might as well tag for security review as well, but I think a new issue to add an explicit composer audit and show the results would do a lot more here.

catch’s picture

Also I'm not sure #11 is really describing what the --audit flag does - it doesn't audit your composer project as such, it checks for security advisories. If there's a problem with a require or update, you get an error long before --audit would happen because it's (iirc) the very last thing to run.

cmlara’s picture

The --audit flag is enabled for every package manager operation - this includes unattended automatic updates which could be run via a cli cron job.

I was reading #4 and following as suggesting that audits NOT be a part of the package manager operation (wasn't aware flag explicitly was there vs the implicit composer use of it by default).

so "silently allowing a 'known vulnerable' package to be installed" is the status quo.

Understood on that being current and IMO bug on its own that it should be handled rather than silently allowed.

I think a new issue to add an explicit composer audit and show the results would do a lot more here.

There can be some value in this. Assuming that an audit call is added as part of a transaction that prevents a vulnerable package from being installed beyond just a 'sandbox' and transferred to 'production' that would likely be acceptable.

I would suggest that should be done before passing the audit ignore flag which may cause a successful return from Composer (in other words, postpone this issue).

Note: I'm not familiar with Project Browsers internals. I see comments such as 'sandbox' above and assume its doing a standard A/B on disk with a staged swap over only after passing basic checks such as composer success.

catch’s picture

Title: Look into skipping audit of composer operations in package manager » Look into skipping audit of composer operations in package manager tests
Issue tags: -Needs security review

Untagging for security review because this is a test-only change and clarifying that in the title.

If we want to remove --audit everywhere that could possibly use security review but given the --audit does literally nothing when run via package_manager at the moment, I don't see what it's doing that would be remotely useful.

I've opened #3531138: Consider showing composer audit results in a report as a spin-off though.

Assuming that an audit call is added as part of a transaction that prevents a vulnerable package from being installed

Feel free to open an issue about this, but simply checking if composer audit returns any results isn't sufficient - it would for example prevent updating to a security release of a dependency, just because another dependency had a CVE issued in the last ten minutes or similar. The composer audit results would have to be filtered down to only whether the project is being newly installed, and composer doesn't actually provide a useful list of what is being newly installed. #3525563: Create a Composer plugin that records what packages are being updated, installed, or removed is open to try to workaround that, but it would at minimum need to be postponed on that issue.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs subsystem maintainer review

Asked this in slack #core-development https://drupal.slack.com/archives/C079NQPQUEN/p1755969156766519 and @phenaproxima
mentioned we should skip audits in tests, so removing that tag.

Re-ran AssetAggregationAcrossPagesTest twice though and it's consistently failing, can that be looked at

Thanks!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.