4.3. Configuring authentication and authorization
By default, AMQ Broker uses a Java Authentication and Authorization Service (JAAS) properties login module to authenticate and authorize users. The configuration for the default JAAS login module is stored in a /home/jboss/amq-broker/etc/login.config file on each broker Pod and reads user and role information from the artemis-users.properties and artemis-roles.properties files in the same directory. You add the user and role information to the properties files in the default login module by updating the ActiveMQArtemisSecurity Custom Resource (CR).
An alternative to updating the ActiveMQArtemisSecurity CR to add user and role information to the default properties files is to configure one or more JAAS login modules in a secret. This secret is mounted as a file on each broker Pod. Configuring JAAS login modules in a secret offers the following advantages over using the ActiveMQArtemisSecurity CR to add user and role information.
- If you configure a properties login module in a secret, the brokers do not need to restart each time you update the property files. For example, when you add a new user to a properties file and update the secret, the changes take effect without requiring a restart of the broker.
-
You can configure JAAS login modules that are not defined in the
ActiveMQArtemisSecurityCRD to authenticate users. For example, you can configure an LDAP login module or any other JAAS login module.
Both methods of configuring authentication and authorization for AMQ Broker are described in the following sections.
4.3.1. Configuring JAAS login modules in a secret 复制链接链接已复制到粘贴板!
You can configure JAAS login modules in a secret to authenticate users with AMQ Broker. After you create the secret, you must add a reference to the secret in the main broker Custom Resource (CR) and also configure permissions in the CR to grant users access to AMQ Broker.
Procedure
Create a text file with your new JAAS login modules configuration and save the file as
login.config. By saving the file aslogin.config, the correct key is inserted in the secret that you create from the text file. The following is an example login module configuration:activemq { org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule sufficient reload=true org.apache.activemq.jaas.properties.user="new-users.properties" org.apache.activemq.jaas.properties.role="new-roles.properties"; org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule sufficient reload=false org.apache.activemq.jaas.properties.user="artemis-users.properties" org.apache.activemq.jaas.properties.role="artemis-roles.properties" baseDir="/home/jboss/amq-broker/etc"; };After you configure JAAS login modules in a secret and add a reference to the secret in the CR, the default login module is no longer used by AMQ Broker. However, a user in the
artemis-users.propertiesfile, which is referenced in the default login module, is required by the Operator to authenticate with the broker. To ensure that the Operator can authenticate with the broker after you configure a new JAAS login module, you must either:-
Include the default properties login module in the new login module configuration, as shown in the example above. In the example, the default properties login module uses the
artemis-users.propertiesandartemis-roles.propertiesfiles. If you include the default login module in the new login module configuration, you must set thebaseDirto the/home/jboss/amq-broker/etcdirectory, which contains the default properties files on each broker Pod. Add the user and role information required by the Operator to authenticate with the broker to a properties file referenced in the new login module configuration. You can copy this information from the default
artemis-users.propertiesandartemis-roles.propertiesfiles, which are in the/home/jboss/amq-broker/etc directoryon a broker Pod.注意The properties files referenced in a login module are loaded only when the broker calls the login module for the first time. A broker calls the login modules in the order that they are listed in the
login.configfile until it finds the login module to authenticate a user. By placing the login module that contains the credentials used by the Operator at the end of thelogin.configfile, all preceding login modules are called when the broker authenticates the Operator. As a result, any status message which states that property files are not visible on the broker is cleared.
-
Include the default properties login module in the new login module configuration, as shown in the example above. In the example, the default properties login module uses the
If the
login.configfile you created includes a properties login module, ensure that the users and roles files specified in the module contain user and role information. For example:- new-users.properties
ruben=ruben01! anne=anne01! rick=rick01! bob=bob01!- new-roles.properties
admin=ruben, rick group1=bob group2=anne
Use the
oc create secretcommand to create a secret from the text file that you created with the new login module configuration. If the login module configuration includes a properties login module, also include the associated users and roles files in the secret. For example:oc create secret generic custom-jaas-config --from-file=login.config --from-file=new-users.properties --from-file=new-roles.properties注意The secret name must have a suffix of
-jaas-configso the Operator can recognize that the secret contains login module configuration and propagate any updates to each broker Pod.For more information about how to create secrets, see Secrets in the Kubernetes documentation.
Add the secret you created to the Custom Resource (CR) instance for your broker deployment.
Using the OpenShift command-line interface:
- Log in to OpenShift as a user that has privileges to deploy CRs in the project for the broker deployment.
Edit the CR for your deployment.
oc edit ActiveMQArtemis <CR instance name> -n <namespace>
Using the OpenShift Container Platform web console:
- Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
-
In the left pane, click
. - Click the Red Hat Integration - AMQ Broker for RHEL 8 (Multiarch) operator.
- Click the AMQ Broker tab.
- Click the name of the ActiveMQArtemis instance name.
Click the YAML tab.
Within the console, a YAML editor opens, enabling you to configure a CR instance.
Create an
extraMountselement and asecretselement and add the name of the secret. The following example adds a secret namedcustom-jaas-configto the CR.deploymentPlan: ... extraMounts: secrets: - "custom-jaas-config" ...In the CR, grant permissions to the roles that are configured on the broker.
In the
specsection of the CR, add abrokerPropertieselement and add the permissions. You can grant a role permissions to a single address. Or, you can specify a wildcard match using the#sign to grant a role permissions to all addresses. For example:spec: ... brokerProperties: - securityRoles.#.group2.send=true - securityRoles.#.group1.consume=true - securityRoles.#.group1.createAddress=true - securityRoles.#.group1.createNonDurableQueue=true - securityRoles.#.group1.browse=true ...In the example, the group2 role is assigned
sendpermissions to all addresses and the group1 role is assignedconsume,createAddress,createNonDurableQueueandbrowsepermissions to all addresses.注意In a Java properties file, a colon (:) is a reserved character that is used to separate a key and a value in a key/value pair. If you want to grant permissions to a fully qualified queue name (FQQN), which consists of an address name and a queue name separated by colons (::), you must use the backslash (\) character to escape the colon characters in the FQQN. For example:
spec: ... brokerProperties: - 'securityRoles."my-address\:\:my-queue".group2.send=true'
Save the CR.
The Operator mounts the
login.configfile in the secret in a/amq/extra/secrets/secret namedirectory on each Pod and configures the broker JVM to read the mountedlogin.configfile instead of the defaultlogin.configfile. If thelogin.configfile contains a properties login module, the referenced users and roles properties file are also mounted on each Pod.View the status information in the CR to verify that the brokers in your deployment are using the JAAS login modules in the secret for authentication.
Using the OpenShift command-line interface:
Get the status conditions in the CR for your brokers.
$ oc get activemqartemis -o yaml
Using the OpenShift web console:
-
In the CR, navigate to the
statussection.
-
In the CR, navigate to the
In the status information, verify that a
JaasPropertiesAppliedtype is present, which indicates that the broker is using the JAAS login modules configured in the secret. For example:- lastTransitionTime: "2023-02-06T20:50:01Z" message: "" reason: Applied status: "True" type: JaasPropertiesAppliedWhen you update any of the files in the secret, the value of the
reasonfield showsOutofSyncuntil OpenShift Container Platform propagates the latest files in the secret to each broker Pod. For example, if you add a new user to thenew-users-propertiesfile and update the secret, you see the following status information until the updated file is propagated to each Pod:- lastTransitionTime: "2023-02-06T20:55:20Z" message: 'new-users.properties status out of sync, expected: 287641156, current: 2177044732' reason: OutOfSync status: "False" type: JaasPropertiesApplied
When you update user or role information in a properties file that is referenced in the secret, use the
oc set datacommand to update the secret. You must readd all the files to the secret again, including thelogin.configfile. For example, if you add a new user to thenew-users.propertiesfile that you created earlier in this procedure, use the following command to update thecustom-jaas-configsecret:oc set data secret/custom-jaas-config --from-file=login.config=login.config --from-file=new-users.properties=new-users.properties --from-file=new-roles.properties=new-roles.properties
The broker JVM reads the configuration in the login.config file only when it starts. If you change the configuration in the login.config file, for example, to add a new login module, and update the secret, the broker does not use the new configuration until the broker is restarted.
Additional Resources
第 8.3 节 “Example: configuring AMQ Broker to use Red Hat Single Sign-On”
For information about the JAAS login module format, see JAAS Login Configuration File.
You can use the ActiveMQArtemisSecurity Custom Resource (CR) to configure user and role information in the default JAAS properties login module to authenticate users with AMQ Broker. For an alternative method of configuring authentication and authorization on AMQ Broker by using secrets, see 第 4.3.1 节 “Configuring JAAS login modules in a secret”.
The ActiveMQArtemisSecurity CR is deprecated starting in AMQ Broker 7.12.
The following procedure shows how to configure the default JAAS login module using the Security Custom Resource (CR).
Prerequisites
You must have already installed the AMQ Broker Operator. For information on two alternative ways to install the Operator, see:
- You should be familiar with broker security as described in Securing brokers
You can deploy the security CR before or after you create a broker deployment. However, if you deploy the security CR after creating the broker deployment, the broker pod is restarted to accept the new configuration.
Start configuring a Custom Resource (CR) instance to define users and associated security configuration for the broker deployment.
Using the OpenShift command-line interface:
Log in to OpenShift as a user that has privileges to deploy CRs in the project for the broker deployment.
oc login -u <user> -p <password> --server=<host:port>Edit the CR for your deployment.
oc edit ActiveMQArtemis <CR instance name> -n <namespace>
Using the OpenShift Container Platform web console:
- Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
-
In the left pane, click
. - Click the Red Hat Integration - AMQ Broker for RHEL 8 (Multiarch) operator.
- Click the AMQ Broker tab.
- Click the name of the ActiveMQArtemis instance name
Click the YAML tab.
Within the console, a YAML editor opens, enabling you to configure a CR instance.
In the
specsection of the CR, add lines to define users and roles. For example:apiVersion: broker.amq.io/v1beta1 kind: ActiveMQArtemisSecurity metadata: name: ex-prop spec: loginModules: propertiesLoginModules: - name: "prop-module" users: - name: "sam" password: "samspassword" roles: - "sender" - name: "rob" password: "robspassword" roles: - "receiver" securityDomains: brokerDomain: name: "activemq" loginModules: - name: "prop-module" flag: "sufficient" securitySettings: broker: - match: "#" permissions: - operationType: "send" roles: - "sender" - operationType: "createAddress" roles: - "sender" - operationType: "createDurableQueue" roles: - "sender" - operationType: "consume" roles: - "receiver" ...注意Always specify values for the elements in the preceding example. For example, if you do not specify values for
securityDomains.brokerDomainor values for roles, the resulting configuration might cause unexpected results.The preceding configuration defines two users:
-
a
propertiesLoginModulenamedprop-modulethat defines a user namedsamwith a role namedsender. -
a
propertiesLoginModulenamedprop-modulethat defines a user namedrobwith a role namedreceiver.
The properties of these roles are defined in the
brokerDomainandbrokersections of thesecurityDomainssection. For example, thesendrole is defined to allow users with that role to create a durable queue on any address. By default, the configuration applies to all deployed brokers defined by CRs in the current namespace. To limit the configuration to particular broker deployments, use theapplyToCrNamesoption described in 第 8.1.3 节 “Security Custom Resource configuration reference”.注意In the
metadatasection, you need to include thenamespaceproperty and specify a value only if you are using the OpenShift Container Platform web console to create your CR instance. The value that you should specify is the name of the OpenShift project for your broker deployment.-
a
Deploy the CR instance.
Using the OpenShift command-line interface:
- Save the CR file.
Switch to the project for the broker deployment.
$ oc project <project_name>Create the CR instance.
$ oc create -f <path/to/security_custom_resource_instance>.yaml
Using the OpenShift web console:
- When you have finished configuring the CR, click Create.
4.3.2.2. Storing user passwords in a secret 复制链接链接已复制到粘贴板!
In the 第 4.3.2.1 节 “Configuring the default JAAS login module using the Security Custom Resource (CR)” procedure, user passwords are stored in clear text in the ActiveMQArtemisSecurity CR. If you do not want to store passwords in clear text in the CR, you can exclude the passwords from the CR and store them in a secret. When you apply the CR, the Operator retrieves each user’s password from the secret and inserts it in the artemis-users.properties file on the broker pod.
Procedure
Use the
oc create secretcommand to create a secret and add each user’s name and password. The secret name must follow a naming convention ofsecurity-properties-module name, where module name is the name of the login module configured in the CR. For example:oc create secret generic security-properties-prop-module \ --from-literal=sam=samspassword \ --from-literal=rob=robspasswordIn the
specsection of the CR, add the user names that you specified in the secret along with the role information, but do not include each user’s password. For example:apiVersion: broker.amq.io/v1beta1 kind: ActiveMQArtemisSecurity metadata: name: ex-prop spec: loginModules: propertiesLoginModules: - name: "prop-module" users: - name: "sam" roles: - "sender" - name: "rob" roles: - "receiver" securityDomains: brokerDomain: name: "activemq" loginModules: - name: "prop-module" flag: "sufficient" securitySettings: broker: - match: "#" permissions: - operationType: "send" roles: - "sender" - operationType: "createAddress" roles: - "sender" - operationType: "createDurableQueue" roles: - "sender" - operationType: "consume" roles: - "receiver" ...Deploy the CR instance.
Using the OpenShift command-line interface:
- Save the CR file.
Switch to the project for the broker deployment.
$ oc project <project_name>Create the CR instance.
$ oc create -f <path/to/address_custom_resource_instance>.yaml
Using the OpenShift web console:
- When you finish configuring the CR, click Create.
Additional resources
For more information about secrets in OpenShift Container Platform, see Providing sensitive data to pods in the OpenShift Container Platform documentation.