Wednesday, May 4, 2016

Ruby on Rails PHP and Node.js Applications Accepting Image Uploads Vulnerable to Remote Code Execution Through ImageMagick

If your project accepts image uploads, your application could be at risk.

A new vulnerability affecting the image conversion package ImageMagick, has been reported that would allow attackers to upload malicious image files capable of executing code on your server.

ImageMagick is a system level package for image manipulation that is highly utilized by web applications based on node.js, ruby on rails, and php. Bottom line, if your application accepts image uploads, there is a very good chance it relies on ImageMagick and is vulnerable.

This link outlines the steps you should be taking to mitigate the possibility of being affected. If you or your team needs help addressing this please contact me.

Friday, April 29, 2016

Upgrade your SSH experience with Mosh

I am a remote developer who relies on SSH to wrangler code and servers.

On top of this, part of my day is spent from a secure off-the-grid location where it's a pure miracle high speed wireless internet exists. With this miracle comes the reality of latency. Typical ssh latency over wimax in my location is about 400-500ms. Not unbearable, but it is not the same as having a wired connection.

Enter mosh. Mosh is an ssh replacement, more robust and responsive especially over Wi-Fi, cellular, and long-distance links.

I installed from git, and as advertised, it just worked. In fact, since it issues the ssh command, if you are using a *nix based system, your configured ssh connection alias will also work.

Happy moshing!

Monday, October 5, 2015

Configuring Devcamps to run multiple Apache or NGINX instances

Here is a solution for enabling Devcamps to run your apps using separate instances of Apache2.

Out of the box, Devcamps does not configure our Apache2 setup.

It's nice to go from running mkcamp to viewing a live version of the app on the camp port without running any additional setup scripts.

I knew running multiple apache2 instances was possible. Googling some brought me to run this in my terminal:

cat /usr/share/doc/apache2/README.multiple-instances

The key take away is this:

The basic idea is to copy /etc/apache2 to /etc/apache2-xxx.

Since our 'camp type' directory [camp_type]/etc gets copied down to our camp directories on running mkcamp, we can copy the /etc/apache2 directory to our [camp_type]/etc directory and modify the appropriate Apache config files with our camp tokens. The 'magic' happens when we change httpd_command_path value in local-config to:

httpd_cmd_path:sudo cp __CAMP_PATH__/apache2-camp/apache2ctl __CAMP_PATH__/apache2-camp/apache2ctl-camp__CAMP_NUMBER__ && sudo __CAMP_PATH__/apache2-camp/apache2ctl-camp__CAMP_NUMBER__

This will allow us start the apache2 binary on separate processes for each camp.

The apache config files I tokenize are as follows:

apache2-camp/apache2ctl
apache2-camp/apache2.conf
apache2-camp/ports.conf
apache2-camp/envvars
apache2-camp/sites-enabled/site.conf

Update: 12/04/2015

The above code works. However, we don't want to run our web servers as root. There is a better way and it's baked into devcamps. The copy-paths.yml file lets us include the camp tokens in the paths with the 'parse_target' options.

source: /usr/bin/apache2ctl
target: apache2-camp/apache2ctl-__CAMP_NUMBER__
always: 1
parse_target: 1

Happy camping!

Friday, September 25, 2015

Create Value From Technical Difficulties

Like a fine tuned engine, great software development runs when there's minimal technical difficulties.

Let's refer to these technical difficulties as "FRICTION$". Like real friction they heat EVERYONE up and in the end they are costing us money and time.

It isn't uncommon that a developer could spend anywhere between 1 and 5 hours per week working on FRICTIONS$ of environment configuration. If you have a 4 person dev team you could be looking at 16-80 hours lost to friction in critical months across the team.

How many man-hours are you spending per month in configuration? Per developer? Per year?

By the end of this article you will know how to spot some FRICTION$ in your project and I will share with you a skill to turn FRICTION$ into value

