Skip to content

Commit 4770af1

Browse files
authored
Allow setting Allauth provider secrets from host system (#11194)
* Allow setting Allauth provider secrets from host system This requires - readthedocs/common#209 It is modeled after the Stripe setting pattern. There is a stronger pattern here at some point, this is a bare minimum for now to unblock us from not having these settings on our local environments. You can use `direnv` to automatically export (and encrypt if you are so inclined) these secrets for your local envs. The env vars pass through Docker with common/#209 above. * Add some docs too * Note direnv too * Drop unused key env vars/settings for allauth pass through * Update common * Drop bitbucket provider settings/env vars * Update common
1 parent bba466b commit 4770af1

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

docs/dev/settings.rst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,41 @@ ELASTICSEARCH_DSL_AUTOSYNC
130130

131131
This setting is used for automatically indexing objects to elasticsearch.
132132

133-
134133
.. _elasticsearch-dsl-py.connections.configure: https://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters
134+
135+
136+
Docker pass-through settings
137+
----------------------------
138+
139+
If you run a Docker environment, it is possible to pass some secrets through to
140+
the Docker containers from your host system. For security reasons, we do not
141+
commit these secrets to our repository. Instead, we individually define these
142+
settings for our local environments.
143+
144+
We recommend using `direnv`_ for storing local development secrets.
145+
146+
.. _direnv: https://direnv.net/
147+
148+
Allauth secrets
149+
~~~~~~~~~~~~~~~
150+
151+
It is possible to set the Allauth application secrets for our supported
152+
providers using the following environment variables:
153+
154+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GITHUB_CLIENT_ID
155+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GITHUB_SECRET
156+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GITLAB_CLIENT_ID
157+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GITLAB_SECRET
158+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_BITBUCKET_OAUTH2_CLIENT_ID
159+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_BITBUCKET_OAUTH2_SECRET
160+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GOOGLE_CLIENT_ID
161+
.. envvar:: RTD_SOCIALACCOUNT_PROVIDERS_GOOGLE_SECRET
162+
163+
Stripe secrets
164+
~~~~~~~~~~~~~~
165+
166+
The following secrets are required to use ``djstripe`` and our Stripe integration.
167+
168+
.. envvar:: RTD_STRIPE_SECRET
169+
.. envvar:: RTD_STRIPE_PUBLISHABLE
170+
.. envvar:: RTD_DJSTRIPE_WEBHOOK_SECRET

readthedocs/settings/docker_compose.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ def DATABASES(self): # noqa
208208
STRIPE_TEST_SECRET_KEY = STRIPE_SECRET
209209
DJSTRIPE_WEBHOOK_SECRET = os.environ.get("RTD_DJSTRIPE_WEBHOOK_SECRET")
210210

211+
@property
212+
def SOCIALACCOUNT_PROVIDERS(self):
213+
"""Allow settings social account settigs from the host system."""
214+
providers = self._SOCIALACCOUNT_PROVIDERS
215+
for provider in providers.keys():
216+
try:
217+
for setting in ["client_id", "secret"]:
218+
value = os.environ.get(
219+
f"RTD_SOCIALACCOUNT_PROVIDERS_{provider.upper()}_{setting.upper()}"
220+
)
221+
if value is not None:
222+
providers[provider]['APPS'][0][setting] = value
223+
except KeyError:
224+
pass
225+
return providers
226+
211227
RTD_SAVE_BUILD_COMMANDS_TO_STORAGE = True
212228
RTD_BUILD_COMMANDS_STORAGE = "readthedocs.storage.s3_storage.S3BuildCommandsStorage"
213229
BUILD_COLD_STORAGE_URL = "http://storage:9000/builds"

0 commit comments

Comments
 (0)