<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Geoff Bourne on Medium]]></title>
        <description><![CDATA[Stories by Geoff Bourne on Medium]]></description>
        <link>https://medium.com/@itzgeoff?source=rss-1783a85ef34a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VeXg6IB7L7WIG-n_.</url>
            <title>Stories by Geoff Bourne on Medium</title>
            <link>https://medium.com/@itzgeoff?source=rss-1783a85ef34a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:41:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@itzgeoff/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Enabling Kafka batch consuming in a Spring Boot application]]></title>
            <link>https://medium.com/@itzgeoff/enabling-kafka-batch-consuming-in-a-spring-boot-application-66d74854681b?source=rss-1783a85ef34a------2</link>
            <guid isPermaLink="false">https://medium.com/p/66d74854681b</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Geoff Bourne]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 19:18:29 GMT</pubDate>
            <atom:updated>2020-09-16T19:18:29.964Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing a <a href="https://kafka.apache.org/">Kafka</a> consumer with <a href="https://spring.io/projects/spring-boot">Spring Boot</a> is incredibly easy, but changing a consumer to do batch processing is not immediately obvious.</p><p><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-kafka">Spring Boot’s Kafka support</a> is consistent with the other technologies it supports: Spring Boot auto-configures the common scenarios with reasonable defaults and exposes most customization via properties.</p><blockquote>Some documentation will lead you astray of that philosophy and have you customize your application the “Spring way” with tedious, custom configuration components. Be skeptical of such solutions, since the “<strong>Spring Boot</strong> way” of customization is typically much easier than the “<strong>Spring</strong> way”.</blockquote><p>Let’s start with a service component that has a @KafkaListener method and simply logs the received message:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84ddb11610d066dc6982ba8d5263f312/href">https://medium.com/media/84ddb11610d066dc6982ba8d5263f312/href</a></iframe><p>To consume a batch of messages instead, first change the method arguments to accept a List, as shown in the newly renamed method consumeBatchOfMessages:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d32f02bb544a543a435320fdf226f9/href">https://medium.com/media/93d32f02bb544a543a435320fdf226f9/href</a></iframe><p>When I originally tried this, I had hoped that was the only change I needed to make. The application successfully started up and consumed messages; however, the list only contained one element each time.</p><p>It turns out, one more change is needed: set the spring.kafka.listener.type to batch, where the default is single. In application.yml that setting looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47f8d03b40feca1aa6f8cf8edf137189/href">https://medium.com/media/47f8d03b40feca1aa6f8cf8edf137189/href</a></iframe><p>Now, depending on the topic volume, the consumer method will receive a varying number of messages per invocation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66d74854681b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using a custom trust store with RestTemplate in Spring Boot]]></title>
            <link>https://medium.com/@itzgeoff/using-a-custom-trust-store-with-resttemplate-in-spring-boot-77b18f6a5c39?source=rss-1783a85ef34a------2</link>
            <guid isPermaLink="false">https://medium.com/p/77b18f6a5c39</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[tls]]></category>
            <dc:creator><![CDATA[Geoff Bourne]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 18:03:26 GMT</pubDate>
            <atom:updated>2020-05-22T14:54:45.011Z</atom:updated>
            <content:encoded><![CDATA[<p>Out of the box, Spring Boot makes it easy to secure the embedded web server, but there’s not an obvious way to configure the client-side, RestTemplate to use a private or self-signed certificate chain. It turns out that the pieces are readily available, they just need to be glued together in a RestTemplateCustomizer.</p><p>Before moving on, I want to clarify that by default RestTemplate is able to access HTTPS endpoints that have a certificate chain signed by a well known certificate authority. It’s worth clarifying that <a href="https://stackoverflow.com/a/882479/121324">there are ways to install a custom CA certificate into the standard trust store used by the JVM and/or alter the location via JVM properties</a>; however, those solutions don’t lend themselves to Docker/Kubernetes deployments especially since passing passwords via JVM properties is not very secure.</p><p>As such, this article focuses on a solution that fits with Spring Boot’s property binding of environment variables to ensure that microservices deployed in Docker/Kubernetes can be easily customized to use custom, in-cluster certificate chains.</p><h3>What you’ll need</h3><p>You’ll need to provide a Java trust store file and know the password for that store. If you have a PEM file for the CA, you can convert that into a Java trust store file (JKS) using:</p><pre>keytool -import -keystore ca-truststore.jks -alias CAroot -file ca.pem -trustcacerts</pre><h3>The solution</h3><p>Spring Boot provides an abstraction, RestTemplateBuilder, to simplify the instantiation of pre-configured RestTemplate instances that can then be tailored to each component that needs to make REST calls. In turn, Spring Boot allows for global customization of that builder by locating and invoking any components that implement RestTemplateCustomizer, <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-resttemplate-customization">as described in the Spring Boot reference guide</a>.</p><p>The following code provides a component that implements the customizer interface. The auto-wired SecureRestTemplateProperties is a @ConfigurationProperties component to enable property binding. Its code is shown in a later section:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd3b7ee6268bb91aec127b517ccdecb9/href">https://medium.com/media/cd3b7ee6268bb91aec127b517ccdecb9/href</a></iframe><h3>How does it work?</h3><p>The best way to explain the solution is to work from the bottom of that method and go up.</p><p>The RestTemplate can have it’s low level, HTTP functionality customized by swapping out the request factory:</p><pre>restTemplate.setRequestFactory(requestFactory);</pre><p>Spring Web provides a standard implementation of an HTTP request factory:</p><pre><strong>final </strong>ClientHttpRequestFactory requestFactory =<br>        <strong>new </strong>HttpComponentsClientHttpRequestFactory(httpClient);</pre><p>That request factory in turn leverages an Apache HttpClient to perform the low-level HTTP/TCP operations. The Apache Http library provides many useful builders and one is available for HttpClient instances:</p><pre><strong>final </strong>HttpClient httpClient = HttpClientBuilder.<em>create</em>()<br>        .setSSLContext(sslContext)<br>        .build();</pre><p>That builder allows for setting a standard Java SSLContext from the javax.net.ssl package. The Apache Http library also provides a builder for simplifying the creation of SSLContext instances:</p><pre>sslContext = SSLContextBuilder.<em>create</em>()<br>    .loadTrustMaterial(<br>        <strong>new </strong>URL(<strong>properties</strong>.getTrustStore()),<br>        <strong>properties</strong>.getTrustStorePassword()<br>    )<br>    .setProtocol(<strong>properties</strong>.getProtocol())<br>    .build();</pre><p>There are several overloaded methods for loading the trust material (aka a “trust store”), so you may want to explore the API to choose one that works best for you. Finally, the protocol specifies the SSL/TLS algorithm/version, so be sure to adjust that accordingly.</p><h3>The property binding class</h3><p>For reference, the property binding class auto-wired into the component is declared as follows with getters generated via the Lombok @Data annotation:</p><pre>@ConfigurationProperties(<strong>&quot;rest.ssl&quot;</strong>)<br>@Data<br><strong>public class </strong>SecureRestTemplateProperties {<em><br>  </em>String <strong>trustStore</strong>;<br><em>  </em><strong>char</strong>[] <strong>trustStorePassword</strong>;<br><em>  </em>String <strong>protocol </strong>= <strong>&quot;TLSv1.2&quot;</strong>;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77b18f6a5c39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fine-tuning OAuth2 in Spring Boot]]></title>
            <link>https://medium.com/@itzgeoff/fine-tuning-oauth2-in-spring-boot-3f1eff1ea4c0?source=rss-1783a85ef34a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f1eff1ea4c0</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[spring-security]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Geoff Bourne]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 20:36:07 GMT</pubDate>
            <atom:updated>2018-12-08T03:39:44.423Z</atom:updated>
            <content:encoded><![CDATA[<p>Rather than create a new account on each web app I use, I like it when a web app let’s me use an existing authentication provider, such as Google, Github, or Facebook. Likewise, I like to implement that choice with the web apps I develop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*awtd9I3H2T454wVaa2uSQg.png" /></figure><p>The good news is that the providers mentioned above (and more) support <a href="https://oauth.net/2/">OAuth 2.0</a> and we can use a portion of the OAuth 2.0 authentication flow to verify that a user accessing our web app is who they say they are by way of an OAuth 2.0 authentication provider</p><p>Spring Boot, via Spring Security, supports the different roles in OAuth 2.0, but what we’re specifically interested in is the client part. Even more specifically, this article will focus on the use of Facebook as an authentication provider since Facebook’s API (or maybe Spring Security) has a quirk where the user info retrieval responds with a content type of “text/javascript” for what is actually JSON.</p><blockquote>The source code for the complete application built below is <a href="https://github.com/itzg/try-oauth2-login">available in GitHub</a>.</blockquote><p>Let’s walk through creating a Spring Boot application from scratch. Start by using <a href="https://start.spring.io/">Spring Initializr</a> (or the IDE equivalent) to create a new project with the dependencies</p><ul><li>web</li><li>security</li></ul><p>After creating/downloading that initial project you’ll also need to manually add the spring-security-oauth2-client dependency, as mentioned <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-security.html#boot-features-security-oauth2-client">in the Spring Boot documentation</a>. Here is the Maven pom.xml entry for that dependency:</p><pre>&lt;dependency&gt;<br>  &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;<br>  &lt;artifactId&gt;spring-security-oauth2-client&lt;/artifactId&gt;<br>  &lt;version&gt;${spring-security.version}&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>This one needs a version specified since it is not declared as a managed dependency in the Spring Boot parent. The spring-security.version property <strong>is</strong> declared in the parent, so that can be used to identify a compatible Spring Security dependency.</p><p>To give us something to access and also provide information about how Spring Security identifies OAuth users, we’ll declare an API controller that returns the current security principal to the caller:</p><pre>@RestController<br>@RequestMapping(<strong>&quot;/api&quot;</strong>)<br><strong>public class </strong>ApiController {<br><br>  @GetMapping(<strong>&quot;currentUser&quot;</strong>)<br>  <strong>public </strong>Object getCurrentUser(Principal principal) {<br>    <strong>return </strong>principal;<br>  }<br>}</pre><p>This is actually enough code to try out the OAuth2 integration; however, let’s switch gears and get your test application registered in <a href="https://developers.facebook.com/">Facebook’s Developer area</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*Z-A5EH0ki2-dFCBZN3grbg.png" /></figure><p>After declaring your new app, setup the “Facebook Login” product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*unNG-MZf7u2GsajAP0bupQ.png" /></figure><p>You can skip the quickstart by clicking into the settings section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*Nyb663Z-CacnA2Ikaz7cIg.png" /></figure><p>Fill in the “Valid OAuth Redirect URIs” with https://localhost:8443/login/oauth2/code/facebook for development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*bl3r3Fn_Gunt0DdFo-tCGQ.png" /></figure><p>As you may have noticed, that URL is HTTPS and not HTTP. Facebook, rightly so, requires that all callback URIs be secured. It’s a little annoying for local development, but it is fairly easy to solve in a Spring Boot application.</p><blockquote>If you’re coming over here from <a href="https://medium.com/@itzgeoff/including-react-in-your-spring-boot-maven-build-ae3b8f8826e">my other story about including React in your Spring Boot build</a>, then <a href="https://facebook.github.io/create-react-app/docs/using-https-in-development">the React Tools make development-time HTTPS even easier</a> — just declare the environment variable HTTPS=true and run the front-end like normal. You’ll <strong>need </strong>to replace or add https://localhost:3000/login/oauth2/code/facebook as a valid redirect URL.</blockquote><p>Since this is for your own development, you can just generate a self signed certificate. To do this, go into the src/main/resources directory and run keytool, which comes with the JDK:</p><pre>keytool -genkey -alias boot \<br>  -storetype PKCS12 -keyalg RSA -keysize 2048 \<br>  -keystore keystore.p12 -validity 3650</pre><p>With the keystore.p12 file generated into your project’s src/main/resources you can reference that and enable SSL/TLS in src/main/resources/application.yml like the following, but replacing PASSWORD_GIVEN_TO_KEYTOOL with the password you gave when prompted.</p><blockquote>You can rename the empty application.properties file there or just delete it.</blockquote><pre><strong>server</strong>:<br>  <strong>port</strong>: 8443<br>  <strong>ssl</strong>:<br>    <strong>key-alias</strong>: boot<br>    <strong>key-store</strong>: classpath:keystore.p12<br>    <strong>key-store-type</strong>: PKCS12<br>    <strong>key-store-password</strong>: PASSWORD_GIVEN_TO_KEYTOOL</pre><p>You’re almost ready to try out the application. In the Facebook Developer area, go into the Basic Settings shown below. Grab the “App ID” and “App Secret” — those will be used as “client-id” and “client-secret”, respectively in the Spring Boot properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fn4iJB5gJRWaRnC2rGpcfg.png" /></figure><p>However you start your Spring Boot app you will need to set the following two properties to reference your Facebook application’s “App ID” and “App Secret” from above.</p><ul><li>spring.security.oauth2.client.registration.facebook.client-id</li><li>spring.security.oauth2.client.registration.facebook.client-secret</li></ul><blockquote>Don’t set those in application.yml since it would be too easy to commit and push that file to a public repository.</blockquote><p>With your application configured and running, you can access the following from your browser, curl, or a REST API client of your choice:</p><p><a href="https://localhost:8443/api/currentUser">https://localhost:8443/api/currentUser</a></p><p>Unfortunately, after approving access via Facebook and accepting the self-signed certificate you’ll probably see the following error about no suitable converter being found:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*gV9RIymY4hOVeWy-vNj2Vw.png" /></figure><p>Let’s work on fixing that by fine tuning the content type processing of the user info request. To do that we’ll create a configuration component that subclasses a WebSecurityConfigurerAdapter like the following</p><pre><a href="http://twitter.com/Configuration">@Configuration</a><br>public class WebSecurityConfig extends WebSecurityConfigurerAdapter {<br>  // ...autowire constructor</pre><pre>  // ...configure(HttpSecurity http)</pre><pre>  // ...userService factory<br>}</pre><p>Let’s autowire an ObjectMapper and RestTemplate to use in the JSON message converter and user info call, respectively:</p><pre>private RestTemplateBuilder restTemplateBuilder;<br>private ObjectMapper objectMapper;</pre><pre><a href="http://twitter.com/Autowired">@Autowired</a><br>public WebSecurityConfig(RestTemplateBuilder restTemplateBuilder, ObjectMapper objectMapper) {<br>  this.restTemplateBuilder = restTemplateBuilder;<br>  this.objectMapper = objectMapper;<br>}</pre><p>We’re going to need an OAuth2UserService that is adjusted from the default created by Spring. We’ll create a factory method to perform those adjustments, called userService in the configuration component:</p><pre>private OAuth2UserService&lt;OAuth2UserRequest, OAuth2User&gt; userService() {<br>    DefaultOAuth2UserService userService = <br>       new DefaultOAuth2UserService();</pre><pre>  // ...message converter</pre><pre>  // ...set RestOperations</pre><pre>  return userService;<br>}</pre><p>For the message converter, we’ll take the typical Jackson JSON converter and insist that it be accepting of “text/javascript”:</p><pre>MappingJackson2HttpMessageConverter messageConverter =<br>        new MappingJackson2HttpMessageConverter(objectMapper);<br>messageConverter.setSupportedMediaTypes(<br>    Collections.singletonList(<br>       new MediaType(<br>          &quot;text&quot;, &quot;javascript&quot;, StandardCharsets.UTF_8<br>      )<br>    )<br>);</pre><p>Finally, with that messageConverter and the RestTemplateBuilder autowired in the constructor, we can tell the user service to query Facebook (and others) with a RestTemplate that converts “text/javascript” as JSON:</p><pre>userService.setRestOperations(<br>    restTemplateBuilder<br>         .additionalMessageConverters(messageConverter)<br>        .build()<br>);</pre><p>One last step is needed in WebSecurityConfig. We need to tell the HTTP security configuration to use our customized user service with the OAuth2 login configuration.</p><pre><a href="http://twitter.com/Override">@Override</a><br>protected void configure(HttpSecurity http) throws Exception {<br>  http<br>      .authorizeRequests()<br>        .anyRequest().fullyAuthenticated()<br>      .and()<br>        .oauth2Login()<br>          .userInfoEndpoint()<br>          .userService(userService());<br>}</pre><p>The authorizeRequests used here is saying all requests must be fully authenticated. The part after the and tells oauth2 login mechanism to use the user service we customized.</p><p>Now, when you access <a href="https://localhost:8443/api/currentUser">https://localhost:8443/api/currentUser</a> it should respond with the content of the oauth2 principal, such as:</p><pre>{<br>  &quot;authorities&quot;: [<br>    {<br>      &quot;authority&quot;: &quot;ROLE_USER&quot;,<br>      &quot;attributes&quot;: {<br>        &quot;id&quot;: &quot;00000000000000000&quot;,<br>        &quot;name&quot;: &quot;Your Name&quot;,<br>        &quot;email&quot;: &quot;<a href="/service/mailto:someone@gmail.com">someone@gmail.com</a>&quot;<br>      }<br>    }<br>  ],<br>  &quot;details&quot;: null,<br>  &quot;authenticated&quot;: true,<br>  &quot;principal&quot;: {<br>    &quot;authorities&quot;: [<br>      {<br>        &quot;authority&quot;: &quot;ROLE_USER&quot;,<br>        &quot;attributes&quot;: {<br>          &quot;id&quot;: &quot;00000000000000000&quot;,<br>          &quot;name&quot;: &quot;Your Name&quot;,<br>          &quot;email&quot;: &quot;<a href="/service/mailto:someone@gmail.com">someone@gmail.com</a>&quot;<br>        }<br>      }<br>    ],<br>    &quot;attributes&quot;: {<br>      &quot;id&quot;: &quot;00000000000000000&quot;,<br>      &quot;name&quot;: &quot;Your Name&quot;,<br>      &quot;email&quot;: &quot;<a href="/service/mailto:someone@gmail.com">someone@gmail.com</a>&quot;<br>    },<br>    &quot;name&quot;: &quot;00000000000000000&quot;<br>  },<br>  &quot;authorizedClientRegistrationId&quot;: &quot;facebook&quot;,<br>  &quot;credentials&quot;: &quot;&quot;,<br>  &quot;name&quot;: &quot;00000000000000000&quot;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f1eff1ea4c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Including React in your Spring Boot maven build]]></title>
            <link>https://medium.com/@itzgeoff/including-react-in-your-spring-boot-maven-build-ae3b8f8826e?source=rss-1783a85ef34a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae3b8f8826e</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Geoff Bourne]]></dc:creator>
            <pubDate>Sat, 14 Jul 2018 15:53:08 GMT</pubDate>
            <atom:updated>2020-03-06T16:56:37.369Z</atom:updated>
            <content:encoded><![CDATA[<p>I call myself a “fullstack developer”, but really I’m a backend, Java developer that also likes to write frontend code. As such, I often develop applications starting first with my favorite application framework: <a href="https://spring.io/projects/spring-boot">Spring Boot</a>.</p><p>You can build Spring Boot apps with <a href="https://gradle.org/">Gradle</a> or <a href="http://maven.apache.org/">Maven</a>, but I remain a fan of the latter due Maven’s declarative approach to build specifications.</p><p>On the front-end side, by far the best way to start a new React application is with <a href="https://github.com/facebook/create-react-app">create-react-app</a> and it in turn prefers the use of <a href="https://yarnpkg.com/">yarn</a> to build the React application.</p><p>At this point we’re faced with a dilemma where we have two best-of-breed, but disparate build tools. It turns out we can have both: use maven for the “outer” build and have a maven plugin take care of the yarn invocation. I’m sure it can be attacked from yarn invoking maven…but, did I mention I’m a backend developer?</p><h3>Project Structure</h3><p>It turns out there’s very little you need to do differently to prepare your project’s structure for this hybrid build.</p><p>Since Maven is used as the primary build tool, we should follow it’s convention of src/main/&lt;type&gt; for situating production code to be built. You could call that &lt;type&gt; whatever you want, but I usually go with “app”. Something like “ui” or “frontend” are good choices too.</p><p>If you haven’t yet run <a href="https://github.com/facebook/create-react-app">create-react-app</a> to initialize your React, then run it like normal from within the src/main directory:</p><pre>cd src/main<br>npx create-react-app myNewApp</pre><p>That will create a directory named for the application name you passed; however, the React build scripts don’t care if that directory is renamed to something else. As such, rename your generated application directory to “app”:</p><pre>mv myNewApp app</pre><p>If you had already generated the React code, then just move that directory to be src/main/app.</p><p>Now you can develop and run the front-end just like normal from within the src/main/app directory:</p><pre>cd src/main/app<br>yarn run start</pre><p>Please note that create-react-app has built in support for <a href="https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development">development-time proxy’ing the API calls</a> via the typical NodeJS port of 3000 over to your Spring Boot web controllers on port 8080. <strong>When running the packaged jar in production, etc you don’t need to use the proxy mechanism</strong> since the Spring Boot embedded web server will be serving up the frontend, React content.</p><h3>Setup the maven build of React code</h3><p>We need to tell Maven to do two things for us:</p><ol><li>Build the React code via yarn</li><li>Place the result of the React build into the right spot for the packaged Spring Boot app</li></ol><h4>Declare the tool versions</h4><p>In your pom.xml locate or create the project &gt; properties section and add the following properties:</p><pre>&lt;<strong>frontend-src-dir</strong>&gt;${project.basedir}/src/main/app&lt;/<strong>frontend-src-dir</strong>&gt;<br>&lt;<strong>node.version</strong>&gt;v12.3.1&lt;/<strong>node.version</strong>&gt;<br>&lt;<strong>yarn.version</strong>&gt;v1.16.0&lt;/<strong>yarn.version</strong>&gt;<br>&lt;<strong>frontend-maven-plugin.version</strong>&gt;1.7.6&lt;/<strong>frontend-maven-plugin.version</strong>&gt;</pre><blockquote><strong>NOTE</strong>: Be sure to use the latest version of each item listed above since the versions shown here are only for example purposes.</blockquote><p>The plugin we’ll add in the next step will take care of downloading NodeJS and Yarn for those versions declared, so <strong>you don’t even need to worry about pre-installing those</strong> on the final build machine (i.e. CI tool). Very handy, right?</p><h4>Add the plugin to run yarn</h4><p>Again, in your pom.xml locate or create the project &gt; build &gt; plugins section and add the following plugin definition:</p><pre>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;com.github.eirslett&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;frontend-maven-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;${frontend-maven-plugin.version}&lt;/<strong>version</strong>&gt;<br><br>    &lt;<strong>configuration</strong>&gt;<br>        &lt;<strong>nodeVersion</strong>&gt;${node.version}&lt;/<strong>nodeVersion</strong>&gt;<br>        &lt;<strong>yarnVersion</strong>&gt;${yarn.version}&lt;/<strong>yarnVersion</strong>&gt;<br>        &lt;<strong>workingDirectory</strong>&gt;${frontend-src-dir}&lt;/<strong>workingDirectory</strong>&gt;<br>        &lt;<strong>installDirectory</strong>&gt;${project.build.directory}&lt;/<strong>installDirectory</strong>&gt;<br>    &lt;/<strong>configuration</strong>&gt;<br><br>    &lt;<strong>executions</strong>&gt;<br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>id</strong>&gt;install-frontend-tools&lt;/<strong>id</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;install-node-and-yarn&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br><br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>id</strong>&gt;yarn-install&lt;/<strong>id</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;yarn&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>            &lt;<strong>configuration</strong>&gt;<br>                &lt;<strong>arguments</strong>&gt;install&lt;/<strong>arguments</strong>&gt;<br>            &lt;/<strong>configuration</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br><br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>id</strong>&gt;build-frontend&lt;/<strong>id</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;yarn&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>            &lt;<strong>phase</strong>&gt;prepare-package&lt;/<strong>phase</strong>&gt;<br>            &lt;<strong>configuration</strong>&gt;<br>                &lt;<strong>arguments</strong>&gt;build&lt;/<strong>arguments</strong>&gt;<br>            &lt;/<strong>configuration</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br>    &lt;/<strong>executions</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;</pre><p>That plugin configuration will work generically for most applications. The plugin executions are taking care of three sub-steps for you:</p><ol><li>Installing NodeJS and Yarn local to the project (in target/node if you’re curious)</li><li>Running yarn install to ensure the frontend dependencies are installed</li><li>Running yarn build to perform the optimized production build of the React code</li></ol><p>If you’re wondering how this seamlessly weaves into the overall Spring Boot build process, then the use of theprepare-package phase for the last execution of that plugin is important to ensure that the React bits are ready right before the final jar is created.</p><h4>Stage React build output into final location</h4><p>The last pom.xml modification is to add the following plugin configuration <strong>after the previous plugin</strong> to the project &gt; build &gt; plugins section:</p><pre>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;maven-resources-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;3.0.1&lt;/<strong>version</strong>&gt;<br>    &lt;<strong>executions</strong>&gt;<br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>id</strong>&gt;position-react-build&lt;/<strong>id</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;copy-resources&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>            &lt;<strong>phase</strong>&gt;prepare-package&lt;/<strong>phase</strong>&gt;<br>            &lt;<strong>configuration</strong>&gt;<br>                &lt;<strong>outputDirectory</strong>&gt;${project.build.outputDirectory}/static&lt;/<strong>outputDirectory</strong>&gt;<br>                &lt;<strong>resources</strong>&gt;<br>                    &lt;<strong>resource</strong>&gt;<br>                        &lt;<strong>directory</strong>&gt;${frontend-src-dir}/build&lt;/<strong>directory</strong>&gt;<br>                        &lt;<strong>filtering</strong>&gt;false&lt;/<strong>filtering</strong>&gt;<br>                    &lt;/<strong>resource</strong>&gt;<br>                &lt;/<strong>resources</strong>&gt;<br>            &lt;/<strong>configuration</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br>    &lt;/<strong>executions</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;</pre><p>This adds an execution of the built-in resources plugin to copy over the React build output from src/main/app/build into the /static path of the jar’s staging directory, target/classes. That is where the embedded Spring Boot web container expects index.html and supporting files to reside. After a mvn package run you can even look in target/classes/static to see how the usual web content ended up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*gniv8AN-nzr_k74JsPK9MQ.png" /></figure><p><em>The </em><em>static/static path is a bit odd, but that’s just a quirk of both Spring Boot and React build tools using the same naming convention.</em></p><h3>Run the build</h3><p>This step is super easy since it is no different than any other Spring Boot build:</p><pre>mvn package</pre><p>You can run the resulting jar just like any other Spring Boot app and then access the front-end code at <a href="http://localhost:8080/">http://localhost:8080</a> (or wherever you have it deployed):</p><pre>java -jar target/your-app-VERSION.jar</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae3b8f8826e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securely sending application logs and metrics across the internet]]></title>
            <link>https://medium.com/@itzgeoff/securely-sending-application-logs-and-metrics-across-the-internet-33a6e0089a6a?source=rss-1783a85ef34a------2</link>
            <guid isPermaLink="false">https://medium.com/p/33a6e0089a6a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[influxdb]]></category>
            <category><![CDATA[elastic]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Geoff Bourne]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 16:53:41 GMT</pubDate>
            <atom:updated>2018-01-10T17:06:07.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Using TLS, Logstash, Telegraf, and friends</p><h4>Here’s what I wanted to achieve:</h4><ul><li>Run a Spring Boot web application maximizing availability</li><li>Monitor the application’s logs and metrics for errors and just general activity</li></ul><p>Since I work at Rackspace, I get a few monthly credits on their public cloud. That roughly allows for running a Docker Swarm of two 2GB, 2-core nodes, which is plenty for my web application and its MongoDB. What that capacity doesn’t allow is running the telemetry pieces, such as Graylog, Elasticsearch, InfluxDB, Kibana, Chronograf, and so on.</p><p>Speaking of Graylog, while a very nice looking and thorough system for log monitoring, analysis, and alerting, from the start it felt too resource intensive. So, in an early version of this endeavor I abandoned Graylog in favor of plain old Elasticsearch + Kibana. Actually, now that Elastic products are up in the 6.x series they are pretty slick and cover all my needs anyway.</p><p>So, my application hosting is easily satisfied by my public cloud budget. That leaves me with the challenge of where to run the telemetry gathering and visualization pieces. Here’s where I get to cheat a bit because I already had an Intel NUC sitting under my desk at home running Ubuntu. With a dual-core i5, 16 GB RAM, and a 256 GB SSD it can run a surprising amount of stuff without making a noise.</p><p>The NUC will be a great place to run a dual stack of logging/metrics collection and visualization; however, that will be running without the safety net of a hosting provider. There are two things I can leverage though: 1) my entire home network is already behind the NAT of my cable modem and 2) public key cryptography + TLS.</p><p>The NAT port forwarding is fairly boring, so here’s the quick run down on that:</p><ul><li>I assigned a reserved IP for my NUC in the cable modem’s configuration. That way I can be lazy and let the NUC use DHCP, yet get a fixed IP address.</li><li>I picked a block of 1000 ports to forward to the NUC’s IP address</li><li>My self imposed rule is that ports in that 1000-port range, which are now exposed to the public internet, are secured by TLS and client certificate authentication</li></ul><h4>Brief Overview of Public Key Infrastructure (PKI)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*gCBYXKjINIjS7PLP_KhTnA.png" /><figcaption>Establishing Mutual Trust using PKI</figcaption></figure><p>There’s a lot of things in this diagram, but that’s because it includes all of the ingredients needed to establish mutual trust between a client and a server over the untrusted wilds of the internet. That’s all possible thanks to two intense sounding acronyms, PKI and TLS. If this already melts your brain, you can safely skip this entire section.</p><p>TLS is a whole topic in itself, so here’s the short version: TLS stands for Transport Layer Security and is the successor to SSL. It provides a way for two network devices to handshake and establish an encrypted communication channel between them. Part of that handshake involves public key cryptography, which is where the concept overlaps with PKI.</p><p>PKI, or Public Key Infrastructure, refers to the cryptographic ability to leverage publicly visible certificates to verify a message that is signed by a combination of that public certificate and a private key held by the signer.</p><p>Secure communication is all about trust or rather the lack thereof. In short, trust no one. So, first, how does a client trust that the certificate presented by a server is really theirs? This is where the <em>Infrastructure</em> in PKI comes into play.</p><p>DNS is actually part of that infrastructure and for the sake of this discussion we have to assume we trust our DNS server and its answers. The client knows a server by its hostname, but an IP connection needs an IP address. We’re still skeptical, but the first step towards trust is that our DNS server has told us the IP address of the server we think we want.</p><p>Now, the client can connect to the server over IP and during an early part of that TLS handshake the server presents its public certificate. Certificates include a field called the canonical name (CN) of the holder of that certificate. For server certificates that CN is typically the server’s hostname, but not always. There are also optional extensions to certificates one of which is the Subject Alternative Names (SANs). If the expected hostname of the server matches the CN or one of the DNS entries in the SAN list, then the client can further trust the server is the one expected.</p><p>But wait, just because the certificate looks valid and contains the expected hostname, how can the client trust the certificate in the first place? That can be answered by resolving a chain-of-trust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*NkMNDGSppk_wo3TN95CRLg.png" /></figure><p>Certificates (like C, above) are issued by a certificate authority and that certificate authority has a certificate (B) and that certificate is issued by a certificate authority…and that’s why it is called a chain. Like the diagram above, that chain of issuing can’t go on forever, so in the majority of cases there are well known root and intermediate certificate authorities. How are those well known? Typically because your operating system or browser says so. For example, if we trust B because it is bundled with our browser, then we can trust C because it was issued by B.</p><h4>Using self-signed certificates to build a triad of trust</h4><p>There was a lot going on in that previous section and that only scratched the surface. If you skipped that section, glance back at the diagram “Establishing Mutual Trust using PKI”. Items within that yellow, center cloud are things that my client and server trust and can even share “in the clear”. Of particular interest is that Issuer Certificate, which I can trust, because I created it.</p><p>The following diagram shows the triad of trust I need to implement mutually authenticated TLS across my own systems:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*sDWnv9s5DZgy7FOHFXfyVA.png" /></figure><p>The diagram only lists the public certificate file name, but there’s actually three files in each set:</p><p>The public certificate file, such as “ca.pem” and contains the header line:</p><pre>-----BEGIN CERTIFICATE-----</pre><p>The key file, such as “ca-key.pem” and contains the header line:</p><pre>-----BEGIN RSA PRIVATE KEY-----</pre><p>and a bundled certificate file, “ca-bundle.pem” which contains both the public certificate content and key such as:</p><pre>-----BEGIN CERTIFICATE-----<br>MIIDgjCCAmqgAwIBAgIUYoFix22qYHwMLqW7MFSm9WrCDxswDQYJKoZIhvcNAQEL<br>...<br>-----END CERTIFICATE-----<br>-----BEGIN RSA PRIVATE KEY-----<br>MIIEpAIBAAKCAQEA7LTksyDmYwH8ITenwTdsTzPxC1X9X8kBHisEdQpeQlAY+GjD<br>...<br>-----END RSA PRIVATE KEY-----</pre><p>The set of three files covers all of the configuration cases where some software, such as Logstash, work with separate certificate and key files, while other software, such as HAproxy, require a bundled file.</p><p>With a tiny helper script, I used <a href="https://github.com/cloudflare/cfssl">CFSSL </a>to generate the three sets of files. (Later I’ll rewrite that helper script to be a makefile.) In the past I had written my own bash script that wrapped openssl to create certificates, but cfssl was much easier. One part that makes it easier is that you define the certificate signing request (CSR) as a JSON file. With that you can tweak, re-run, and source control the definition.</p><p>Here is the CSR JSON file I used to generate the “logstash-server” files (with fake hostnames):</p><pre>{<br>  <strong>&quot;CN&quot;</strong>: <strong>&quot;full.host.name&quot;</strong>,<br>  <strong>&quot;hosts&quot;</strong>: [<br>    <strong>&quot;full.host.name&quot;</strong>,<br>    <strong>&quot;127.0.0.1&quot;<br>  </strong>],<br>  <strong>&quot;key&quot;</strong>: {<br>    <strong>&quot;algo&quot;</strong>: <strong>&quot;rsa&quot;</strong>,<br>    <strong>&quot;size&quot;</strong>: 2048<br>  },<br>  <strong>&quot;names&quot;</strong>: [<br>    {<br>      <strong>&quot;C&quot;</strong>:  <strong>&quot;US&quot;</strong>,<br>      <strong>&quot;L&quot;</strong>:  <strong>&quot;Your Town&quot;</strong>,<br>      <strong>&quot;O&quot;</strong>:  <strong>&quot;Your Org&quot;</strong>,<br>      <strong>&quot;OU&quot;</strong>: <strong>&quot;logstash&quot;</strong>,<br>      <strong>&quot;ST&quot;</strong>: <strong>&quot;Your State&quot;<br>    </strong>}<br>  ]<br>}</pre><p>For “ca” and “logstash-client” is the same except I removed the hosts field and replaced the CN with “CA” and “client”, respectively.</p><p>The first step actually generating the certificate filesets is to generate the self-signed, “CA” certificate:</p><pre>mkdir -p certs<br>cfssl gencert -initca csr-ca.json | cfssljson -bare certs/ca</pre><p>The cfssljson tool in that pipeline picks out the public certificate and key parts from the output and saves them each to a file, under a certs sub-directory in my case.</p><p>With the “CA” certificate I can issue the client and server certificates:</p><pre>cfssl gencert -profile=client \<br>    -ca=certs/ca.pem -ca-key certs/ca-key.pem \<br>    csr-logstash-client.json | cfssljson -bare certs/logstash-client<br><br>cfssl gencert -profile=www \<br>    -ca=certs/ca.pem -ca-key certs/ca-key.pem \<br>    csr-logstash-server.json | cfssljson -bare certs/logstash-server</pre><p>Using the -profile option leverages a default configuration in cfssl to generate certificates with specific “uses” for each case.</p><p>The “-bundle” derivative of each pair is created by cating the two generated files:</p><pre><strong>for </strong>t <strong>in </strong>ca logstash-client logstash-server; <strong>do<br></strong>    cat certs/<strong>$</strong>{t}.pem certs/<strong>$</strong>{t}-key.pem <em>&gt; certs/${t}-bundle.pem<br></em><strong>done</strong></pre><h4>Publishing certificates and keys into the Docker Swarm</h4><p>Docker Swarm makes it very easy to publish sensitive content into a Swarm of services. First, I published the top of the triad, “ca.pem” <strong>BUT NOT </strong>its key. Even though all private key files should be stored and transmitted carefully, <em>the CA key file should be treated with extra special care</em> since it is effectively the keys to the kingdom.</p><p>This is the command to create a secret containing the “ca.pem” content:</p><pre>docker secret create ca.pem ca.pem</pre><p>The first “ca.pem” is the name of the secret and the second is the source file of the content. Using a filename as the secret name works out nicely since the default behavior is to create a file named for the secret under /var/run/secrets. In the application swarm, I did the same for the public, key, and bundle files for the client. In the telemetry swarm, I did the same for the server files.</p><h4>Deploying the application swarm</h4><p>For the application swarm, I am deploying a Docker Swarm Stack defined in a Docker Compose file. <em>In this section I’ll show only snippets of the compose file.</em></p><p>First, the compose file is opened with the schema version and an example of the application service. Notice it only needs to refer to the logs and metrics receiver by their service name, since Docker Swarm will take care of DNS declarations amongst the containers:</p><pre><strong>version: &quot;3.4&quot;<br><br>services:<br>  app:<br>    environment:<br>      LOGGING_GELF_SERVER: </strong>logstash<br>      <strong>SPRING_METRICS_EXPORT_STATSD_HOST: </strong>telegraf</pre><p>The logstash service is declared as:</p><pre><strong>logstash:<br>  image: </strong>docker.elastic.co/logstash/logstash-oss:6.1.1<br>  <strong>configs:<br>    </strong>- <strong>source: </strong>logstash<br>      <strong>target: </strong>/usr/share/logstash/pipeline/logstash.conf<br>  <strong>secrets:<br>    </strong>- ca.pem<br>    - logstash-client.pem<br>    - logstash-client-key.pem<br>  <strong>ports:<br>    </strong>- 127.0.0.1:12201:12201/udp</pre><p>and telegraf as:</p><pre><strong>telegraf:<br>  image: </strong>telegraf:1.5.0<br>  <strong>secrets:<br>    </strong>- ca.pem<br>    - logstash-client.pem<br>    - logstash-client-key.pem<br>  <strong>configs:<br>    </strong>- <strong>source: </strong>telegraf<br>      <strong>target: </strong>/etc/telegraf/telegraf.conf<br>      <strong>mode: </strong>0660<br>  <strong>ports:<br>    </strong>- 127.0.0.1:8125:8125/udp</pre><p>Since we published the certificate and key content with docker secret commands manually, the secrets are declared in the compose file as external:</p><pre><strong>secrets:<br>  ca.pem:<br>    external: </strong>true<br>  <strong>logstash-client.pem:<br>    external: </strong>true<br>  <strong>logstash-client-key.pem:<br>    external: </strong>true</pre><p>Finally, we reference the respective configuration files for logstash and telegraf. Unlike the secrets, we’ll let the file content get published as service configuration during stack deployment:</p><pre><strong>configs:<br>  logstash:<br>    file: </strong>./logstash.conf<br>  <strong>telegraf:<br>    file: </strong>./telegraf.conf</pre><p>Since secrets declared on Swarm services are situated under /var/run/secrets by default, the following logstash configuration references them there:</p><pre>input <strong>{<br>    </strong>gelf <strong>{<br>    </strong>}<br>}<br><br>output <strong>{<br>    </strong>tcp <strong>{<br>        </strong>host =<strong>&gt; &quot;...&quot;<br>        </strong>port =<strong>&gt; ...<br>        </strong>codec =<strong>&gt; &quot;json_lines&quot;<br>        </strong>ssl_enable =<strong>&gt; true<br>        </strong>ssl_verify =<strong>&gt; true<br>        </strong>ssl_cacert =<strong>&gt; &quot;/var/run/secrets/ca.pem&quot;<br>        </strong>ssl_cert =<strong>&gt; &quot;/var/run/secrets/logstash-client.pem&quot;<br>        </strong>ssl_key =<strong>&gt; &quot;/var/run/secrets/logstash-client-key.pem&quot;<br>    </strong>}<br>}</pre><p>The telegraf configuration likewise references the certificate files in /var/run/secrets:</p><pre><em># Configuration for telegraf agent<br></em><strong>[agent]<br>  </strong>interval = <strong>&quot;10s&quot;<br><br>[[inputs.statsd]</strong>]<br>  protocol = <strong>&quot;udp&quot;<br><br>  </strong>service_address = <strong>&quot;:8125&quot;<br><br>[[outputs.influxdb]</strong>]<br>  urls = <strong>[&quot;https://your.host.name:5086&quot;]<br>  </strong>database = <strong>&quot;telegraf&quot;<br><br>  </strong>ssl_ca = <strong>&quot;/var/run/secrets/ca.pem&quot;<br>  </strong>ssl_cert = <strong>&quot;/var/run/secrets/logstash-client.pem&quot;<br>  </strong>ssl_key = <strong>&quot;/var/run/secrets/logstash-client-key.pem&quot;</strong></pre><p>With all that, the Swarm is deployed (and re-deployed) using:</p><pre>docker stack deploy --compose-file=docker-compose.yml app</pre><h4>Deploying the telemetry swarm</h4><p>The telemetry swarm follows a very similar process, so I’ll skip the docker secret publication since it also includes the “ca.pem” file, but the “-server” files instead of “-client”.</p><p>Logstash is defined much in the same way in the docker compose file:</p><pre><strong>version: &#39;3.4&#39;<br>services:<br><br>  logstash:<br>    image: </strong>docker.elastic.co/logstash/logstash-oss:6.1.1<br>    <strong>configs:<br>      </strong>- <strong>source: </strong>logstash<br>        <strong>target: </strong>/usr/share/logstash/pipeline/logstash.conf<br>    <strong>ports:<br>      </strong>- 5555:5555<br>    <strong>secrets:<br>      </strong>- ca.pem<br>      - logstash-server-key.pem<br>      - logstash-server.pem</pre><p>The configuration of InfluxDB is more awkward since it doesn’t (yet, as of 1.4.2) support client TLS authentication. Instead I’m using an open source tool from Square called <a href="https://github.com/square/ghostunnel">ghostunnel</a>. The outside world accesses port 5086, serviced by ghostunnel and it in turn tunnels valid connections through to port 8086 of InfluxDB:</p><pre><strong>influxdb:<br>  image: </strong>influxdb:1.4.2<br><br><strong>influxdb_tls_auth:<br>  image: </strong>squareup/ghostunnel<br>  <strong>command: </strong>&gt;<br>    server<br>    --listen 0.0.0.0:5086<br>    --unsafe-target<br>    --target influxdb:8086<br>    --keystore /certs/logstash-server-bundle.pem<br>    --cacert /certs/ca.pem<br>    --allow-all<br>  <strong>secrets:<br>    </strong><em># Can&#39;t use default /var/run/secrets <br>    # since ghostunnel image is based on alpine<br>    </em>- <strong>source: </strong>ca.pem<br>      <strong>target: </strong>/certs/ca.pem<br>    - <strong>source: </strong>logstash-server-bundle.pem<br>      <strong>target: </strong>/certs/logstash-server-bundle.pem<br>  <strong>ports:<br>    </strong>- 5086:5086</pre><p>Again, the telemetry swarm is deployed as a stack:</p><pre>docker stack deploy --compose-file=docker-compose.yml telemetry</pre><h4>Lots of details omitted</h4><p>A lot of details have been purposely omitted from this article, so please feel free to ask any and all questions in the comments. I maintain the Docker compose files of my application and telemetry swarms in these two spots:</p><ul><li><a href="https://github.com/itzg/kidsbank-js/blob/master/src/main/compositions/prod/docker-compose.yml">Application’s docker-compose.yml</a></li><li><a href="https://github.com/itzg/ansible-plays/blob/master/roles/telemetry/files/docker-compose.yml">Telemetry’s docker-compose.yml</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33a6e0089a6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>