Project stakeholders in a make or break position can quickly feel the burn on their checkbooks and calendars when projects begin requiring more complex environments. Coordinating upgrades with all engineers can become a large point of FRICTION$

Upgrades, integration of new modules and services, boots and reboots are naturally part of the creative process, and reaching stable environments quicker is the oil that increases your teams velocity. Here are some external FRICTION$ that we end up paying for if we work in traditional offices or in remote teams.

Human condition + Murphy's Law
What's the cost to your project if a laptop is stolen or has a virus? Flood? Battery failure? Lost power cord? Chewed power cord? What if a developer has worked on your project across multiple computers?

Did you know you can mitigate the risks of problems on a developer's computer effecting their ability to complete work on your product?

Is it costing you time when your engineers need to take the time to install development tools when they get Apple's newest Mac Book Pro or they need to dig out an older system because of a system failure or even worse, theft.

OS SHOWDOWN, Fragmentation, BYOD
For many start-ups, we want to stay LEAN and operate at a fast velocity. We find talent with different diversity and with that will come stakeholders who prefer or have requirements of different technologies, operating systems, system specs and in the Glory of the Chaos we must all collaborate and build something awesome, yesterday on our virtual islands and reconnect them the mother-ship for take-off.

Don't miss the rocket - Let me help you empower your team to drive your ship.

Even more burning questions. (Yes that is a large LION in the room)
How secure are the systems of your remote developers? How exposed is your data or your clients data?

Take a few breaths. There is hope. I started sleeping a lot better at night after I made one simple change as a developer.

This is a change that could save your project up to 200 hours per year. Now before I tell you the change that helped me wrangle the beast I want you to think about where you project could use another 200 hours of development. Got it? Good.

Coming through on my promise, the simple change I made that has helped reduce FRICTIION$:

I started developing and collaborating with teams on a remote development system. No development work took place on my actual computer. It all happens on an AWS instance. This all hands on deck approach has turned repetitive apples and oranges configuration, and "island life" into unified development work that creates product value. The tools that make this possible go by the names of Vagrant, Docker, github and Devcamps.

Please leave a comment below if FRICTION$ are costing your project time and money and you want to reclaim 200 man-hours. Developers, how do you combat FRICTION$?

Wednesday, September 23, 2015

The Future of Wireless Internet in Costa Rica

Clients always want to know about my internet connection in Costa Rica

Until recently, using the internet was a challenge I have had pretty much every day for the past 8 years.

It wasn't till this last month when my service provider Japi delivered a flat-line signal to my off-the-grid office for the last 30 days that I had to start the search again on backup solutions.

I did an exhaustive search talking to every company providing WiWax to Microwave (Point-to-Point) services about what could be done to get service here, including the possibilities of installing towers.

The ultimate solution was to rent an office in town for about $200 per month including internet expenses and to fix the problem up here at the off-the-grid office permanently.

Here is what I found and would recommend.

GET READY FOR IT!!!!

Wait till 2016!

Yesterday I spoke with Alberto Araya regarding cell signal boosters and he told me that in 2016 affordable internet in off-the-grid locations problem will be possible. I confirmed what he told me. There are two scheduled satellite launches for late 2015 (Eutelsat 117W B) and mid 2016 (Via-Sat 2) that will bring the same technology used in "in-flight" internet service to the Central America region of the world. It will probably come in a package in this form: Tooway or may be sold by other national carriers. This isn't any ordinary satellite internet. We're talking 5Mb uplink! 22Mb downlink.

In the mean time you might need to test/try different carriers and boosting their signals. Under the "about your phone" menu on your phone there's a menu that shows signal strength (-60dbm to -110dbm). A strong and steady signal keeps your connection strong is on the -60dbm side. As the number increases and gets around -100dbm your signal degrades and calls are dropped. There's also an app called Antenna Point that should point you in the direction of the tower you are connected to.

