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

feat(server): allow to use ssl on server #8722

Merged
merged 14 commits into from
Nov 26, 2024
Merged

feat(server): allow to use ssl on server #8722

merged 14 commits into from
Nov 26, 2024

Conversation

AMoreaux
Copy link
Contributor

No description provided.

Replaced individual environment-based server URL retrievals with a centralized ServerUrl utility. This change simplifies URL management and ensures a consistent approach across different services. Added validation for SSL configurations when using HTTPS.
Removed standalone ServerUrl and integrated with combined ServerUrl/ApiUrl module. Refactored codebase to use ApiUrl for public network accessibility and adjusted corresponding imports.
Renamed utils file for better readability and consistency. Updated all references to the new file name and added unit tests for ServerUrl and ApiUrl functionalities.
Move the reset of ServerUrl and ApiUrl to beforeEach in tests to ensure clean state before each test runs. Update example SSL_KEY_PATH and SSL_CERT_PATH to use relative paths for more portability.
Import the ApiUrl module and set the local URL in the setup function. This ensures the tests have the correct API endpoint configured.
Reordered import statements in `workspace-invitation.service.spec.ts` for improved code organization. This change ensures that dependencies are imported in a more logical sequence.
Included API_URL in self-hosting documentation for public endpoint configuration. This helps developers set up the correct URLs for API interactions in their self-hosted environments.
Removed protocol check logic from main.ts and enforced URL validation to require protocol directly in environment variables definition. This ensures consistent and secure URL formats throughout the application.
Add a new Bash script for generating self-signed SSL certificates, including a README with instructions. Supports customizable domain, root certificate name, and validity period, and integrates root certificate into macOS keychain.
Deleted the now-redundant server-and-api-urls utility and its tests. Replaced all references with `environmentService.get('SERVER_URL')` to simplify the configuration management.
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR adds SSL/HTTPS support to the Twenty server through self-signed certificates, including environment configuration and a certificate generation script.

  • Added SSL certificate generation script scripts/ssl-generation/script.sh with macOS keychain integration and 825-day validity period
  • New environment variables SSL_KEY_PATH and SSL_CERT_PATH in .env.example for configuring HTTPS server
  • Modified main.ts to enable HTTPS when SSL paths are provided in environment variables
  • Improved URL handling in SSO service using URL class for proper protocol support
  • Security consideration: Script stores sensitive keys in home directory and requires sudo access for macOS keychain

6 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile

packages/twenty-server/.env.example Show resolved Hide resolved
packages/twenty-server/scripts/ssl-generation/README.md Outdated Show resolved Hide resolved
packages/twenty-server/scripts/ssl-generation/README.md Outdated Show resolved Hide resolved
cd $CERTS_DIR

# Generate the private key for the Certificate Authority (CA)
openssl genrsa -des3 -out ${ROOT_CERT_NAME}.key 2048
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: -des3 is deprecated and considered insecure. Use -aes256 instead for the root CA key encryption.

packages/twenty-server/src/main.ts Show resolved Hide resolved
packages/twenty-server/src/main.ts Outdated Show resolved Hide resolved
packages/twenty-server/src/main.ts Show resolved Hide resolved
Eliminated redundant FRONT_AUTH_CALLBACK_URL environment variable from auth controller, environment variables, and documentation. Updated error handling to directly redirect to the verification page.
Cleaned up the main.ts file by removing the unused server URL configuration logic. Updated SSL generation script and documentation to change certificate validity days to 398 and switched to aes256 for key generation.
Changed default SERVER_URL from 'http://localhost' to 'http://localhost:3000'. This ensures the server runs on port 3000 by default for better compatibility with existing setups.
@AMoreaux AMoreaux enabled auto-merge (squash) November 26, 2024 15:23
@AMoreaux AMoreaux enabled auto-merge (squash) November 26, 2024 15:23
@AMoreaux AMoreaux merged commit eb39288 into main Nov 26, 2024
19 checks passed
@AMoreaux AMoreaux deleted the feat/allow-to-use-ssl branch November 26, 2024 15:30
Copy link

Thanks @AMoreaux for your contribution!
This marks your 10th PR on the repo. You're top 3% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants