Grant permission to current user at runtime in specific environment Many Drupal contrib modules have inverse "feature flag" implementations vis-a-vis a killswitch variable added to settings.local.php to disable a feature:

// Killswitch setting.
$settings['disable_captcha'] = TRUE;

// Config override.
$config['google_analytics.settings']['account'] = '';


However, the Drupal 8 version of CAPTCHA does not yet have the disable_captcha killswitch that existed in Drupal 7 (see related issue #2836076).

The module does have another kind of killswitch via a Drupal permission skip CAPTCHA.  This got me wondering:

Is it possible to dynamically add a permission to the current site visitor—both anonymous or authenticated users—at runtime for a specific environment without affecting the standard roles &amp; permissions store so that configuration management/sync is not adversely affected by the environment-specific permission?

Ideally this logic would be located in settings.local.php to avoid the following risks and technical debt


the chance that unintended environments would be affected, and 
to have to copy/paste/commit solutions to this problem in every client project only to have to later remove that code once the proper killswitch solution in issue #2836076 lands.
Yes you can but why not just remove the field ? here is a few ideas on to how to do it..

in settings.local.php

 //add
$settings['stop_captcha_from_being_stupid'] = TRUE;
// or 
$settings['enviroment_name'] = 'dev';


in some hook_form_alter

use Drupal\Core\Site\Settings; // above ^^^
$stop_capcha = Settings::get('stop_captcha_from_being_stupid') ;
if ($stop_capcha === TRUE) {
  unset($form['captcha']);
}

// or enviroment with custom header ;)
$current_request = $request = \Drupal::request();
if (!empty($current_request-&gt;headers-&gt;get('shutup-captcha'))) {
  if ($current_request-&gt;headers-&gt;get('shutup-captcha') == 'somesalt') {
    $environment_name = Settings::get('enviroment_name') ;
    $environments_to_allow_bypass_captcha = [
      'dev',
      'int',
      'test',
    ];
    if (in_array($environment_name, $environments_to_allow_bypass_captcha)) {
      unset($form['captcha']);
    }
  }
}