My past weekend was spent walking around my place and taking measurements at places I noticed signal. I found I could get 3G internet at most places from Kolbi and Movistar. The hill up there getting a steady -77dbm to -83dbm. The house getting about a -90dbm. The Antenna Pointer program helped a lot too because it showed me I was actually on a different tower and that different carriers needed slightly different angles.

I will be having Alberto boost my signal. He's in Ciudad Colon and will sell the equipment or install.

It could give a nice improvement to the signals that arrives here so there is better backup in the home office in case Japi is down.

Like a pilgrim, waiting for latest ship from GB I wait eagerly for news of the satellite launches!

Thursday, September 25, 2014

Monday, May 12, 2014

Diarrhea Cure

Healthy software development starts with healthy mind and body.

Here is my cure for diarrhea.

Ingredients:
1 handful Guarilama
5 teabags of chamomile tea (te de manzanillo)
5 ripe guava
4 tablespoons linseed (semilla de linaza)
2 liters of water

Preparation:
1. Bring 2L of water to boil with the Guarilama, chamomile tea, and guava.
2. Turn off heat and mix in the linseed.
3. Let sit for about 5 minutes.
4. Chill.

Serve chilled and drink 2-3 8oz glasses per day. Symptoms should improve within a few hours of the first glass.

Thursday, March 20, 2014

4 Quick ProTips for New Ruby on Rails Programmers and Managers

I'm writing these four tips for programmers and managers who are starting to work professionally on projects using the Ruby on Rails development framework. These tips are helpful in fine tuning your understanding, and productivity on the apps you are working on. Bottom line, your team mates and project managers will be happy you have these things under control.

  1. "Read the code"

    Often, our expectations mislead us and the code that we or others have written produces different outcomes. The first reaction might be to ask other team members for help. The next time you hit this, first ask yourself, "Did you read the code?" Did you read it all? Did you go to the next file in the stack-trace? Did you dig into dependent gem's code? You see new methods or syntax you don't understand? Keep reading! The solution is in the code!

  2. rake routes

    Are you curious about a path in the app that you need to hook up client-side code to? The Rails stack along with rake has a slick command that breaks down all the paths that the app handles. Simply run: rake routes
    Does the app have tons and tons of routes? Pipe the output through grep to search for the keyword you are looking for: rake routes | grep 'resource_name'

  3. Speed up your Rails Environment

    The faster your environment, the faster you can deliver value on your projects. Rails apps grow, and loading dependencies takes time. Constantly look for ways work around these known obstacles and you will find you can quickly iterate on your rails app confidently. For many years I found myself waiting for test runs, console restarts, rake tasks, etc. I recently started using a tool (zeus) to eliminate these wait times. Make sure you and your team aren't wasting time.

  4. Write integration and unit tests

    Without evidence of a fully integrated system, you have no control of your app. This lack of control quickly will be seen in uncontrollable errors, costs, and expectations. Do your team a favor and demand any code commit for feature or bug fix go in with passing unit and integration tests. But we aren't just writing test code for clients, we're writing them for other programmers too! I currently prefer using rspec for unit tests and cucumber with capybara for integration specs where browser interaction is required.

Friday, November 8, 2013

Move terminal cursor to front of prompt while attached to GNU Screen

Moving your cursor to the front of a terminal prompt will save you time and frustration. To move your cursor to the front of the terminal prompt in a bash shell session simply use the key binding

C - a

Since it is common that C - a is the key binding for GNU Screen, you have to use:

C - a - a

The other option is to bind it to a key for your shell. In bash, add this line to ~/.bashrc

bind '"\C-p": beginning-of-line'

Then

source ~/.bashrc

Now you can nail that cursor home anywhere with:

C - p

This is the two-step of terminal prompt dance moves. Learn it.

Thursday, October 17, 2013

An overview of pub/sub in the Ruby on Rails ecosystem

It’s not AJAX, it’s PUB/SUB

The following will look at the basics of pub-sub and review a number of pub-sub solutions for ruby/rails apps.

