-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(server): Add ApiUrl + ServerUrl env + allow usage of https #8579
Open
AMoreaux
wants to merge
10
commits into
twentyhq:main
Choose a base branch
from
AMoreaux:feat/allow-to-use-ssl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+305
−37
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
450d137
refactor(core): centralize SERVER_URL logic + allow ssl on server
AMoreaux 398364d
refactor: consolidate ServerUrl and ApiUrl handling
AMoreaux 4fbaaac
refactor: rename serverAndApiUrl to server-and-api-urls
AMoreaux 8a88f40
fix(server-setup): Adjust test hooks and SSL config paths
AMoreaux 886c6f2
test: Adjust WorkspaceInvitationService tests to set ApiUrl
AMoreaux 7ef1c73
[test] Reorder import statements
AMoreaux a933d31
feat(self-hosting): Add API_URL to environment variables
AMoreaux 8b40561
fix(server): enforce protocol in environment URLs
AMoreaux 8cf6502
feat(ssl-generation): Add SSL generation script
AMoreaux 79a8da2
chore(): remove comment
AMoreaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Local SSL Certificate Generation Script | ||
|
||
This Bash script helps generate self-signed SSL certificates for local development. It uses OpenSSL to create a root certificate authority, a domain certificate, and configures them for local usage. | ||
|
||
## Features | ||
- Generates a private key and root certificate. | ||
- Creates a signed certificate for a specified domain. | ||
- Adds the root certificate to the macOS keychain for trusted usage (macOS only). | ||
- Customizable with default values for easier use. | ||
|
||
## Requirements | ||
- OpenSSL | ||
|
||
## Usage | ||
|
||
### Running the Script | ||
|
||
To generate certificates using the default values: | ||
|
||
```sh | ||
./script.sh | ||
``` | ||
|
||
### Specifying Custom Values | ||
|
||
1. **Domain Name**: Specify the domain name for the certificate. Default is `localhost.com`. | ||
2. **Root Certificate Name**: Specify a name for the root certificate. Default is `myRootCertificate`. | ||
3. **Validity Days**: Specify the number of days the certificate is valid for. Default is `825` days. | ||
|
||
#### Examples: | ||
|
||
1. **Using Default Values**: | ||
```sh | ||
./script.sh | ||
``` | ||
|
||
2. **Custom Domain Name**: | ||
```sh | ||
./script.sh example.com | ||
``` | ||
|
||
3. **Custom Domain Name and Root Certificate Name**: | ||
```sh | ||
./script.sh example.com customRootCertificate | ||
``` | ||
|
||
4. **Custom Domain Name, Root Certificate Name, and Validity Days**: | ||
```sh | ||
./script.sh example.com customRootCertificate 1095 | ||
``` | ||
|
||
## Script Details | ||
|
||
1. **Check if OpenSSL is Installed**: Ensures OpenSSL is installed before executing. | ||
2. **Create Directory for Certificates**: Uses `~/certs/{domain}`. | ||
3. **Generate Root Certificate**: Creates a root private key and certificate. | ||
4. **Add Root Certificate to macOS Keychain**: Adds root certificate to macOS trusted store (requires admin privileges). | ||
5. **Generate Domain Key**: Produces a private key for the domain. | ||
6. **Create CSR**: Generates a Certificate Signing Request for the domain. | ||
7. **Generate Signed Certificate**: Signs the domain certificate with the root certificate. | ||
|
||
## Output Files | ||
|
||
The generated files are stored in `~/certs/{domain}`: | ||
|
||
- **Root certificate key**: `{root_cert_name}.key` | ||
- **Root certificate**: `{root_cert_name}.pem` | ||
- **Domain private key**: `{domain}.key` | ||
- **Signed certificate**: `{domain}.crt` | ||
|
||
## Notes | ||
|
||
- If running on non-macOS systems, you'll need to manually add the root certificate to your trusted certificate store. | ||
- Ensure that OpenSSL is installed and available in your PATH. | ||
## License | ||
This script is licensed under the [MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
# Check if OpenSSL is installed | ||
if ! command -v openssl &> /dev/null | ||
then | ||
echo "OpenSSL is not installed. Please install it before running this script." | ||
exit | ||
fi | ||
|
||
# Default values | ||
DOMAIN=${1:-localhost.com} | ||
ROOT_CERT_NAME=${2:-myRootCertificate} | ||
VALIDITY_DAYS=${3:-825} # Default is 825 days | ||
|
||
CERTS_DIR=~/certs/$DOMAIN | ||
|
||
# Create a directory to store the certificates | ||
mkdir -p $CERTS_DIR | ||
cd $CERTS_DIR | ||
|
||
# Generate the private key for the Certificate Authority (CA) | ||
openssl genrsa -des3 -out ${ROOT_CERT_NAME}.key 2048 | ||
|
||
# Generate the root certificate for the CA | ||
openssl req -x509 -new -nodes -key ${ROOT_CERT_NAME}.key -sha256 -days $VALIDITY_DAYS -out ${ROOT_CERT_NAME}.pem \ | ||
-subj "/C=US/ST=State/L=City/O=MyOrg/OU=MyUnit/CN=MyLocalCA" | ||
|
||
# Add the root certificate to the macOS keychain (requires admin password) | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" ${ROOT_CERT_NAME}.pem | ||
fi | ||
|
||
# Generate the private key for the provided domain | ||
openssl genrsa -out $DOMAIN.key 2048 | ||
|
||
# Create a Certificate Signing Request (CSR) for the provided domain | ||
openssl req -new -key $DOMAIN.key -out $DOMAIN.csr \ | ||
-subj "/C=US/ST=State/L=City/O=MyOrg/OU=MyUnit/CN=*.$DOMAIN" | ||
|
||
# Create a configuration file for certificate extensions | ||
cat > $DOMAIN.ext << EOF | ||
authorityKeyIdentifier=keyid,issuer | ||
basicConstraints=CA:FALSE | ||
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = $DOMAIN | ||
DNS.2 = *.$DOMAIN | ||
EOF | ||
|
||
# Sign the certificate with the CA | ||
openssl x509 -req -in $DOMAIN.csr -CA ${ROOT_CERT_NAME}.pem -CAkey ${ROOT_CERT_NAME}.key -CAcreateserial \ | ||
-out $DOMAIN.crt -days $VALIDITY_DAYS -sha256 -extfile $DOMAIN.ext | ||
|
||
echo "Certificates generated in the directory $CERTS_DIR:" | ||
echo "- Root certificate: ${ROOT_CERT_NAME}.pem" | ||
echo "- Domain private key: $DOMAIN.key" | ||
echo "- Signed certificate: $DOMAIN.crt" | ||
|
||
# Tips for usage | ||
echo "To use these certificates with a local server, configure your server to use $DOMAIN.crt and $DOMAIN.key." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
add TODO + Deprecate flag