2

Background

I want to make my site code open source, for reasons of:

  • collaboration
  • developing an open source Drupal distribution or module (yes I know distributions might be superseded by recipes but that is still a work in progress)
  • (other reasons not applicable to me, but good reasons): public sector / government requirement

Problem

In wanting to open source my code, I notice that my config export as code (yaml) contains personal email addresses. I want to stop this happening but for my working site to still function. So I want to store them outside of git-version controlled config.

Specific examples of personal emails being stored in config export which will be committed to git:

  • Site mail address in system.site.yml
  • Webform email addresses - in webform.webform.contact.yml:

e.g.

handlers:
  email_confirmation:
    settings:
      to_mail: [email protected]

My question

How can I store specific config items such as email addresses, api keys and hashes outside of git-version controlled config export but still read by Drupal as config?

My research to solve the problem:

I have been unsuccessful, hence asking this question, but here is what I tried.

I tried to apply the following to my own example:

Here's what I tried to apply - I have my system.site.yml which contains the personal email address which I want to take out of git version controlled config and control in the environment:

_core:
  default_config_hash: (a hash value)
langcode: en
uuid: (a long dash separated hex number)
name: 'My site'
mail: [email protected]
slogan: ''
page:
  403: ''
  404: ''
  front: /node/1
admin_compact_mode: false
weight_select_max: 100
default_langcode: en
mail_notification: ''

Based on the above 2 links to references above, here's my attempt at equivalent config in settings.local.php not stored in git (.gitignore-d), but called from git controlled settings.php

# config/sync/system.site.yml
# mail: [email protected]
$config['system.site']['mail'] = '[email protected]';

(this file also stores my database credentials).

So to try this out, I:

  • commented out mail: [email protected] in system.site.yml
  • added the config as above to my settings.local.php
  • ran drush cim to remove the email from active config, hoping that Drupal would now take it from my settings.local.php
  • ran drush cr to clear the cache

Then I visited the Basic site settings page (that uses system.site.yml config): admin/config/system/site-information, but saw that the mail field was empty!

email email setting

So Drupal wasn't taking the config defined in my settings.local.php.

Further research

From looking at the below links, I'm unclear if general full support is available to override any / all of the configurations in Drupal:

Other items (not sure if relevant)

Research to do - how do distro-makers do it?

I would imagine in their development, they test real sites, with personal settings, but then want to release their work to the public with this data removed, so how do they do it?

2
  • “So Drupal wasn't taking the config defined in my settings.local.php.” That is untrue. Drupal doesn’t show overridden configurations in the UI.
    – mona lisa
    Commented Jul 7 at 22:10
  • Yes @monalisa - also Patrick Kenny says this in their answer below. For me, it was reasonable for me to assume "Drupal wasn't taking the config defined in my settings.local.php." if it wasn't showing it. And I agree with Patrick Kenny that this is very confusing behaviour; after all a purpose of a UI is to reflect the true state of the system. But now, with the knowledge that you and Patrick Kenny have shared, I am aware of the behaviour. Thank you. Commented Jul 7 at 23:06

1 Answer 1

2

Drupal does not show overridden config in the UI; this is very confusing behavior and a 10-year-old core issue. To see overridden config, you need something like the COI module or Config Override Warn module.

How to avoid committing certain config items

Most forms in the Drupal UI have some kind of validation. So, if you are using a standard workflow like drush cex to export config, to generate the config in the first place, you will need to put in valid values (such as an email address).

That means that you can't just put in a value like placeholder for an email address field; you will have to input something like [email protected]. Personally, I would use the same placeholder email everywhere to make it easier to search for later, but any valid email address will do. Alternately, you can input the actual values in the UI, export config, and then edit the exported config to placeholder values, but with that approach there is a higher risk that you will miss something and commit it accidentally.

Then you can override the values in settings.local.php as you described in your question.

If you want to use environment variables instead, that is also possible. But the basic approach for this is the same as using settings.php: you set the config value in settings.php according to the environment variable value read in settings.php, in the way described in this answer, for example.

5
  • +1 thank you @Patrick Kenny. Success: with your advice, I found that what I did actually worked. As you say the overriden config isn't displayed. I will checkout [drupal.org/project/coi](Config Override Inspector). This will likely be the accepted answer. I will do some further tests and then follow up here. Thanks again. Commented Jul 7 at 23:03
  • working towards marking this answer as accepted. In doing so I'm looking at any other personal/sensitive info in config. What do you think of uuid and default_config_hash - these appear to be unique. I wouldn't want these in my published open source either, this answer somewhat addresses it but wish Drupal/Drush provided some built-in automation drupal.stackexchange.com/questions/295320/… Commented Jul 8 at 14:53
  • Unique !== sensitive. UUIDs are basically equivalent to UIDs/NIDs, and if you are using something like JSON:API, they are all public even if your site's code is not available. Commented Jul 8 at 22:36
  • +1 finally accepted. I've just adjustment my site today and tested and it works great - so... thank you very much. Also Drupal 11 out today so wondering if that issue has been worked on, as the comments there indicated: drupal.org/project/drupal/issues/2408549 Commented Aug 3 at 1:57
  • 1
    @therobyouknow Yes, Drupal 11 now issues a basic warning about this! Commented Aug 3 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.