-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds makecerts: creates ssl certs for the app, nginx (static) and loc…
…alstack
- Loading branch information
Showing
8 changed files
with
232 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
.env | ||
.in | ||
.localstack/ | ||
package-lock.json | ||
node_modules/* | ||
|
||
|
||
# Ignore the build directory | ||
|
||
|
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,76 @@ | ||
|
||
|
||
## Development | ||
|
||
|
||
### Additional repositories | ||
|
||
[fablib](https://github.com/NUKnightLab/fablib) and the | ||
[knightlab cdn](https://github.com/NUKnightLab/cdn.knightlab.com) should be | ||
co-resident with this repository: | ||
|
||
``` | ||
$ cd .. | ||
$ git clone [email protected]:NUKnightLab/fablib.git | ||
$ git clone [email protected]:NUKnightLab/cdn.knightlab.com.git | ||
``` | ||
|
||
### Install less | ||
|
||
``` | ||
$ npm install -g npm | ||
$ npm install less -g | ||
$ npm install uglify-js -g | ||
``` | ||
|
||
### Build the static media | ||
|
||
Build static to the build directory: | ||
|
||
``` | ||
$ fab build | ||
``` | ||
|
||
- **or** - | ||
|
||
Build static and copy files to the dev location in the cdn repository: | ||
|
||
``` | ||
$ fab stage_dev | ||
``` | ||
|
||
Static files are hosted via an Nginx container from the build directory. See | ||
the compose file for details. | ||
|
||
### Setup ssl | ||
|
||
``` | ||
$ ./makecerts.sh | ||
``` | ||
|
||
Set SSL cert trust: | ||
|
||
#### Firefox: | ||
|
||
* Preferences > Certificates | ||
* View certificates | ||
* Import: .localstack/KnightLabRoot.pem | ||
|
||
#### Chrome (Mac): | ||
|
||
Add the cert to keychain: | ||
|
||
* File > Import items ... | ||
* .localstack/server.test.pem | ||
* set trust SSL | ||
|
||
|
||
For building static media, you will need a Python2 virtualenvironment with the | ||
dependencies in `requirements.p2.txt` installed. See the fablib repo for static | ||
build details. | ||
|
||
### Run the stack | ||
|
||
``` | ||
$ docker-compose up | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
server { | ||
listen 80 default_server; | ||
listen [::]:80 default_server; | ||
return 301 https://$server_name$request_uri; | ||
} | ||
|
||
server { | ||
listen 443 ssl; | ||
|
||
server_name ~.; | ||
|
||
ssl_certificate /etc/nginx/conf.d/server.crt; | ||
ssl_certificate_key /etc/nginx/conf.d/server.key; | ||
|
||
#location / { | ||
# add_header 'Access-Control-Allow-Origin' $http_origin; | ||
# add_header 'Access-Control-Allow-Credentials' 'true'; | ||
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | ||
# add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; | ||
# root /var/www; | ||
#} | ||
|
||
# | ||
# Wide-open CORS config for nginx | ||
# https://enable-cors.org/server_nginx.html | ||
# | ||
location / { | ||
if ($request_method = 'OPTIONS') { | ||
add_header 'Access-Control-Allow-Origin' $host; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | ||
# | ||
# Custom headers and headers various browsers *should* be OK with but aren't | ||
# | ||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | ||
# | ||
# Tell client that this pre-flight info is valid for 20 days | ||
# | ||
add_header 'Access-Control-Max-Age' 1728000; | ||
add_header 'Content-Type' 'text/plain; charset=utf-8'; | ||
add_header 'Content-Length' 0; | ||
return 204; | ||
} | ||
if ($request_method = 'POST') { | ||
add_header 'Access-Control-Allow-Origin' $host; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | ||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | ||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | ||
} | ||
if ($request_method = 'GET') { | ||
add_header 'Access-Control-Allow-Origin' $host; | ||
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | ||
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | ||
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | ||
} | ||
root /var/www; | ||
} | ||
|
||
## If the static server was another docker service, | ||
## It is possible to forward requests to its port: | ||
# location / { | ||
# proxy_set_header Host $host; | ||
# proxy_set_header X-Real-IP $remote_addr; | ||
# proxy_pass http://web:3000/; | ||
# } | ||
} | ||
|
||
|
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,6 @@ | ||
authorityKeyIdentifier=keyid,issuer | ||
basicConstraints=CA:FALSE | ||
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = localhost |
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
# Adapted from: | ||
# https://gist.github.com/cecilemuller/9492b848eb8fe46d462abeb26656c4f8 | ||
|
||
CERTDIR=.localstack | ||
CA=KnightLabRootCA | ||
FN=server.test.pem | ||
STATE=Illinois | ||
CITY=Evanston | ||
COUNTRY=US | ||
ORG=KnightLab | ||
COMMON_NAME=localhost.storymap | ||
|
||
mkdir -p .localstack | ||
|
||
if [[ -f $CERTDIR/$FN | ||
|| -f $CERTDIR/$FN.crt | ||
|| -f $CERTDIR/$FN.key | ||
|| -f $CERTDIR/$CA.crt | ||
|| -f $CERTDIR/$CA.key | ||
|| -f $CERTDIR/$CA.pem | ||
|| -f $CERTDIR/$CA.srl | ||
]]; then | ||
echo "Please delete existing cert files to run this script.\n\nTo delete, execute: rm $CERTDIR/$FN*; rm $CERTDIR/$CA.*" | ||
exit 1 | ||
fi | ||
|
||
# Generate CA | ||
|
||
|
||
openssl req \ | ||
-x509 \ | ||
-nodes \ | ||
-new \ | ||
-sha256 \ | ||
-days 1024 \ | ||
-newkey rsa:2048 \ | ||
-keyout $CERTDIR/$CA.key \ | ||
-out $CERTDIR/$CA.pem \ | ||
-subj "/C=$COUNTRY/CN=$CA" | ||
|
||
openssl x509 -outform pem -in $CERTDIR/$CA.pem -out $CERTDIR/$CA.crt | ||
|
||
# Generate domain name cert | ||
|
||
|
||
openssl req \ | ||
-new \ | ||
-nodes \ | ||
-newkey rsa:2048 \ | ||
-keyout $CERTDIR/$FN.key \ | ||
-out $CERTDIR/$FN.csr \ | ||
-subj "/C=$COUNTRY/ST=$STATE/L=$CITY/O=$ORG/CN=$COMMON_NAME" | ||
|
||
openssl x509 \ | ||
-req \ | ||
-sha256 \ | ||
-days 1024 \ | ||
-in $CERTDIR/$FN.csr \ | ||
-CA $CERTDIR/$CA.pem \ | ||
-CAkey $CERTDIR/$CA.key \ | ||
-CAcreateserial \ | ||
-extfile localhost/domains.ext \ | ||
-out $CERTDIR/$FN.crt | ||
|
||
cat $CERTDIR/$FN.key $CERTDIR/$FN.crt > $CERTDIR/$FN | ||
|
||
echo "Trust cert. E.g.: Apple Keychain > System. File > Import items: $CERTDIR/$FN\n\nSet to trust SSL." | ||
echo "\nFor Firefox: Preferences > Certificates > View Certificates > Import $CERTDIR/$FN." |