Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat 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
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud 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

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • 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

Set up Red Hat AMQ 7 custom certificates on OpenShift

 

November 26, 2019
Federico Valeri
Related topics:
Kubernetes
Related products:
Streams for Apache KafkaRed Hat OpenShift Container Platform

Share:

    Secure communication over a computer network is one of the most important requirements for a system, and yet it can be difficult to set up correctly. This example shows how to set up Red Hat AMQ 7 end-to-end TLS encryption using a custom X.509 certificate on the Red Hat OpenShift platform.

    Prerequisites

    You need to have the following in place before you can proceed with this example:

    • An OpenShift cluster up and running.
    • A custom X.509 certificate in PEM format (along with its chain).
    • An active Red Hat Customer Portal account.

    The procedure

    Before we start, let's define a few handy variables:

    PROJECT="demo"
    USER="developer"
    BASEURL="https://raw.githubusercontent.com/jboss-container-images/jboss-amq-7-broker-openshift-image/74-7.4.0.GA"

    The first step is to log in and create a new project to host our broker:

    oc login -u $USER -p x
    oc new-project $PROJECT

    Then, we need to create a dedicated ServiceAccount for deployment and add the view role:

    echo '{"kind": "ServiceAccount", "apiVersion": "v1", "metadata": {"name": "amq-service-account"}}' | oc create -f -
    oc policy add-role-to-user view system:serviceaccount:$PROJECT:amq-service-account

    At this point, we should have all custom certificate files available. Most likely, this signed custom certificate came from the security team, along with its private key and the whole certificate's chain (all in PEM format).

    The certificate files consist of the following:

    • rootca.pem: The root Certificate Authority (CA) in our domain.
    • interm.pem: An intermediate CA created to sign the certificate in a specific context.
    • server.pem: The final server certificate, which can be issued for single or multiple domains (wildcard).
    • server-prk.pem: The private key associated with our server's certificate.

    Using these files, create a server KeyStore, convert it to Java KeyStore (JKS) format, and then trust the chain of certificates used to sign it:

    cat interm.pem rootca.pem > chain.pem
    cat server.pem chain.pem > bundle.pem
    openssl pkcs12 -export -in bundle.pem -inkey server-prk.pem -out server.p12 -name server -CAfile chain.pem -passout pass:secret
    keytool -importkeystore -alias server -srcstoretype PKCS12 -srckeystore server.p12 -srcstorepass secret -destkeystore server.jks -deststorepass secret 
    keytool -import -noprompt -trustcacerts -alias chain -file chain.pem -keystore server.jks -storepass secret

    When the server KeyStore is ready, it can be imported into a Secret that must also be added to the ServiceAccount created earlier:

    oc create secret generic amq-app-secret --from-file=server.jks
    oc secrets add sa/amq-service-account secret/amq-app-secret

    In this example, we use the persistent AMQ 7 SSL template, because we usually want our messages to survive a broker shutdown. Let's create the image stream and download the broker's template:

    oc login -u system:admin
    oc replace --force -f $BASEURL/amq-broker-7-image-streams.yaml
    curl -o broker.yaml $BASEURL/templates/amq-broker-74-persistence-ssl.yaml

    To be able to download the broker's image from the Red Hat Container Registry, we also need to add an authentication Secret and link it to the default ServiceAccount:

    oc create secret docker-registry registry-auth \
        --docker-server=registry.redhat.io \
        --docker-username=<portal-username> \
        --docker-password=<portal-password>
    oc secrets link default registry-auth --for=pull

    The next step is to deploy the broker using the downloaded template and pass our KeyStore as a parameter:

    oc login -u $USER -p x
    oc process -f broker.yaml \
        -p APPLICATION_NAME=$PROJECT \
        -p AMQ_USER=admin \
        -p AMQ_PASSWORD=admin \
        -p AMQ_TRUSTSTORE=server.jks \
        -p AMQ_TRUSTSTORE_PASSWORD=secret \
        -p AMQ_KEYSTORE=server.jks \
        -p AMQ_KEYSTORE_PASSWORD=secret \
        | oc create -f -

    We are almost finished. The last step is to create a service and a passthrough route to expose the desired port to the external world. Here we are exposing the AMQP port, but you can do the same with the other available protocols:

    oc create -f - <<EOF
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        application: $PROJECT-amq
      name: broker-amq-amqp-ssl
    spec:
      ports:
        - port: 5671
          targetPort: 5671
      selector:
        statefulset.kubernetes.io/pod-name: $PROJECT-amq-0
    EOF
    oc create route passthrough --service=broker-amq-amqp-ssl

    Java client setup

    You can use your preferred JMS library to build your client, but you will certainly need a truststore in JKS format for one-way TLS authentication:

    keytool -import -noprompt -file server.pem -alias server -keystore truststore.jks -storepass secret

    If you want to access the broker from outside OpenShift, then you also need to use a ConnectionFactory URL similar to this one:

    amqps://broker-amq-amqp-ssl-demo.192.168.64.53.nip.io:443?transport.verifyHost=false&transport.trustStoreLocation=src/main/resources/truststore.jks&transport.trustStorePassword=secret

    Additional notes

    You must bind the hostname you are using in the certificate's CN field to the cluster's HAProxy IP address in your DNS server. If you are using a homemade CA, then you also need to trust the chain on the client machine to access the Hawtio web console.

    Last updated: March 29, 2023

    Recent Posts

    • Skopeo: The unsung hero of Linux container-tools

    • Automate certificate management in OpenShift

    • Customize RHEL CoreOS at scale: On-cluster image mode in OpenShift

    • How to set up KServe autoscaling for vLLM with KEDA

    • How I used Cursor AI to migrate a Bash test suite to Python

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue