Skip to content

Commit 44a91cb

Browse files
authored
Merge pull request #483 from azavea/feature/hmc/http-to-https
Add support for redirecting HTTP to HTTPS
2 parents 9a6bea7 + 3ae9b02 commit 44a91cb

File tree

15 files changed

+145
-45
lines changed

15 files changed

+145
-45
lines changed

Vagrantfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ end
3737
# if any dependencies are missing
3838
def install_dependent_roles
3939
ansible_directory = File.join("deployment", "ansible")
40-
ansible_roles_txt = File.join(ansible_directory, "roles.txt")
40+
ansible_roles_spec = File.join(ansible_directory, "roles.yml")
4141

42-
File.foreach(ansible_roles_txt) do |line|
43-
role_name, role_version = line.split(",")
42+
YAML.load_file(ansible_roles_spec).each do |role|
43+
role_name = role["src"]
44+
role_version = role["version"]
4445
role_path = File.join(ansible_directory, "roles", role_name)
4546
galaxy_metadata = galaxy_install_info(role_name)
4647

4748
if galaxy_metadata["version"] != role_version.strip
48-
unless system("ansible-galaxy install -f -r #{ansible_roles_txt} -p #{File.dirname(role_path)}")
49+
unless system("ansible-galaxy install -f -r #{ansible_roles_spec} -p #{File.dirname(role_path)}")
4950
$stderr.puts "\nERROR: An attempt to install Ansible role dependencies failed."
5051
exit(1)
5152
end
@@ -125,7 +126,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
125126
end
126127

127128
# Web
128-
app.vm.network "forwarded_port", guest: 80, host: 8024
129+
app.vm.network "forwarded_port", guest: 443, host: 8024
129130

130131
# Django Dev
131132
app.vm.network "forwarded_port", guest: 8026, host: 8026

deployment/ansible/app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- hosts: app
3-
sudo: True
3+
become: True
44

55
pre_tasks:
66
- name: Update APT cache

deployment/ansible/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- hosts: database
3-
sudo: True
3+
become: True
44

55
pre_tasks:
66
- name: Update APT cache

deployment/ansible/otp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- hosts: otp
3-
sudo: True
3+
become: True
44

55
pre_tasks:
66
- name: Update APT cache

deployment/ansible/roles.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

deployment/ansible/roles.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- src: azavea.git
2+
version: 0.1.0
3+
4+
- src: azavea.java
5+
version: 0.2.6
6+
7+
- src: azavea.opentripplanner
8+
version: 1.0.1
9+
10+
- src: azavea.nginx
11+
version: 0.2.2
12+
13+
- src: azavea.nodejs
14+
version: 0.4.0
15+
16+
- src: azavea.packer
17+
version: 0.2.0
18+
19+
- src: azavea.papertrail
20+
version: 1.1.1
21+
22+
- src: azavea.pip
23+
version: 0.1.1
24+
25+
- src: azavea.python
26+
version: 0.1.0
27+
28+
- src: azavea.virtualenv
29+
version: 0.1.0
30+
31+
- src: azavea.postgresql-support
32+
version: 0.3.0
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
---
22
- name: Clear out the NPM artifacts when in production (want a fresh set)
33
file: path="{{ root_src_dir }}/node_modules" state=absent
4-
sudo: yes
4+
become: yes
55
when: production
66

77
- name: Install NPM dependencies
88
command: npm install chdir="{{ root_src_dir }}"
9-
sudo: no
9+
become: no
1010

1111
- name: Create Static Directory
1212
file: path="{{ root_static_dir }}" state=directory mode=0755 owner="{{ app_username }}"
13-
sudo: yes
13+
become: yes
1414

1515
- name: Install application javascript dependencies with bower
1616
command: npm run bower-install
17-
sudo: no
17+
become: no
1818
args:
1919
chdir: "{{ root_src_dir }}"
2020

2121
- name: Create static files -- development
2222
command: npm run gulp-development
23-
sudo: no
23+
become: no
2424
args:
2525
chdir: "{{ root_src_dir }}"
2626
when: not production and not test
2727

