Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Feature/per app access #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project makes use of the [Sementic Versioning](http://semver.org/)

### Added
- Set the max db `pool` size via an ENV var called `DB_POOL_SIZE`
- Ability to define per-app IP-address white and blacklists that may access the app.

## 2.5.0 - 2015-04-30

Expand Down
11 changes: 11 additions & 0 deletions vendor/cookbooks/rails/libraries/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ def nginx_custom_configuration(app_info)

empty_conf.merge(app_info["nginx_custom"] || {})
end

##
# Create a rendered set of access and deny rules for nginx conf.
# Ensures we always have a string to render.
def nginx_access(app_info)
# Ensure we always have a hash, and dup to make it writable
access = app_info.fetch("access", {}).dup
access["allowed"] ||= []
access["denied"] ||= []
access
end
end
end
2 changes: 1 addition & 1 deletion vendor/cookbooks/rails/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license "MIT"
description "Installs/Configures rails"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.3.1"
version "0.4.1"
depends "rbenv", "~> 1.7.1"
depends "sudo", "> 1.2.0"
depends "database"
Expand Down
3 changes: 2 additions & 1 deletion vendor/cookbooks/rails/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
redirect_domain_names: app_info["redirect_domain_names"],
client_max_body_size: app_info["client_max_body_size"],
enable_ssl: File.exists?("#{applications_root}/#{app}/shared/config/certificate.crt"),
custom_configuration: nginx_custom_configuration(app_info))
custom_configuration: nginx_custom_configuration(app_info),
access: nginx_access(app_info))
notifies :reload, resources(service: "nginx")
end

Expand Down
3 changes: 2 additions & 1 deletion vendor/cookbooks/rails/recipes/passenger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
redirect_domain_names: app_info["redirect_domain_names"],
client_max_body_size: app_info["client_max_body_size"],
enable_ssl: enable_ssl,
custom_configuration: nginx_custom_configuration(app_info))
custom_configuration: nginx_custom_configuration(app_info),
access: nginx_access(app_info))
notifies :reload, resources(:service => "nginx")
end

Expand Down
2 changes: 2 additions & 0 deletions vendor/cookbooks/rails/templates/default/app_nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ server {
proxy_pass http://<%= @name %>;
<%= @custom_configuration["server_app"] %>
}
<%= render 'nginx/access.erb', variables: { access: @access } %>
<%= @custom_configuration["server_main"] %>
}

Expand Down Expand Up @@ -54,6 +55,7 @@ server {
proxy_pass http://<%= @name %>;
<%= @custom_configuration["ssl_app"] %>
}
<%= render 'nginx/access.erb', variables: { access: @access } %>
<%= @custom_configuration["ssl_main"] %>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ server {
passenger_app_env <%= @rails_env %>;

<%= "client_max_body_size #{@client_max_body_size};" if @client_max_body_size.to_i != 0 %>

<%= render 'nginx/access.erb', variables: { access: @access } %>
<%= @custom_configuration["server_main"] %>
}

Expand All @@ -54,8 +54,8 @@ server {
<%= "client_max_body_size #{@client_max_body_size};" if @client_max_body_size.to_i != 0 %>

server_name <%= @domain_names.join(' ') %>;

root <%= node['rails']['applications_root'] %>/<%= @name %>/current/public;
<%= render 'nginx/access.erb', variables: { access: @access } %>
<%= @custom_configuration["ssl_main"] %>
}

Expand Down
9 changes: 9 additions & 0 deletions vendor/cookbooks/rails/templates/default/nginx/access.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% @access["denied"].each do |denied_address| %>
deny <%= denied_address %>;
<% end %>
<% @access["allowed"].each do |allowed_address| %>
allow <%= allowed_address %>;
<% end %>
<% if @access["allowed"].any? %>
deny all;
<% end %>