<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amit Kumar</title>
    <description>The latest articles on DEV Community by Amit Kumar (@mnpaa).</description>
    <link>https://dev.to/mnpaa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F234399%2F9ee728f2-f68c-4f3b-9040-0c2ef287251f.jpg</url>
      <title>DEV Community: Amit Kumar</title>
      <link>https://dev.to/mnpaa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mnpaa"/>
    <language>en</language>
    <item>
      <title>Disable SSL certificate validation in Spring RestTemplate</title>
      <dc:creator>Amit Kumar</dc:creator>
      <pubDate>Wed, 19 Aug 2020 12:30:24 +0000</pubDate>
      <link>https://dev.to/mnpaa/disable-skip-ssl-validation-in-springboot-resttemplate-1ec2</link>
      <guid>https://dev.to/mnpaa/disable-skip-ssl-validation-in-springboot-resttemplate-1ec2</guid>
      <description>&lt;p&gt;We often run into certificate issue while using Rest Template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RestTemplate can give any of the below error if SSL certificate of the target host is not valid :&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PKIX path building failed&lt;/strong&gt; : sun.security.provider.certpath&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;PKIX path building failed&lt;/strong&gt; : sun.security.provider.certpath.SunCertPathBuilderException : unable to find valid certification path to requested target&lt;br&gt;
javax.net.ssl.SSLHandshakeException: PKIX path building failed&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Reasons for invalid SSL certificate could be any of the below :&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expired certificates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Self-signed certificates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrong host information in certificates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Revoked certificates&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Untrusted root of certificates.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;How we deal with it in production and non-production environment ?&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In &lt;em&gt;production&lt;/em&gt; environment, we usually add the required certificates to our application key-store, which allows us to make the HTTPS request successfully.&lt;/p&gt;

&lt;p&gt;In &lt;em&gt;non production&lt;/em&gt; environments, while developing an application, we often need to disable ssl certificate validation (self-signed, expired, non trusted root, etc) &lt;br&gt;
as we don’t want to go through the hassle of generating appropriate certificates and managing the key-store for testing purpose. &lt;/p&gt;

&lt;p&gt;So, We configure &lt;em&gt;RestTemplate&lt;/em&gt; to disable SSL validation (non-prod environment), and thus trust all kind of certificates whether valid or not in Spring Boot RestTemplate and allow http requests to the hosts without throwing exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public RestTemplate restTemplate() 
                throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -&amp;gt; true;

    SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
                    .loadTrustMaterial(null, acceptingTrustStrategy)
                    .build();

    SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

    CloseableHttpClient httpClient = HttpClients.custom()
                    .setSSLSocketFactory(csf)
                    .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
                    new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);
    RestTemplate restTemplate = new RestTemplate(requestFactory);
    return restTemplate;
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note : Avoid SSL Validation for RestTemplate for development environment only. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For production environment, we must do certificate management and SSL verification as disabling SSL verification might lead to security risks.&lt;/p&gt;

</description>
      <category>java</category>
      <category>security</category>
      <category>ssl</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Hello Istio!</title>
      <dc:creator>Amit Kumar</dc:creator>
      <pubDate>Sun, 01 Mar 2020 16:16:51 +0000</pubDate>
      <link>https://dev.to/mnpaa/what-is-istio-1o2h</link>
      <guid>https://dev.to/mnpaa/what-is-istio-1o2h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Istio&lt;/strong&gt; : An open source service mesh that helps you run a distributed microservice architecture. &lt;/p&gt;