For many web apps, we want to notify our users about activity within their network. This is broken down into two steps 1) knowing when there’s a notification and 2) displaying it.

With AJAX, we can send asynchronous requests to check app endpoints for updates, but this means lots of requests.

It’s 2013 and the new way to address this challenge is called pub-sub. There’s a publisher (publishing notifications) and our users, once online, become subscribers to the publications.

The means the messages are pushed instead of pulled.

The transfer of these pushed notifications commonly utilize either Websockets or the Server Sent Event (SSE) methods to push data to the clients.

The websocket protocol is established over http or https, using an upgrade handshake request from the client to the server. If properly validated, a full-duplex data transfer is initialized between the client and server on the ws or wss protocol. As of Thursday October 17, 2013 all the latest browsers except Android browser support the latest specification (RFC 6455) of the WebSocket protocol.

Server Side Events are part of the HTML5 EventSource API. The browser is set up listen for text/event_stream server responses. They are not currently supported for IE.

It's important to understand what Websockets and SSE are so you can make the right decision for which technology you want to integrate into your production stack, and to understand the limitations of each.

What tools are available to do pub-sub in your rails app? Here are a few options...

Pusher.com

Pusher is a commercial service that handles all websocket interaction and exposes an API for publishing to subscribers.

Pros:

-Should work out of the box making it fast to integrate, and offer the same basic features we'd get from Faye
-Rails 3 compatible

Cons:

-Seems like the android browser is out of the picture since it's websockets backed.
-Connections limited based on your service plan
-Not Free

Rails

Rails 4 offers the ActionController::Live mixin to do SSE.

Pros:
-No additional gems needed

Cons:
-No IE support

For Rails 3 Aleksey Magusev shows a dead simple implementation which seems to work in Rails 3. A simple response object sent to establish and feed the SSE stream, and it's handled by an instance of the EventSource class in the HTML5 compliant browsers. In a load-balanced server environment, this solution might not be enough since connections could be left open.

Faye

Faye, has been around for a while (2009) and recently hit v1.0. It is an implementation of the Bayeux protocol over websockets (supported by faye-websocket) and uses an in-memory or redis engine for storage and message semantics. Enabling redis supports load-balanced (distributed) servers. It utilizes it's own websocket impmentation faye-websocket - https://github.com/faye/faye-websocket-ruby and a redis client - faye-redis - https://github.com/faye/faye-redis-ruby.

Pros
-Actively maintained, mature project
-Can push messages for Chats and more
-Can be used across multiple devices
-Solid candidate for a production pub-sub platform

Cons
-Comprehensive configuration options might be overkill
-Requires configuring redis

Closing Thoughts

True pub/sub means turning on websockets or SSE. The faye platform offers a complete solution for production systems, with fine tune-able configurations for single direction and bi-directional streams. If you are looking to extensively use pub/sub in your app, it’s worth taking the time to intrgrate faye. For quick streams, the rails solution offers less strings attached approach.

Tuesday, April 9, 2013

Full Stack Developer Retires MacBookPro for Ubuntu Laptop

Since I began developing with open source technologies in 2007, my computer of choice was the MacBookPro (MBP).

The MBP continues to be a great system for developing open source software, but at this time, when I started looking for my next development workstation, speed, service and value were the leading factors, and it made more sense to stop working with the MBP and start working on a laptop that doesn't glow Apple.

I will miss the MBP's glowing keyboard, and I will miss the magnetic click of the power adapter. However, I will not miss needing to drop $80 for a new adapter after my daughter decides to suck on it like a chew toy.

AppleCare is a fantastic service plan that I have utilized to keep the MBP in tip-tip shape in the USA and Costa Rica. Now, I'm living too far away from an Apple Store to get a F'ed system in the hands of a "Genius." My town has a sharp computing community and would not have a hard time serving any issues on a generic system.

