4.4. Configuring AMQ Management Console
Configure user access and request access to resources on the broker.
Prerequisites
- Red Hat Single Sign-On 7.4
Procedure
Configure Red Hat Single Sign-On:
-
Navigate to the realm in Red Hat Single Sign-On that you want to use for securing AMQ Management Console. Each realm in Red Hat Single Sign-On includes a client named
Broker. This client is not related to AMQ. -
Create a new client in Red Hat Single Sign-On, for example
artemis-console. Navigate to the client settings page and set:
Valid Redirect URIs to the AMQ Management Console URL followed by
*, for example:https://broker.example.com:8161/console/*-
Web Origins to the same value as Valid Redirect URIs. Red Hat Single Sign-On allows you enter
+, indicating that allowed CORS origins includes the value for Valid Redirect URIs.
-
Create a role for the client, for example
guest. - Make sure all users who require access to AMQ Management Console are assigned the above role, for example, using Red Hat Single Sign-On groups.
-
Navigate to the realm in Red Hat Single Sign-On that you want to use for securing AMQ Management Console. Each realm in Red Hat Single Sign-On includes a client named
Configure the AMQ Broker instance:
Add the following to your
<broker-instance-dir>/instances/broker0/etc/login.configfile to configure AMQ Management Console to use Red Hat Single Sign-On:console { org.keycloak.adapters.jaas.BearerTokenLoginModule required keycloak-config-file="${artemis.instance}/etc/keycloak-bearer-token.json" role-principal-class=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal ; };Adding this configuration sets up a JAAS principal and a requirement for a bearer token from Red Hat Single Sign-On. The connection to Red Hat Single Sign-On is defined in the
keycloak-bearer-token.jsonfile, as described in the next step.Create a file
<broker-instance-dir>/etc/keycloak-bearer-token.jsonwith the following contents to specify the connection to Red Hat Single Sign-On used for the bearer token exchange:{ "realm": "<realm-name>", "resource": "<client-name>", "auth-server-url": "<RHSSO-URL>/auth", "principal-attribute": "preferred_username", "use-resource-role-mappings": true, "ssl-required": "external", "confidential-port": 0 }<realm-name>- the name of the realm in Red Hat Single Sign-On
<client-name>- the name of the client in Red Hat Single Sign-On
<RHSSO-URL>- the URL of Red Hat Single Sign-On
Create a file
<broker-instance-dir>/etc/keycloak-js-token.jsonwith the following contents to specify the Red Hat Single Sign-On authentication endpoint:{ "realm": "<realm-name>", "clientId": "<client-name>", "url": "<RHSSO-URL>/auth" }Configure the security settings by editing the the
<broker-instance-dir>/etc/broker.xmlfile.For example, to allow users with the
amqrole consume messages and allow users with theguestrole send messages, add the following:<security-setting match="Info"> <permission roles="amq" type="createDurableQueue"/> <permission roles="amq" type="deleteDurableQueue"/> <permission roles="amq" type="createNonDurableQueue"/> <permission roles="amq" type="deleteNonDurableQueue"/> <permission roles="guest" type="send"/> <permission roles="amq" type="consume"/> </security-setting>
- Run the AMQ Broker instance and validate AMQ Management Console configuration.
4.4.2. Setting up user access to AMQ Management Console 复制链接链接已复制到粘贴板!
You can access AMQ Management Console using the broker login credentials. The following table provides information about different methods to add additional broker users to access AMQ Management Console:
| Authentication Method | Description |
|---|---|
| Guest authentication | Enables anonymous access. In this configuration, any user who connects without credentials or with the wrong credentials will be authenticated automatically and assigned a specific user and role. For more information, see Configuring guest access in Configuring AMQ Broker. |
| Basic user and password authentication | For each user, you must define a username and password and assign a security role. Users can only log into AMQ Management Console using these credentials. For more information, see Configuring basic user and password authentication in Configuring AMQ Broker. |
| LDAP authentication | Users are authenticated and authorized by checking the credentials against user data stored in a central X.500 directory server. For more information, see Configuring LDAP to authenticate clients in Configuring AMQ Broker. |
4.4.3. Securing network access to AMQ Management Console 复制链接链接已复制到粘贴板!
To secure AMQ Management Console when the console is being accessed over a WAN or the internet, use SSL to specify that network access uses https instead of http.
Prerequisites
The following should be located in the <broker_instance_dir>/etc/ directory:
- Java key store
- Java trust store (needed only if you require client authentication)
Procedure
-
Open the
<broker_instance_dir>/etc/bootstrap.xmlfile. In the
<web>element, add the following attributes:<web path="web"> <binding uri="https://0.0.0.0:8161" keyStorePath="<path_to_keystore>" keyStorePassword="<password>" clientAuth="<true/false>" trustStorePath="<path_to_truststore>" trustStorePassword="<password>"> </binding> </web>- bind
-
For secure connections to the console, change the URI scheme to
https. - keyStorePath
Path of the keystore file. For example:
keyStorePath="<broker_instance_dir>/etc/keystore.jks"- keyStorePassword
- Key store password. This password can be encrypted.
- clientAuth
-
Specifies whether client authentication is required. The default value is
false. - trustStorePath
-
Path of the trust store file. You need to define this attribute only if
clientAuthis set totrue. - trustStorePassword
- Trust store password. This password can be encrypted.
Additional resources
-
For more information about encrypting passwords in broker configuration files, including
bootstrap.xml, see Encrypting Passwords in Configuration Files.
You can configure AMQ Management Console to authenticate users by using certificates instead of passwords.
Procedure
Obtain certificates for the broker and clients from a trusted certificate authority or generate self-signed certificates. If you want to generate self-signed certificates, complete the following steps:
Generate a self-signed certificate for the broker.
$ keytool -storetype pkcs12 -keystore broker-keystore.p12 -storepass securepass -keypass securepass -alias client -genkey -keyalg "RSA" -keysize 2048 -dname "CN=ActiveMQ Broker, OU=Artemis, O=ActiveMQ, L=AMQ, S=AMQ, C=AMQ" -ext bc=ca:false -ext eku=cAExport the certificate from the broker keystore, so that it can be shared with clients.
$ keytool -storetype pkcs12 -keystore broker-keystore.p12 -storepass securepass -alias client -exportcert -rfc > broker.crtOn the client, import the broker certificate into the client truststore.
$ keytool -storetype pkcs12 -keystore client-truststore.p12 -storepass securepass -keypass securepass -importcert -alias client-ca -file broker.crt -nopromptOn the client, generate a self-signed certificate for the client.
$ keytool -storetype pkcs12 -keystore client-keystore.p12 -storepass securepass -keypass securepass -alias client -genkey -keyalg "RSA" -keysize 2048 -dname "CN=ActiveMQ Client, OU=Artemis, O=ActiveMQ, L=AMQ, S=AMQ, C=AMQ" -ext bc=ca:false -ext eku=cAExport the client certificate from the client keystore to a file so that it can be added to the broker truststore.
$ keytool -storetype pkcs12 -keystore client-keystore.p12 -storepass securepass -alias client -exportcert -rfc > client.crtImport the client certificate into the broker truststore.
$ keytool -storetype pkcs12 -keystore client-truststore.p12 -storepass securepass -keypass securepass -importcert -alias client-ca -file client.crt -noprompt注意On the broker machine, ensure that the keystore and truststore files are in a location that is accessible to the broker.
In the
<broker_instance_dir>/etc/bootstrap.xmlfile, update the web configuration to enable the HTTPS protocol and client authentication for the broker console. For example:... <web path="web"> <binding uri="https://localhost:8161" keyStorePath="${artemis.instance}/etc/server-keystore.p12" keyStorePassword="password" clientAuth="true" trustStorePath="${artemis.instance}/etc/client-truststore.p12" trustStorePassword="password"> ... </binding> </web> ...binding uri- Specify the https protocol to enable SSL and add a host name and port.
keystorePath- The path to the keystore where the broker certificate is installed.
keystorePassword- The password of the keystore where the broker certificate is installed.
ClientAuth- Set to true to configure the broker to require that each client presents a certificate when a client tries to connect to the broker console.
trustStorePath- If clients are using self-signed certificates, specify the path to the truststore where client certificates are installed.
trustStorePasswordIf clients are using self-signed certificates, specify the password of the truststore where client certificates are installed .
NOTE. You need to configure the
trustStorePathandtrustStorePasswordproperties only if clients are using self-signed certificates.
Obtain the Subject Distinguished Names (DNs) from each client certificate so you can create a mapping between each client certificate and a broker user.
Export each client certificate from the client’s keystore file into a temporary file. For example:
keytool -export -file <file_name> -alias broker-localhost -keystore broker.ks -storepass <password>Print the contents of the exported certificate:
keytool -printcert -file <file_name>The output is similar to that shown below:
Owner: CN=AMQ Client, OU=Artemis, O=AMQ, L=AMQ, ST=AMQ, C=AMQ Issuer: CN=AMQ Client, OU=Artemis, O=AMQ, L=AMQ, ST=AMQ, C=AMQ Serial number: 51461f5d Valid from: Sun Apr 17 12:20:14 IST 2022 until: Sat Jul 16 12:20:14 IST 2022 Certificate fingerprints: SHA1: EC:94:13:16:04:93:57:4F:FD:CA:AD:D8:32:68:A4:13:CC:EA:7A:67 SHA256: 85:7F:D5:4A:69:80:3B:5B:86:27:99:A7:97:B8:E4:E8:7D:6F:D1:53:08:D8:7A:BA:A7:0A:7A:96:F3:6B:98:81The
Ownerentry is the Subject DN. The format used to enter the Subject DN depends on your platform. The string above could also be represented as;Owner: `CN=localhost,\ OU=broker,\ O=Unknown,\ L=Unknown,\ ST=Unknown,\ C=Unknown`
Enable certificate-based authentication for the broker’s console.
Open the
<broker_instance_dir>/etc/login.configconfiguration file. Add the certificate login module and reference the user and roles properties files. For example:activemq { org.apache.activemq.artemis.spi.core.security.jaas.TextFileCertificateLoginModule debug=true org.apache.activemq.jaas.textfiledn.user="artemis-users.properties" org.apache.activemq.jaas.textfiledn.role="artemis-roles.properties"; };org.apache.activemq.artemis.spi.core.security.jaas.TextFileCertificateLoginModule- The implementation class.
org.apache.activemq.jaas.textfiledn.user- Specifies the location of the user properties file relative to the directory that contains the login configuration file.
org.apache.activemq.jaas.textfiledn.roleSpecifies the properties file that maps users to defined roles for the login module implementation.
注意If you change the default name of the certificate login module configuration in the
<broker_instance_dir>/etc/login.configfile, you must update the value of the-dhawtio.realmargument in the<broker_instance_dir>/etc/artemis.profilefile to match the new name. The default name isactivemq.
Open the
<broker_instance_dir>/etc/artemis-users.propertiesfile. Create a mapping between client certificates and broker users by adding the Subject DNS that you obtained from each client certificate to a broker user. For example:user1=CN=user1,O=Progress,C=US user2=CN=user2,O=Progress,C=USIn this example, the user1 broker user is mapped to the client certificate that has a Subject Distinguished Name of CN=user1,O=Progress,C=US Subject DN. After you create a mapping between a client certificate and a broker user, the broker can authenticate the user by using the certificate.
Open the
<broker_instance_dir>/etc/artemis-roles.propertiesfile. Grant users permission to log in to the console by adding them to the role that is specified for the HAWTIO_ROLE variable in the<broker_instance_dir>/etc/artemis.profilefile. The default value of the HAWTIO_ROLE variable isamq. For example:amq=user1, user2
Configure the following recommended security properties for the HTTPS protocol.
-
Open the
<broker_instance_dir>/etc/artemis.profilefile. Set the
hawtio.http.strictTransportSecurityproperty to allow only HTTPS requests to the AMQ Management Console and to convert any HTTP requests to HTTPS. For example:hawtio.http.strictTransportSecurity = max-age=31536000; includeSubDomains; preloadSet the
hawtio.http.publicKeyPinsproperty to instruct the web browser to associate a specific cryptographic public key with the AMQ Management Console to decrease the risk of “man-in-the-middle” attacks using forged certificates. For example:hawtio.http.publicKeyPins = pin-sha256="..."; max-age=5184000; includeSubDomains
-
Open the
If requests to AMQ Management Console are routed through a proxy server, you can configure the AMQ Broker embedded web server, which hosts AMQ Management Console, to handle X-Forwarded headers. By handling X-Forwarded headers, AMQ Management Console can receive header information that is otherwise altered or lost when a proxy is involved in the path of a request. For example, the proxy can expose AMQ Management Console using HTTPS, and the AMQ Management Console, which uses HTTP, can identify from the X-Forwarded header that the connection between the browser and the proxy uses HTTPS and switch to HTTPS to serve browser requests.
Procedure
-
Open the
<broker_instance_dir>/etc/bootstrap.xmlfile. In the
<web>element, add thecustomizerattribute with a value oforg.eclipse.jetty.server.ForwardedRequestCustomizer. For example:<web path="web" customizer="org.eclipse.jetty.server.ForwardedRequestCustomizer"> .. </web>-
Save the
bootstrap.xmlfile. Start or restart the broker by entering the following command:
-
On Linux:
<broker_instance_dir>/bin/artemis run -
On Windows:
<broker_instance_dir>\bin\artemis-service.exe start
-
On Linux: