-
Notifications
You must be signed in to change notification settings - Fork 26
Config: Granular env-based Solution for Connection Strings #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Config: Granular env-based Solution for Connection Strings #57
Conversation
bf02100
to
6ceb654
Compare
8f4b0e6
to
2e1e160
Compare
5eeef92
to
e52709c
Compare
* testing with inveniosoftware/invenio-config#57
e52709c
to
c8d1038
Compare
* testing with inveniosoftware/invenio-config#57
b9c6913
to
8859a27
Compare
49faf05
to
f03c861
Compare
i'll check again how the usual configuration workflow in invenio is done: if i remember correctly, the fetching of config items from environment variables (which have the at TUW, we used to parse env vars similarly in our |
alright, so i just did a quick sweep: ✔️ this PR is actually part of the "env" part of invenio-config however, it looks like the
while it's nontrivial to override the prefix to be something other than (at TUW we used to also check all sorts of env vars in our that being said, i think this PR would only support the case where all of the parts are specified via env vars – is this correct? would it make sense to piece together the various connection strings in the most closely related packages' extensions on startup? |
as a bit of extra context, because i've mentioned TUW moving away from env var parsing in there we perform a very similar logic to what's presented in this PR here: https://gitlab.tuwien.ac.at/crdm/invenio-config-tuw/-/blob/master/invenio_config_tuw/startup/config.py?ref_type=heads#L87-106 (please ignore the overriding of the flask config class, that's related to our use case for supporting multiple domains) [1] some extensions like to set up their own variables (e.g. because there is no dedicated spot that fulfills our requirement (there is no hook between env loading & extension init), we "simply" made sure that our [2] https://gitlab.tuwien.ac.at/crdm/invenio-config-tuw/-/blob/master/invenio_config_tuw/config.py?ref_type=heads#L389-421 you are now cursed |
Add logic to build connection urls from env vars if available needed for helm charts security best practices. includes: * Build db uri * Build redis url * Build mq url Partially closes: inveniosoftware/helm-invenio#112
1da2e22
to
336e9e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, but I am a bit hesitant about placing it in invenio-config
, which so far has been dealing with "how" config is loaded, rather than "what" config is loaded.
My first thought to see where e.g. DB_HOST
is defined, purely based on convention, would be invenio-db
. I think it's worth to directly:
- remove the
INVENIO_
-prefixing logic in each function, since it anyways gets taken into account in this file - move each
build_*
function to its relevant module under theInvenioXYZ.init_config()
method of its extension. That would be:build_db_uri
toinvenio-db
build_search_uri
toinvenio-search
build_broker_uri
toinvenio-celery
build_redis_uri
toinvenio-cache
(though there is a caveat here that might require a bit more discussion, since we're depending on it also ininvenio-accounts
).
i just submitted a PR for a slightly adapted version of the code for Invenio-DB (linked above), and will create the other PRs later. |
With @max-moser stepping in, I'll gladly step back and let you work your magic 🪄. |
For context and history: following the discussion during the teleconference, we concluded with the following points, which @max-moser helpfully summarized on Discord and created issues for:
|
❤️ Thank you for your contribution!
Description
Add logic to build connection URLs from env vars if available
needed for helm charts security best practices.
This PR includes:
Partially closes: inveniosoftware/helm-invenio#112
Depends on: inveniosoftware/invenio-app-rdm#2918
Note
I created a test version encapsulated in a cached class. Let me know if you prefer this over simple functions, and I’ll update accordingly see link
Findings
For the database URI, ensure that
SQLALCHEMY_DATABASE_URI=""
is set to an empty string to allow the granular variables to take effect.For the broker, I opted for the naming convention
INVENIO_RABBITMQ_*
instead ofINVENIO_BROKER_*
, as the latter conflicts with RabbitMQ's default naming variables. For more details, refer to the documentation here.For reviewers:
I set up a testing instance to test these changes, with the
.env
file anddocker-services
modified, see: https://github.com/Samk13/invenio-dev-latest/tree/granular-env-vars-changesinvenio-app-rdm
to set these variables.Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: