Encryption as a Service using Vault with Spring Boot

Database columns can be encrypted multiple ways. Most of the databases have built-in support to encrypt the values. For example, in Postgres we can use the function pgp_sym_encrypt and pgp_sym_decrypt. It has some disadvantages like every read/write operation will have some operation overhead and slow down the DB servers. Most of the database providers give an option to encrypt the values. Moreover, keys used for the encryption should be properly managed. And it is complicated to do within the realms of the database servers. In a distributed system, the computing costs should be kept minimal and databases have a very high i/o. And cryptographic functions use a big chunk of resources and it is a well-known fact. Most of the industries have regulatory requirements and protect sensitive data in an effective way. Finally, a common concern for engineers and security teams alike is to protect the data in transit and avoid eavesdropping. Encryption as a Service (EaaS) solves this problem and Hashicorp’s Vault has a transit engine which takes out the burden of encrypting the data in transit. Vault is already a default key management and secret management solution in most of the organizations and has been integration with popular

Continue reading

Changing HttpClient in Spring RestTemplate

If you’re a Spring boot user, you might have definitely used RestTemplate. If you read the official documentation carefully, you might read that RestTemplate will be deprecated in the future and we must use WebClient which offers Synchronous, Asynchronous and Streaming scenarios such as Server-Sent Events, WebSockets, etc. Majority of the applications in production uses RestTemplates and will be practically a long way before it is completely replaced with Reactive WebFlux. It is important to know how we can customize the RestTemplate changing different Http clients. The default HttpClient used in the RestTemplate is provided by the JDK. It is developed on top of the HttpURLConnection. There is a new module added in Java 9 in incubation status and standardized in Java 11 called java.net.http.HttpClient. We can use this to make a client connection as well without needing third-party libraries. It is still unclear whether this will be used in Spring clients. Let’s get back to the business. In Spring, the default HTTP client can be changed to Apache’s HttpClient or Square’s OkHttpClient. We can configure the RestTemplate to use the HttpClient of our choice. We can do this either directly or by using Spring Cloud Commons org.springframework.cloud.commons.httpclient which provides

Continue reading

Introduction to Micrometer with Springboot

Springboot and Springcloud has made it easier to develop Microservices in the past couple of years and its usage has increased tremendously. Springboot without Micrometer is like riding a Tesla X without the instrument cluster. Alternatively there are plenty of other tools available to instrument your code to collect metrics and some of them supplied by the metrics aggregators, some are provided by APM vendors and then there is a big gamut of open source projects. When we think about it at the enterprise scale questions like below may arise before choosing the right tool. Where should I place my instrumentation code? How to instrument uniformly across systems with the least possible overhead? What is the impact if we need to change the metrics aggregator? How to collect multi-dimensional metrics? Micrometer is one such amazing library which provides out of the box instrumentation for JVM applications and it addresses some of the common problems that we face while instrumenting and collecting metrics. It has first-class support for most of the metrics collectors and new ones getting added at a rapid pace. Let’s see how it works with an example. We will be using spring-boot in our example application and use

Continue reading