Ruby on Rails applications Security Checklist

Ruby on Rails applications Security Checklist

Summary

This document provides a list of security measures to be implemented when developing a Ruby on Rails application. It is designed to serve as a quick reference and minimize vulnerabilities caused by developer forgetfulness.

Zen Rails Security Checklist

Read Full Document. https://github.com/brunofacca/zen-rails-security-checklist 

 

 

Mac shortcuts

Command(⌘)+space to search and open any application

Command(⌘)+t to open a new chrome tab

Command(⌘)+w to close a chrome tab

Command(⌘)+option(⌥)+arrow(→) to navigate chrome tabs

Command(⌘)+l to jump to chrome search bar

Command(⌘)+option(⌥)+h to hide apps other than the one you’re on

Command(⌘)+h to hide the app you’re on

Control+a to jump to the beginning of the line

Control+k to delete the line after the cursor

How To Install Elasticsearch 1.7 on ubuntu

How To Install Elasticsearch 1.7 on ubuntu

Install Java 8

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java8-installer

Now that Java 8 is installed, let’s install ElasticSearch.

Run the following command to import the Elasticsearch public GPG key into apt:

wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Create the Elasticsearch source list:

echo "deb http://packages.elastic.co/elasticsearch/1.7/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-1.7.list

Update your apt package database:

sudo apt-get update

Install Elasticsearch with this command:

sudo apt-get -y install elasticsearch

Elasticsearch is now installed. Let’s edit the configuration:

sudo vim /etc/elasticsearch/elasticsearch.yml

change
network.host: 192.168.0.1

to

network.host: localhost

Now start Elasticsearch:

sudo service elasticsearch restart

Test it

curl -X GET 'http://localhost:9200'


{
  "status" : 200,
  "name" : "Authority",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.7.5",
    "build_hash" : "00f95f4ffca6de89d68b7ccaf80d148f1f70e4d4",
    "build_timestamp" : "2016-02-02T09:55:30Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

Install mongodb and security setting

Install MongoDB
1 Import the public key used by the package management system.

The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import the MongoDB public GPG Key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

2 Create a list file for MongoDB.

Create the /etc/apt/sources.list.d/mongodb.list list file using the following command:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

3 Reload local package database.

Issue the following command to reload the local package database:

sudo apt-get update

4 Install the MongoDB packages.

You can install either the latest stable version of MongoDB or a specific version of MongoDB.
Install the latest stable version of MongoDB.

Issue the following command:

sudo apt-get install mongodb-org

Deploy Rails 4.2 application with ruby 2.2 and nginx passenger on amazon ec2

Deploy Rails 4.2 application with ruby 2.2 and nginx passenger on amazon ec2

Deploying Rails 4.2 application with nginx + passenger is so easy.

Step 1
Setup EC2 server with ubuntu 14.04
Install ruby 2.2.2 and setup one database like PG etc.
This can be done following this http://railsroot.com/setup_rails

Once all the basic setup is done.
Now install nginx with passenger.
Follow following steps to do it.

you can now install Passenger on Ubuntu with the Advanced Packaging Tool (APT)

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7

Create an APT source file (you will need sudo privileges):

sudo vim /etc/apt/sources.list.d/passenger.list

And insert the following line in the file:

deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main

Update the APT cache:

sudo apt-get update

Finally, install Passenger with Nginx:

sudo apt-get install nginx-extras passenger

Open the Nginx configuration file:

sudo vim /etc/nginx/nginx.conf

Find the following lines, in the http block:

##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/passenger_free_ruby;

Uncomment both of them. Update the path in the passenger_ruby line. They should look like this:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;

We need to disable the default Nginx configuration. Open the Nginx config file:

sudo vim /etc/nginx/sites-available/default

Find the lines:

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

Comment them out, like this:

# listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;

Save the file.

Now, create an Nginx configuration file for your rails app:

sudo vim /etc/nginx/sites-available/appname

Add the following server block. The settings are explained below.

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  server_name www.example.com;
  passenger_enabled on;
  passenger_app_env production;
  root /home/ubuntu/appname/public;
  
  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root /home/ubuntu/appname/public;
  }
}

Create a symlink for it:

sudo ln -s /etc/nginx/sites-available/appname /etc/nginx/sites-enabled/appname

Restart Nginx:

sudo service nginx restart

Now your app’s website should be accessible.

Updating code and assets:

rake assets:precompile RAILS_ENV=production
touch tmp/restart.txt

A Checklist for Personal Efficiency

1. Plan your day in advance.
Don’t just start work. Take 15 minutes to carefully go through what your tasks are, get them all down on paper. Next , decide when you will do each item throughout the day. Only then should you begin your day’s work. Such planning may look like a waste of time, but it usually doubles the speed at which your To Do list gets done.
As Abraham Lincoln said, ” If I had six hours to cut down a tree I’d spend the first four hours sharpening the axe.”

2. Do the most important tasks first.
Let’s face it, these days there is simply not enough time to get all your To Do’s done. So if you don’t do your most crucial jobs first, many days you will find they never get done at all.

3. Rush unimportant tasks.
This is a rarely mentioned technique of efficiency. You can unlock huge amounts of time by rushing jobs that don’t matter much. As Warren Buffettput it, “Whats’ not worth doing is not worth doing well.”

4. Work in uninterrupted blocks.
Interruptions destroy efficiency. The more you can find a quiet place to work uninterrupted on your To Do’s, the more you’ll get done. Consider working two mornings a week at a nearby coffee shop. Or book a meeting room at your office and post a big ‘Do Not Disturb’ sign on the door.

5. Don’t do emails until 11am.
When you start work, glance at your emails for anything truly urgent. (This should take no more than ten minutes). Then forget about email until mid morning. Don’t be one of those people that puts everyone else’s priorities before your own.

6. Pick one key job for the day.
What’s the one task that would help your business the most? Get clear on this, each and every day. If all you did was achieve your single most important task daily, in 3 months your business would be powering. But most people have never identified what their key daily task is.

7. Have a finishing time.
Everyone has a start time, but few have a time they must leave at the end of the day. You’d be amazed how much more efficient you become when you do. When you know there’s a certain time you must finish work, it forces you to work quickly all through the day so you can make the deadline. But when your work day is open ended, there’s no real need to work fast. Remember Parkinson’s Law: “Work expands to fill the time allotted for it.”

So that’s your personal efficiency checklist. Keep it nearby as you work through your day.

If you can stick to this list daily you will find you will radically change how much you achieve. You’ll be able to work less and earn more. Your stress will go down and your confidence will go up.