The features I wanted in my new system were a Solid State Hard Drive for fast disk read/writes, and a monster dose of RAM (16 Gig). The MBP with retina display offered these features, for a hefty price. Adding the AppleCare support plan gave me pretty expensive system that I would need to dump in three years when the warranty expired.

I've learned the lessons on servicing computers in Costa Rica and know the risk of carrying around a $2K system. It's time for something new.

I'm empowering myself to continue the journey in open source software and Linux operating systems. The seven years that I have been working with Linux hosting environments has given me the chance to learn how to be productive in the Linux environment. I am excited to add to that knowledge and offer clients more "full-stack" skills. Developing on a Mac and managing production environments are two different animals. Bringing the practices of maintaining secure production systems back to the workstation is clearly the new win-win to work towards.

Sunday, January 13, 2013

Dreamhost Server Blocking Emails From Getting Sent

For anyone who has a rails project hosted on Dreamhost that sends emails this might affect you. Some time recently Dreamhost updated their security setting for sending mail through their SMTP servers and now require plain authentication to send mail through your localhost.

If your error log looks like this, you definitely need to make sure you are getting authenticated to send email.

Dec 28 17:51:16 servernuts postfix/smtpd[57430]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 554 5.7.1 : Recipient address rejected: Access denied;
In your rails app environment files you can enable authentication:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "localhost",
:port => 587,
:domain => 'foobar.com',
:user_name => '',
:password => '',
:authentication => 'plain',
:enable_starttls_auto => true }

I am not a fan of this update since one would have to put their shell account credentials in a codebase. This is a good reason to check out something like postmarkapp or sendgrid.

Saturday, January 12, 2013

Problem Solving: Thread a 1/2 in. tube

Problem solving is an art. Here's a problem I recently faced outside of the software engineering space, but I felt it was worth posting here.

The problem: Running copper wire through 90 meters of 1/2 tubing

Background: I decided it was time to extend my electricity line to a structure about 60 meters from the source. With 120 meters of copper wire in hand I set off on the challenge. To protect from weather, I wanted to make sure the wire is insulated in a plastic tube. It became apparent rather quickly that the cable wasn't going to walk itself through the tube.

The solution: +1 to my neighbor who happened to be walking by and gave the suggestion that ultimately did the trick.

Materials:
100 meters of fishing line
Small piece of foam that with a little squeezing will fit in the 1/2 in tube
100 meters of all purpose twine
Water source (hose will work)
Sharp piercing object that will pierce tube

  1. Start off by unraveling the tubing
  2. With your piercing object, make a small hole about 2 inches from the high end of the tube. My hole was small enough to pass the fishing line through, but small enough that a pencil wouldn't enter
  3. Put the tip of the fishing line through this hole and pull it out the closest end of the tube
  4. Tie off the sponge
  5. Push the sponge towards the low and end apply water source
  6. Watch the fishing line get pulled into the tube with the sponge fighting the force of the water
  7. Your sponge will eventually come our of the other end of the tube and you can tie off the fishing line the the all purpose twine and feed the twine through the tube by pulling on the fishing line that the water fed down the line. I had to run the twine because my fishing line was pretty light weight and probably would snap if the copper wires were tied off to the line
  8. With the twine capable of resisting more force, tie it off of the copper cables and pull the suckers through.

    ----------------------------
A     .                            B
    ----------------------------

Monday, January 7, 2013

Suppress RestClient gem Exceptions

This is a little rant on how the RestClient gem handles 400 'bad request' responses. I often use RestClient to handle calls to third-party APIs. I recently hit a use case that had me a little stumped.

I was working on a task that required me to hit a few endpoints on the plivo.com API. No biggie. I set up a RestClient post like normal and expected to get a response back.

