Skip to content
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

Add TLS/mTLS settings for postgreSQL and Redis #47

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

Shivangi-ch
Copy link
Contributor

This PR fixes: #28

Current behavior:-
With the current settings we can use PostgreSQL as database and Redis as cache, we only have to specify it in the configurations.
However, the current settings.py does not specify any TLS/mTLS options for DB and cache.

New Behavior:-
So to support TLS connections with the database and cache I have added new options only for postgresql database and redis caches.
I have added new keys such as sslmode, sslrootcert etc.
These values should be set in the configurations before running the server if we need to run in TLS/mTLS mode.

@Shivangi-ch
Copy link
Contributor Author

Hey @hongquan,
I have taken care of the recommendations mentioned by you in PR #46
Also I have moved the TLS config building logic to a separate file tls_settings.py and imported it in the main settings.py

Could you please review the PR

Copy link
Member

@hongquan hongquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename tls_settings.py to settings_helpers.py. Later on, we can move some other code to it.

Please format your code with Ruff. Only format your new file. Don't touch other files (this must be done in a dedicated PR somedays in the future).

@Shivangi-ch
Copy link
Contributor Author

Please rename tls_settings.py to settings_helpers.py. Later on, we can move some other code to it.

@hongquan I have renamed the file as suggested.

Please format your code with Ruff. Only format your new file. Don't touch other files (this must be done in a dedicated PR somedays in the future).

and formatted the new file using ruff.

}
# add postgresql mTLS options
if config.has_option("database", "sslcert"):
db_tls_config.update(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinks in these lines, writing like this is clearer:

db_tls_config['sslcert'] = config.get('database', 'sslcert')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the changes.

@@ -3,7 +3,7 @@
import os
import sys
from urllib.parse import urlparse

from .settings_helpers import *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please not use import *. Be explicit about what you want to import.
PEP8 coding style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made these changes.

"CLIENT_CLASS": "django_redis.client.DefaultClient",
"REDIS_CLIENT_KWARGS": {"health_check_interval": 30}
}
redis_tls_config = build_redis_tls_config(config)
if(redis_tls_config is not None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't format your code with Ruff?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this file is an existing file, we don't run Ruff on it. Then you have to format your code manually, based on PEP8 coding style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatted the code.

@@ -209,22 +214,28 @@

HAS_REDIS = config.has_option('redis', 'location')
if HAS_REDIS:
OPTIONS = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename it to redis_options. We don't expose it as application settings, no reason to make it all-uppercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to redis_options.

@hongquan hongquan merged commit 9387332 into fossasia:master Mar 12, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 5, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 6, 2024
@mariobehling
Copy link
Member

Due to challenges with the previous branch merges, it would be easiest if you could make this PR again against the current development branch. Appreciate your effort!

eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 20, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
eMBee pushed a commit to eMBee/eventyay-tickets that referenced this pull request May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PostgreSQL and Redis TLS/mTLS support
3 participants