2828
- name: Create static files -- production
2929
command: npm run gulp-production
30-
sudo: no
30+
become: no
3131
args:
3232
chdir: "{{ root_src_dir }}"
3333
when: production or test

deployment/ansible/roles/cac-tripplanner.app/tasks/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
notify: Restart nginx
6868

6969
- name: Touch cron job log file if it does not exist
70-
command: touch {{ app_cron_event_feed_log }}
71-
creates={{ app_cron_event_feed_log }}
70+
copy: content="" dest="{{ app_cron_event_feed_log }}" force=no
7271

7372
- name: Touch cron job log file if it does not exist, and set permissions
7473
file: path={{ app_cron_event_feed_log}} state=touch

deployment/ansible/roles/cac-tripplanner.app/templates/nginx-default.j2

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
1+
# Public VPC subnet CIDRs
2+
set_real_ip_from 10.0.0.0/24;
3+
set_real_ip_from 10.0.2.0/24;
4+
set_real_ip_from 10.0.4.0/24;
5+
set_real_ip_from 10.0.6.0/24;
6+
7+
real_ip_header X-Forwarded-For;
8+
9+
server {
10+
listen 80;
11+
server_name gophillygo.org www.gophillygo.org;
12+
return 301 https://$host$request_uri;
13+
}
14+
15+
map $http_x_forwarded_proto $policy {
16+
default "";
17+
https "default-src https: data: blob: 'unsafe-inline' 'unsafe-eval'";
18+
}
19+
120
server {
2-
listen 80 default_server;
21+
listen 443 default_server;
22+
server_name gophillygo.org www.gophillygo.org localhost;
323

4-
server_name _;
24+
# A set of recommended security headers:
25+
#
26+
# https://scotthelme.co.uk/hardening-your-http-response-headers/
27+
#
28+
add_header Strict-Transport-Security "max-age=15552000; preload" always;
29+
add_header Content-Security-Policy $policy always;
30+
add_header X-Content-Type-Options "nosniff" always;
31+
add_header X-Frame-Options "SAMEORIGIN" always;
32+
add_header X-XSS-Protection "1; mode=block" always;
533

634
location / {
735
proxy_set_header Host $http_host;
8-
proxy_pass http://127.0.0.1:8000;
36+
proxy_set_header X-Forwarded-For $remote_addr;
937
proxy_read_timeout {{ otp_session_timeout_s }}s;
38+
proxy_redirect off;
39+
40+
proxy_pass http://127.0.0.1:8000;
1041
}
1142

1243
location /admin/destinations/destination/add/ {
1344
proxy_set_header Host $http_host;
14-
proxy_pass http://127.0.0.1:8000;
45+
proxy_set_header X-Forwarded-For $remote_addr;
46+
proxy_redirect off;
47+
1548
client_max_body_size 10M;
49+
50+
proxy_pass http://127.0.0.1:8000;
1651
}
1752

1853
location /static/ {

deployment/ansible/roles/cac-tripplanner.database/tasks/main.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
- name: Create postgres database
99
postgresql_db: name={{ postgres_db }}
10-
sudo_user: postgres
10+
become_user: postgres
1111

1212
- name: Create postgres user
1313
postgresql_user: db={{ postgres_db }}
1414
name={{ postgres_user }}
1515
password={{ postgres_password }}
1616
role_attr_flags=SUPERUSER
17-
sudo_user: postgres
17+
become_user: postgres
1818

1919
- name: Add PostGIS extension
20-
sudo_user: postgres
20+
become_user: postgres
2121
command: psql {{ postgres_db }} -c "CREATE EXTENSION postgis"
2222
register: psql_result
2323
failed_when: >
@@ -36,4 +36,3 @@
3636
regexp='host\s+all\s+all\s+(127\.0\.0\.1\/32|0\.0\.0\.0\/0)\s+md5'
3737
line="host all all 0.0.0.0/0 md5"
3838
notify: Restart Postgres
39-

0 commit comments

Comments
 (0)