ruby-1.9.3-p194 :023 > cp = {"to"=>"121212121212", "from"=>"12121212121212", "answer_url"=>"http://example.com/AnswerUrl", "answer_method"=>"GET", "hangup_url"=>"http://example.com/HanguUrl", "time_limit"=>10}
 => {"to"=>"121212121212", "from"=>"12121212121212", "answer_url"=>"http://example.com/AnswerUrl", "answer_method"=>"GET", "hangup_url"=>"http://example.com/HanguUrl", "time_limit"=>10} 
ruby-1.9.3-p194 :024 > call = RestClient::Resource.new("https://api.plivo.com/v1/Account/XXXXXXXXXX", "XXXXXXXXX", "XXXXXXXXXXXX")
 => https://api.plivo.com/v1/Account/XXXXXXXXXXX
ruby-1.9.3-p194 :025 > r = call["/Call/"].post cp.to_json, :content_type => 'application/json'

RestClient::BadRequest: 400 Bad Request
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:231:in `process_result'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
        from /Users/user/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in `start'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
        from (irb):25
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
        from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start' 

The problem was that instead of giving me a readable response, it gave me a RestClient exception. Shouldn't a REST-Client return a verbose response regardless of that the http status sent? It should be noted that in the case I was working with, the 400 bad request response also returned a message that would help users get a grasp of the problem, but in this case, RestClient just chokes and never passes the returned response message on. I added a 'puts' on the response instance in the request.rb to check out the body of the response and sure enough I saw the message that I was looking for.

{ 
  "api_id": "0f00e214-62d1-11e2-a3f8-22000abc1360",
  "error": "insufficient balance"
}

From the RestClient request.rb source:

# Return the default behavior corresponding to the response code: 
# the response itself for code in 200..206, redirection for 301, 302 and 307 in get and head cases, redirection for 303 and an exception in other cases

Don't get too hung up on not seeing your 400 responses with RestClient. I did a little digging around and it turns out that you actually can disable the exceptions by passing a block with the request.

call["/Call/"].post(cp.to_json, :content_type => 'application/json'){|response| response }
 => "{\n  \"api_id\": \"7def1e60-62d7-11e2-a3f8-22000abc1360\",\n  \"error\": \"insufficient balance\"\n}" 

This is why we read the code :)

Tuesday, January 1, 2013

Mountable Deals API for Rails 3 Apps

Well written targeted deals online lead to sales. It's that simple.

Now it's really simple to add a powerful deals engine to any Rails 3 site. Check out the "deals" gem that I just authored here.

The deals gem will add an API to your app so you can publish your deals to your partner sites. The deals webservice can also serve as the back end to a rich client app since RESTful requests serve JSON responses.

The deals gem is built with the RailsAdmin UI so you can easily edit the deals and place them in categories and location. This gives you a deep and wide approach to dominate the deals in your niche.

The code for the gem is available on github.

Wednesday, December 19, 2012

Bundle Discount Extension for Piggybak e-commerce framework

I recently authored an extension for the piggybak e-commerce framework: The extension can be found here.

Piggybak is a rails e-commerce maintained by End Point.

There was no go-to guide on writing an extension for piggybak so I went wrote one. It is was recently posted on End Point's blog here.

Sunday, December 2, 2012

Configuring CouchDB for Travis CI

Today I made a new release on the DPLA platform that updated requests for single records. I added some new cucumber integration steps that passed locally but broke the Travis CI build.

The new record "Fetch" mechanism is performing a fetch on CouchDB after doing a simple "transformation" on the requested record ID. The id for the CouchDB is pulled from an ID assigned at the time of ingestion and indexed in ElasticSearch.

The new method and integration tests require hitting CouchDB, so fixing the build entailed enabling CouchDB in Travis. Check out the commit with the new Travis configuration here.

Instructions for setting up the CouchDB service in Travis can be found here. To get the DPLA platform configuration set up correctly for the test suite, I needed to ensure we had an Admin user set up in CouchDB, which was different from the vanilla CouchDB setup with Travis. The final solution entailed a small change to the config files so the search endpoint can be defined independent of the test environment.