&lt;p&gt;Now! You must be wondering why is everyone talking about service mesh ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What exactly is a service mesh ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well! In layman's term, A Service mesh is a dedicated infrastructure layer that eases communication between microservices. It manages how different parts of an application interact with each another and share data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What functionalities does Istio service mesh provides ?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Traffic monitoring.&lt;/li&gt;
&lt;li&gt;Access control.&lt;/li&gt;
&lt;li&gt;Circuit breakers.&lt;/li&gt;
&lt;li&gt;Load balancing&lt;/li&gt;
&lt;li&gt;Security.&lt;/li&gt;
&lt;li&gt;Resiliency.&lt;/li&gt;
&lt;li&gt;Routing. &lt;/li&gt;
&lt;li&gt;Timeouts. &lt;/li&gt;
&lt;li&gt;Retries.&lt;/li&gt;
&lt;li&gt;Reporting.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Istio Architecture :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nXiTRcfW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aehjbiw7w5803semq88i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nXiTRcfW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aehjbiw7w5803semq88i.png" alt="Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pilot&lt;/strong&gt; : It provides routing, development, deployment, testing, timeouts,  retries, circuit breakers, load balancing, fault injection support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixer&lt;/strong&gt; : It provides logging, Tracing, Telemetry, Policy enforcement support.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Citadel/Istio CA&lt;/strong&gt; : It provides secure communication between micro services over TLS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Envoy/Proxy&lt;/strong&gt; - It is a service proxy(sidecar proxy) designed for cloud-native applications. It's added to each microservice and handles ingress/egress traffic between services in the cluster and from a service to external services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Control Plane API&lt;/strong&gt; - Primary Orchestrator like : Kubernetes/Hashicorp Nomad.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why do you need Istio ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Service-to-service communication is what makes microservices work. &lt;/p&gt;

&lt;p&gt;And for communication to happen, developers implements the code logic into each service. Let's say I have 5-10 services running. So it's kind of easy for me to get the code for microservice communication implemented for each of the services.  &lt;/p&gt;

&lt;p&gt;Now, As my application grows big and communication gets more complex, it gets difficult to implemented code logic for service communication.&lt;/p&gt;

&lt;p&gt;That's where you need Istio.&lt;/p&gt;

&lt;p&gt;Best thing about Istio : No code level change is needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does the magic happens ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Istio deploys something called sidecar(proxy) next to each service which uses policy based routing to determine when/how/if traffic should be routed to respective services. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Istio also supports :&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Canary deployment.&lt;/li&gt;
&lt;li&gt;Circuit breaker.&lt;/li&gt;
&lt;li&gt;Fault tolerance etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How can you run Istio in Kubernetes ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Via leveraging the sidecar model, We can run Istio in a linux container in our Kubernetes pods.&lt;/p&gt;

&lt;p&gt;Just few configuration changes and you can onboard Istio to your Kubernetes cluster. &lt;/p&gt;

&lt;p&gt;Let's get started with the setup.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Install &lt;strong&gt;Docker Desktop&lt;/strong&gt; with built-in &lt;strong&gt;Kubernetes&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set &lt;strong&gt;memory = 8.0 GB&lt;/strong&gt; and &lt;strong&gt;CPUs = 4&lt;/strong&gt; under the advanced pane of &lt;strong&gt;Docker Desktop’s preferences&lt;/strong&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run following command to download and extract the latest release automatically : &lt;strong&gt;$ curl -L &lt;a href="https://istio.io/downloadIstio"&gt;https://istio.io/downloadIstio&lt;/a&gt; | sh -&lt;/strong&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the &lt;strong&gt;Istio package directory&lt;/strong&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the istioctl client from bin/ directory. to your path, on a macOS/Linux system : &lt;strong&gt;$ export PATH=$PWD/bin:$PATH&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the demo profile : &lt;strong&gt;$ istioctl manifest apply --set profile=demo&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify the installation : &lt;strong&gt;$ kubectl get svc -n istio-system&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that all the corresponding Kubernetes pods are deployed and are running : &lt;strong&gt;$ kubectl get pods -n istio-system&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Istio&lt;/strong&gt; is successfully installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Label the default namespace with istio-injection=enabled : &lt;strong&gt;$ kubectl label namespace default istio-injection=enabled&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy your application : &lt;strong&gt;$ kubectl apply -f &lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Confirm that all the services and pods are running via : &lt;strong&gt;$ kubectl get services&lt;/strong&gt; and &lt;strong&gt;$ kubectl get pods&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure that your application is running by sending a request to it using &lt;strong&gt;curl&lt;/strong&gt; command from any of the pods.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Congratulations!&lt;/strong&gt; You have got the the basic about what Istio is and why do we need it.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>kubernetes</category>
      <category>docker</category>
      <category>istio</category>
    </item>
  </channel>
</rss>
