Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Set up Red Hat AMQ 7 custom certificates on OpenShift

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

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

    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

    • Tekton joins the CNCF as an incubating project

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

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

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.