• Application development company
  • Application development company
  • Application development company
  • Application development company
  • Application development company
Application development company
Application development company

Jibu James

Senior Software Engineer

Application development companySep, 2020
Application development company9 min read
#JAVASPRINGBOOT
#MICROSERVICES

Microservices Architecture Security Best Practices and Patterns

Any organization moving from a monolithic architecture to microservices needs to be more agile. Microservices are smaller autonomous units that function independently. However, many such units work together to form an application. Microservices are a choice for those delivering complicated, large projects frequently. Microservices also help with reliability.

In this light, the distributed components of the microservices are required to be more secure. To achieve this, microservices architecture security best practices have to be implemented at different levels. The very fact that there are multiple services means that there are multiple vulnerable points in the system. Each of these points has to be secured properly to make for a reliable system.

Standout Benefits of Microservices

Productivity is improved when multiple teams work together on different elements of a single complex application Specific elements can be deployed without any major downtime Docker containers make up the infrastructure and they are easy to use Individual teams have the liberty to choose a suitable tool to fix a problem in the individual microservices components

In this article, we attempt to list out some methods that software architecture teams can use to secure microservices components and their functions.

Microservices Architecture Security Best Practices-Steps to be taken

To fix the vulnerabilities means securing the microservices. This equates to laying down best security practices, implementing them and following them. In such a case, security becomes part and parcel of the system and work goes on without interruption, increasing productivity and integrity of the microservices to a high value.

Step # 1: Go for a secure microservices design

During the developmental stages, developers must see to it that they embed several layers of security to protect the data. Security should be given the highest priority at every stage of development (from the design, to building and deployment stages) to get a secure microservices system. Defence in depth works wonders for the security of the system.

When developers start to write the code for the microservices system, the code should be subjected to continuous stress testing to ensure a strong architecture. This means testing the CI and CD pipelines. Static analysis and dynamic analysis security testing (SAST and DAST) should also be simultaneously implemented.

Whereas SAST can be used to check the weak points that exist in your code and imported libraries. As it works from the inside, a scanner that suits the programming language used should also be kept ready.

DAST mimics malicious attacks from the outside and does not depend on any language. Building these tests in the delivery pipeline ensures that there are fewer manual checks that need to be done.

The OWASP (Open Web Application Security Project) also offers a set of tools for analysis and some resources to help implement best practices while building software.

Step # 2: Scanning for dependencies

The libraries that are used during software development themselves use other libraries. This means that the software package has several dependencies (third-party). Therefore, security is a major concern as this aspect increases the chances of the number of system vulnerabilities.

Eliminating such vulnerabilities can be accomplished by scanning the application’s code repository regularly and thoroughly. Also, the newer code contributions and deployment pipeline should be checked regularly for the presence of vulnerable dependencies. This includes the updated latest releases as well.

It is common to spot an application’s release notes. However, only a few report security issues encountered. Sadly, only 10% report common exposure problems. Knowledge of the dependencies ensures there are no dependencies due to the new pull requests during deployment. It also ensures that your code is up-to-date. Tools such as Github’s Dependabot help to automate updates through pull requests. It is a good idea to enable security alerts in your repository.

Will microservices suit your organization? Read our blog titled "Advantages and Disadvantages of Microservices Architecture".

Download Ebook for FREE "How to choose the best microservices vendor and trim the cost"

Download our ebook: Porting from Monolith to Microservices: Is the shift worth it?

Step # 3: Rampant use of HTTPS

It is best to implement this aspect in a consistent manner for foundational protection of internal and external operations. Softening the attacks that occur within the network is as important as mitigating credential stuffing and phishing. This is best taken care of by implementing HTTPS across the microservices system.

HTTPS ensures privacy and data integrity in the system by encrypting communication over HTTP.

