Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Securely connect Quarkus and Red Hat Data Grid on Red Hat OpenShift

October 15, 2020
James Falkner
Related topics:
SecurityJavaArtificial intelligenceKubernetesQuarkus

Share:

    The release of Red Hat Data Grid 8.1 offers new features for securing applications deployed on Red Hat OpenShift. Naturally, I wanted to check them out for Quarkus. Using the Quarkus Data Grid extension made that easy to do.

    Data Grid is an in-memory, distributed, NoSQL datastore solution based on Infinispan. Since it manages your data, Data Grid should be as secure as possible. For this reason, it uses a default property realm that requires HTTPS and automatically enforces user authentication on remote endpoints. As an additional layer of security on OpenShift, Data Grid presents certificates signed by the OpenShift Service Signer. In practice, this means that Data Grid is as secure as possible out of the box, requiring encrypted connections and authentication from the first request. Data Grid generates a default set of credentials (which, of course, you can override), but unauthenticated access is denied.

    In this article, I show you how to configure a Quarkus application with Data Grid and deploy it on OpenShift.

    Getting started with Data Grid 8.1

    OpenShift's Data Grid Operator makes it easy to deploy Data Grid in a variety of configurations. The Operator also manages Data Grid's security, storage, upgrade, and logging capabilities. Once you've deployed the Data Grid Operator from the OpenShift OperatorHub, it exposes custom resources (called Infinispan Cluster and Infinispan Cache), which Data Grid uses to provision the caches on an existing cluster.

    In the next sections, we'll deploy a three-node Data Grid cluster, configure a sample Quarkus application to securely connect to Data Grid, then deploy and verify our application on OpenShift.

    Deploy a three-node Data Grid cluster

    To deploy a three-node Data Grid cluster, just add the following custom resource to any OpenShift project (note that my project name for this example is dgdemo):

    apiVersion: infinispan.org/v1
    kind: Infinispan
    metadata:
      name: example-infinispan
      namespace: dgdemo
    spec:
      replicas: 3
      expose:
        type: LoadBalancer
    

    After you've added the custom resource, Data Grid deploys the nodes and sets up the networking. The setup includes a Kubernetes service that resolves to the cluster members. The Kubernetes service support HTTPS using the OpenShift Service Signer.

    Using signed certificates to connect Data Grid and Quarkus

    When your applications access Data Grid, they'll do so through the Kubernetes service, so they will be subject to its certificates. It's possible to use an annotated ConfigMap to simplify the process of injecting these certificates into a pod. However, because we're using Java, we'll need the certificates in a format that Java applications can consume, so JKS or PKCS12.

    We'll use the signed certificates when our Quarkus application initiates a TLS handshake with Data Grid. We need to manually extract and convert them to JKS format before mounting them in our application's running pods.

    Extract the certificates

    To generate the Java keystore, we first need to extract the certificates from the OpenShift Service Signer's certificate authority. We can then use the JDK's keytool to generate the keystore file. Using the oc, openssl, and keytool command-line interfaces (CLIs), enter the following:

    $ oc get secrets/signing-key -n openshift-service-ca -o template='{{index .data "tls.crt"}}' | openssl base64 -d -A > /tmp/server.crt
    $ keytool -importcert -keystore /tmp/server.jks -storepass password -file /tmp/server.crt -trustcacerts -noprompt
    

    This series of commands grabs the Base64-encoded certificate content, then uses the keytool format to a file /tmp/server.jks with the passphrase: password.

    Create a secret

    Next, we need to consume the certificates in our Quarkus application namespace (dgdemo). We'll create a secret, clientcerts, whose contents are set to the contents of our certificate file. Here's the command to do it:

    $ oc create secret generic clientcerts -n dgdemo --from-file=clientcerts=/tmp/server.jks
    

    Configure the Quarkus application

    We've created our secret named clientcerts and set its value as the content of our server.jks. Next, we need to configure our Quarkus application to mount the secret at a given mount point, read the contents, and use the certificates whenever it connects to Data Grid.

    I created a sample application for this part of the demonstration. Open it, and you'll see that I've already installed both the infinispan-client and openshift extensions. This is a simple application that responds to the GET /infinispan endpoint with the value of the Data Grid entry under the key of hello. As you might guess, the entry is "Hello World, Infinispan is up!"

    You can find the configuration in src/main/resources/application.properties. I'll also show it here:

    # The DNS name and port of the Service fronting Data Grid
    quarkus.infinispan-client.server-list=example-infinispan:11222
    
    # Auth info, including server name and super secret password for the developer
    quarkus.infinispan-client.auth-server-name=example-infinispan
    quarkus.infinispan-client.auth-realm=default
    
    # DG user credentials. You'll need to change these
    quarkus.infinispan-client.auth-username=developer
    quarkus.infinispan-client.auth-password=I@TIR7awMPvYATGl
    quarkus.infinispan-client.sasl-mechanism=PLAIN
    quarkus.infinispan-client.client-intelligence=BASIC
    
    # Where the application can read the trust store from when it runs
    quarkus.infinispan-client.trust-store=/mnt/clientcerts
    
    # trust store password
    quarkus.infinispan-client.trust-store-password=password
    
    # trust store type
    quarkus.infinispan-client.trust-store-type=jks
    
    # which secret to mount and where to mount it
    quarkus.openshift.mounts.my-volume.path=/mnt
    quarkus.openshift.secret-volumes.my-volume.secret-name=clientcerts
    
    # instructs quarkus to build and deploy to kubernetes/openshift, and
    # create an ingress Route, and to trust the Kubernetes API since we're using self-signed,
    quarkus.container-image.build=true
    quarkus.kubernetes.deploy=true
    quarkus.openshift.expose=true
    quarkus.kubernetes-client.trust-certs=true
    quarkus.kubernetes.deployment-target=openshift
    

    Get the secret

    Our application will use the values of quarkus.infinispan-client.auth-username and quarkus.infinispan-client.auth-password as the credentials to talk to Data Grid. Enter the following command to discover the autogenerated username of developer and its associated password:

    $ oc get secret/example-infinispan-generated-secret -o template='{{index .data "identities.yaml"}}' | openssl base64 -d -A
    

    Take the username and password and insert them into your theapplication.propeties file.

    With all of that in place, we're ready to deploy!

    Deploy to OpenShift

    All we have to do now is log into OpenShift and switch to our demo project, then build and deploy. In this case, the Quarkus OpenShift plugin does most of the work for us; we just enter:

    $ oc project dgdemo
    $ mvn clean package
    

    It will take a minute or so to build and deploy. After the build is done, the application should deploy and show up in the OpenShift developer console, as shown in Figure 1.

    The OpenShift developer console shows the Quarkus application and its build status.
    Data Grid Quarkus app in OpenShift Developer Console
    Figure 1: The Quarkus application with Data Grid in the OpenShift developer console.

    Test the application

    Before we test the application, let's take a look at its log file:

    $ oc logs -n dgdemo dc/infinispan-client-quickstart
    __  ____  __  _____   ___  __ ____  ______
     --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
     -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
    --\___\_\____/_/ |_/_/|_/_/|_|\____/___/
    2020-10-01 22:53:32,096 INFO  [org.inf.SECURITY] (HotRod-client-async-pool-1-1) ISPN000947: Using Java SSL Provider
    2020-10-01 22:53:37,612 INFO  [org.inf.HOTROD] (main) ISPN004021: Infinispan version: Infinispan 'Corona Extra' 11.0.3.Final
    2020-10-01 22:53:37,863 INFO  [InfinispanClientApp] (main) Create or get cache named mycache with the default configuration
    2020-10-01 22:53:37,909 INFO  [io.quarkus] (main) infinispan-client-quickstart 1.0-SNAPSHOT on JVM (powered by Quarkus 1.8.0.Final) started in 1.676s. Listening on: http://0.0.0.0:8080
    2020-10-01 22:53:37,909 INFO  [io.quarkus] (main) Profile prod activated.
    2020-10-01 22:53:37,909 INFO  [io.quarkus] (main) Installed features: [cdi, infinispan-client, kubernetes, resteasy]
    

    That looks healthy. Now, let's test it with curl:

    $ curl http://$(oc get route -n dgdemo infinispan-client-quickstart -o jsonpath="{.spec.host}")/infinispan
    Hello World, Infinispan is up!
    

    Yes, we got the expected value showing that the connection was successful.

    Verify the value in the Data Grid 8.1 web console

    As our final step, let's use the new Data Grid 8.1 web console to verify the value. To get to it, you can discover the URL with:

    $ echo http://$(oc get service/example-infinispan-external
     jsonpath='{.status.loadBalancer.ingress[0].hostname}'):11222
    

    This command outputs the URL, which you can then copy and paste into your browser. You can use the credentials that you specified earlier to log in. Then, find the mycache cache, and search for entries using the key hello, as shown in Figure 2.

    The Data Grid web console shows the The application's key and value.
    Data Grid Web Console
    Figure 2: The application's key and value in the new Data Grid web console.

    Wrap up

    Red Hat Data Grid delivers many features for hybrid cloud deployments on OpenShift. In this article, you've seen how to use a default configuration to securely connect your Quarkus applications to Data Grid and deploy them on OpenShift.

    While the default configuration is considered to be as secure as possible, there are many other features to explore. Examples include cross-data center asynchronous replication on OpenShift and autoscaling to dynamically expand and contract clusters sizes.

    Whether you choose the default configuration or need to explore additional security features, Red Hat Data Grid is a valuable solution for large datasets across large clouds.

    Last updated: October 14, 2020

    Recent Posts

    • How to run AI models in cloud development environments

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue