Going serverless? Here’s what you need to know
Published: 2019-10-28 12:58:23

---
title: Going serverless? Here’s what you need to know
published: true
description: Security best practices to consider before going serverless
tags: 
---

Major companies have embraced this new innovation that is serverless and are changing their entire mindset of what the backend is. But amidst all the buzzwords flying about, comes a very important concern - <strong>how can I be sure I am using serverless in a secure way?</strong>

Serverless or <a href="https://dashbird.io/blog/what-is-faas-function-as-a-service/">Function-as-a-Service (FaaS) </a> has a lot of benefits and one of them is the fact that the security of the infrastructure powering the applications has been moved to the platform providers like AWS Lambda, Azure Functions, IBM Cloud Functions, Google Cloud Functions etc. and denial of service will no longer be as a result of hacker attempts but more of a billing issue. This results in the focus of attackers shifting from the infrastructure as it was in the past, to the application. 

Serverless applications are structured as a combination of small functions that execute your code returning a simple result. Depending on the number of open source repositories this kind of architecture widens the surface area and likelihood of cyber attacks making planning and building secure serverless applications an important point at the top of your todo list.

Here are several steps or best practices that should consider in order to build a secure serverless application. 

<h3>Function-level Security</h3>
The first of on the list of security best practices for serverless is to implement function-level security. As serverless allows you to run your applications through a series of functions that can be triggered, it is important to implement security at the functional level. A good practice is to take note of all your functions and check out what each function is meant(or allowed) to do against what it is currently doing. 

A rule of thumb according to <a href="https://twitter.com/hsolow">Hillel Sollow</a> is to define separate roles for each function which prevents you from giving certain functions access to data that they don’t need or performing actions that aren’t necessary thereby eliminating security loopholes in your code that can be exploited by attackers.

AWS Lambda allows you to do this in two distinct ways:
<strong>Through Identity-based policies</strong> - with this approach, you can either attach policies with permissions to a user or group in your account or you attach a policy to a specific IAM role thereby granting cross-account access to your Lambda function

<strong>Through Lambda Function policies</strong> - this approach allows you to grant cross-account permissions to your lambda functions without using identity-based policies with IAM roles.

<h3>Security audits on all dependencies</h3>
Most serverless applications use a lot of dependencies from Node.js, Python and many other repositories with open-source code. To ensure your application isn't leaving any backdoor to attackers, you need to check all dependencies for vulnerabilities. 

This can pose to be a very hard task in a scenario where you’re running serverless applications with lots of functions but not to worry, there are various solutions like: 
<ul>
<li>RetireJS - an open source vulnerability checker where developers can check if a Javascript library has any known vulnerabilities through a site-checking service
</li>
<li>Npm - an open source Javascript registry that acquired Node Security Project. Npm runs vulnerability checks through the npm audit command which is available in npm@6.
</li>
<li>
Snyk - a commercial vulnerability checker with its own vulnerability database (VD). Snyk works with .NET, PHP, GoLang, Java, Python, Scala, Ruby and Node.js
</li>
<li>
Greenkeeper - a commercial dependency management tool that automatically manages, updates and tests npm dependencies.
</li>
</ul>

Other solutions exist with the ability to help check dependencies with many of them relying on the <a href="https://nvd.nist.gov/">NIST’s</a> National Vulnerability Database (NVD) others rely on both the NIST NVD and their vulnerability databases as well so you will be doing yourself a big favour by searching them out and making good use of them.

<h3>Eliminate all ‘Dead’ Functions</h3>
In serverless, ‘dead’ functions are functions that have not been invoked for a very long time. As we all know that serverless gives room for unused functions to lie around thereby increasing the clutter (remember that you don't pay unless a function is invoked). There is a very high chance that you will have lots of unused functions with various permissions and privileges lying around. 

Now, this can pose a very serious challenge to the developer as you can’t know what functions are not in use if they aren’t running and from a security point of view, functions that haven’t been used for a long time run a risk of having outdated libraries and dependencies.

<h2>So what do you do?</h2>

Well, besides having a well thought out plan from the get-go you'll have to use a proper monitoring tool for your application. There's no going around it. I'd recommend using <a href="dashbird.io">Dashbird.io</a>. It's easy to use, doesn't add any latency to your execution time and is very secure since it connects directly to your AWS account.

<h3>Don’t write bad code</h3>
This really can’t be stressed enough. Even with all the best practices mentioned earlier put in place, if you write bad code, you’ll be opening up your application to exploitation by attackers. Therefore, as a rule of thumb, ensure that your developers are continuously trained on coding best practices and all tools and libraries are constantly updated. 

Also, make sure your code goes through extensive code reviews and lots and lots of tests as a small bug in one function can lead to a good enough opening for attackers to infiltrate your application.

<h3>Conclusion</h3>
As with all applications (serverless or not), security is and will always be a very important factor to consider. 
Even though serverless makes the work of cyber attackers harder as the server infrastructure assigned to a function is almost always reset once the function is no longer active, it is still of great importance that your individual functions have been fortified enough to avoid illegal penetration.