The Transport Layer Security (TLS), now referred to as HTTPS, requires an authentication certificate proving your identity to provide access to encrypted communications (via Public Key Infrastructure). After acquiring the certificates, continuously enhancing your security posture can be achieved by automating certificate generation and renewals. This will help to keep all negative factors that might compromise your architecture out of the system.

Every aspect of the microservices architecture can refer to these secure URLs (from Maven repositories to XSDs). The HTTP Strict-Transport-Security response header can also be used to instruct browsers to selectively access only your endpoints using HTTPS.

HTTPS is vital for securing data that is transmitted within your systems when you build your microservices systems and APIs. After deployment, connections to external users will also be secured, thereby protecting your data.

Are you ready to migrate to a microservices architecture? Talk to our expert team at SayOne today!

Securing GraphQL APIs

GraphQL uses HTTP, and there is no need for extra logic from a security viewpoint. However, it is important for you to keep your GraphQL implementation updated. GraphQL makes POST requests for everything. The server used is responsible for sanitizing the input.

Securing RSocket Endpoints

RSocket, a next-generation, layer 5 application communication protocol, is used for building cloud space and microservices applications.

With built-in reactive semantics, RSocket has the ability to provide reliable communications. The RSocket website purportedly has implementations available for Java, JavaScript, C++,.NET, Go, and Kotlin.

Use access and identity tokens
 

A microservices system encloses a gamut of activities, such as backend services which provide data, the code that transports the data to stores, and the UI that doles out the data in the required form for the users. Appropriate tools and protocols should be in place thereafter to deliver secure/effective authentication as well as authorization across the systems, creating the best microservices security patterns.

OAuth 2.0 is an example of an industry-standard protocol that authorizes users across distributed systems. OAuth 2.0’s client credential flow allows secure server-to-server communication between an API client and an API server in microservices systems.

OpenID Connect (OIDC), an extension of OAuth, offers a standard specification that helps developers to write code that will work across many identity providers. Together, they help the system to determine a user’s identity by sending across an access token to the user information endpoint. The path can be determined using OIDC discovery. This mechanism reduces the job of the developer from being compelled to build authentication mechanisms into every individual microservice.

Authorization Servers: Which is better: Many-to-one or One-to-One

Using OAuth 2.0 to secure your service means using an authorization server. This setup is typically a many-to-one relationship in which many microservices talk to a single authorization server.

The pros of the many-to-one approach:

  • Services use access tokens to talk to another internal service
  • You need to only look at a single place for all scope and permission definitions
  • It is easy to manage for both developers and security personnel
  • Faster
     

The cons of the many-to-one approach:

  • Rogue services may possibly cause problems with their tokens
  • If a service’s token is compromised, all services will be at risk
  • Vague security boundaries

The one-to-one is an alternate, more secure approach where each microservice is bound to an exclusive authorization server. To talk to each other, they have to register prior to trusting.

This architecture allows for clearly defined security boundaries. It is slower, more chatty, and harder to manage. A many-to-one relationship is recommended until a plan and associated documentation to support a one-to-one setup is ready.

PASETO tokens over JWT

The use of JSON Web Tokens (JWT) is popular, but they are also not preferred in some cases. This is because developers try to use JWT in order to avoid server-side storage for sessions.

PASETO expands to platform-agnostic security tokens. PASETO does not have any of the design deficits that plague JOSE standards. However, it is not very easy to use these tokens as many of the popular cloud-service providers do not support PASETO as yet.

Step # 5: Encryption

Encrypt and protect secrets

Microservices that talk to authorization servers will likely have secrets for communication, such as client secrets, API keys, or credentials for basic authentication.

You cannot check for these secrets in your source control management systems because they cause trouble while the team is working on the production code. It would be best to secure the secrets in environmental variables.

Secrets can be encrypted with tools such as HashiCorp Vault, Microsoft Azure Key Vault, or Amazon KMS. The tools allow encryption via a master key that creates an encrypted message stored as a file/database. The keys for decryption are always kept safe, allowing the team to spend more time implementing and managing other safeguards.

Step # 6: Verifying Security with Delivery Pipelines

It is recommended that dependency and container scanning be part of the source control monitoring system and also perform tests when executing your CI and CD pipelines.

DevSecOps is a more suitable term that emphasizes the need to build security into DevOps initiatives. Security unit tests, SAST, and DAST are on the way out. Automating these security checks in the code delivery pipeline is the best, though they will take some time to set up.

Step # 7: Slowing down attackers

Attacking the API with hundreds of username + password combinations will likely take some time for successful authentication. If this attack can be slowed down further, various endpoints can be protected to a greater extent. Approaches like rate limiting may deter attackers from continuing credential stuffing attacks. This method can be implemented in your code, with an open-source library, or within an API gateway.

Step # 8: Use Docker Rootless Mode

Docker version 19.03 introduced a rootless mode and this feature was designed to expose Docker capabilities to those systems (where users cannot gain root privileges) while reducing the security footprint of the Docker daemon.

This has to be looked into if you are running Docker daemons in production. If Kubernetes runs your Docker containers, there will be a requirement to configure runAsUser in the PodSecurityPolicy.

Step # 9: Using Time-Based Security

It is a good idea to use time-based security. Time-based security assumes that a system is never fully secure. In addition to preventing intruders from entering the system, detection and reaction are essential for securing a system.

Using multi-factor authentication is another good idea that slows down intruders and also detects authentication into a critical server, which should not happen too often. A domain controller that controls network traffic can be designed to send an alert to the network administrator team as soon as a successful login takes place.

Step # 10: Scanning the Docker and Kubernetes Configurations for Vulnerabilities

Docker containers commonly find a place in microservices architectures. Some best practices include, preferring minimal base image, using the USER directive to ensure that the least privileged is used, signing and verifying images to mitigate MITM attacks, finding, fixing and monitoring for open-source vulnerabilities, etc., among others.

Step # 11: Knowing the Cloud and Cluster Security

When managing your production clusters and clouds, the 4C’s of Cloud Native Security include Code, Container, Cluster, and Cloud/Corporate Datacenter.

Each of these factors depends on the security standards implemented and it is difficult to safeguard against poor standards in the cloud, containers, and code by simply addressing security at the code levels. If these are dealt with appropriately, then adding security to the code makes the base stronger.

Conclusion

The above is surely not an exhaustive list of microservices architecture security best practices. However, these issues commonly occur when building and running microservices. It pays to have an idea so that you can manage the services better in the long run.

Download our ebook: Porting from Monolith to Microservices: is the shift worth it? 

Are you looking to outsource your microservices project? Give us a call today!

READ ALSO
How to find the best microservices development company

What Kind of Challenges Can Microservices Help You Overcome
Why Business leaders should care about Microservices
Should you migrate from monolith to microservices architecture
The 5 Best Microservices Technologies List
Microservices Architecture – 5 things it is not
Advantages of Microservices Architecture, Disadvantages of Microservices Architecture
5 Microservices Examples: Amazon, Netflix, Uber, Spotify and Etsy
SOA vs. Microservices: What's the Difference?
Microservices and DevOps – Better together: What are the benefits
Uber Microservices Architecture
Future Scope of Microservices
Microservices at eBay

Application development company

Choose the best microservices vendor and trim the cost

A majority of the big corporations in the world are going the microservices way. Microservices are small independent but interconnected services that make up an application. This is unlike the earlier approach, when companies functioned with a single larg

Application development company

Porting from Monoliths to Microservices

Monolith means ‘composed in just one single piece’. A monolith application with reference to software is today a single-tiered application package that has all the different components combined into one behemoth.

Application development company

Focus on your core business while you outsource your app developer

  • Risk-Free trial and Zero Recruitment Charges
  • 100% dedicated developers for flexible custom application development

Need top engineers for your team.
Got a project on your mind

We collaborate with visionary leaders on projects that focus on quality and require the expertise of a highly-skilled and experienced team.

Or