You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/12/22 20:30:30 UTC

(james-project) branch 3.7.x updated (82a4b1c9a6 -> 59bf9b9cdf)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch 3.7.x
in repository https://gitbox.apache.org/repos/asf/james-project.git


    from 82a4b1c9a6 JAMES-3604 Fix inverted condition for RabbitMQWorkQueue quorum queue … (#1749)
     new 3d22156176 [FIX] Set up JMX auth filter for Guice
     new 59bf9b9cdf [FIX] Set up JMX auth for Spring

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/java/org/apache/james/cli/ServerCmd.java  | 12 +++++++++++-
 .../spring-app/src/main/resources/jmxremote.access     |  1 +
 .../spring-app/src/main/resources/jmxremote.password   |  1 +
 .../james/app/spring/JamesAppSpringMainTest.java       | 17 +++++++++++++++++
 .../james/app/spring/JamesSpringContextTest.java       | 18 +++++++++++++++++-
 .../org/apache/james/modules/server/JMXServer.java     |  5 +++--
 .../META-INF/org/apache/james/spring-server.xml        |  7 +++++++
 7 files changed, 57 insertions(+), 4 deletions(-)
 create mode 100644 server/apps/spring-app/src/main/resources/jmxremote.access
 create mode 100644 server/apps/spring-app/src/main/resources/jmxremote.password


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


(james-project) 02/02: [FIX] Set up JMX auth for Spring

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch 3.7.x
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 59bf9b9cdfaabbeb1de6971ce0bbbe230c9f8b36
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Tue Dec 19 18:13:25 2023 +0100

    [FIX] Set up JMX auth for Spring
    
    This prevents un-authenticated user from triggering
    deserialization exploits which could be exploited
    for privilege escalation.
---
 .../src/main/java/org/apache/james/cli/ServerCmd.java  | 12 +++++++++++-
 .../spring-app/src/main/resources/jmxremote.access     |  1 +
 .../spring-app/src/main/resources/jmxremote.password   |  1 +
 .../james/app/spring/JamesAppSpringMainTest.java       | 17 +++++++++++++++++
 .../james/app/spring/JamesSpringContextTest.java       | 18 +++++++++++++++++-
 .../META-INF/org/apache/james/spring-server.xml        |  7 +++++++
 6 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/server/apps/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/apps/cli/src/main/java/org/apache/james/cli/ServerCmd.java
index 77b3aa1496..eddc34c8ae 100644
--- a/server/apps/cli/src/main/java/org/apache/james/cli/ServerCmd.java
+++ b/server/apps/cli/src/main/java/org/apache/james/cli/ServerCmd.java
@@ -121,7 +121,7 @@ public class ServerCmd {
     public static void executeAndOutputToStream(String[] args, PrintStream printStream) throws Exception {
         Stopwatch stopWatch = Stopwatch.createStarted();
         CommandLine cmd = parseCommandLine(args);
-        JmxConnection jmxConnection = new JmxConnection(getHost(cmd), getPort(cmd), getAuthCredential(cmd, JMX_PASSWORD_FILE_PATH_DEFAULT));
+        JmxConnection jmxConnection = new JmxConnection(getHost(cmd), getPort(cmd), getAuthCredential(cmd, locateJmxConfiguration()));
 
         CmdType cmdType = new ServerCmd(
                 new JmxDataProbe().connect(jmxConnection),
@@ -135,6 +135,16 @@ public class ServerCmd {
         stopWatch.stop();
     }
 
+    private static String locateJmxConfiguration() {
+        if (!new File(JMX_PASSWORD_FILE_PATH_DEFAULT).exists()) {
+            return JMX_PASSWORD_FILE_PATH_DEFAULT;
+        }
+        if (!new File("conf/jmxremote.password").exists()) {
+            return "conf/jmxremote.password";
+        }
+        return "../conf/jmxremote.password";
+    }
+
     private final JmxDataProbe probe;
     private final JmxMailboxProbe mailboxProbe;
     private final JmxQuotaProbe quotaProbe;
diff --git a/server/apps/spring-app/src/main/resources/jmxremote.access b/server/apps/spring-app/src/main/resources/jmxremote.access
new file mode 100644
index 0000000000..09a7b6612a
--- /dev/null
+++ b/server/apps/spring-app/src/main/resources/jmxremote.access
@@ -0,0 +1 @@
+james-admin readwrite
\ No newline at end of file
diff --git a/server/apps/spring-app/src/main/resources/jmxremote.password b/server/apps/spring-app/src/main/resources/jmxremote.password
new file mode 100644
index 0000000000..f2ad9e9aee
--- /dev/null
+++ b/server/apps/spring-app/src/main/resources/jmxremote.password
@@ -0,0 +1 @@
+james-admin changeme
\ No newline at end of file
diff --git a/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesAppSpringMainTest.java b/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesAppSpringMainTest.java
index 3acc3a596d..52726603ee 100644
--- a/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesAppSpringMainTest.java
+++ b/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesAppSpringMainTest.java
@@ -18,11 +18,28 @@
  ****************************************************************/
 package org.apache.james.app.spring;
 
+import java.io.File;
+import java.io.FileOutputStream;
+
 import org.junit.jupiter.api.Test;
 
 class JamesAppSpringMainTest {
     @Test
     void testServer() throws Exception {
+        File accessFile = new File("../conf/jmxremote.access");
+        accessFile.getParentFile().mkdirs();
+        accessFile.createNewFile();
+        try (FileOutputStream out = new FileOutputStream(accessFile)) {
+            out.write("james-admin readwrite\r\n".getBytes());
+            out.flush();
+        }
+        File passwordFile = new File("../conf/jmxremote.password");
+        passwordFile.createNewFile();
+        try (FileOutputStream out = new FileOutputStream(passwordFile)) {
+            out.write("james-admin changeme\r\n".getBytes());
+            out.flush();
+        }
+
         JamesAppSpringMain.main(null);
     }
 }
diff --git a/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesSpringContextTest.java b/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesSpringContextTest.java
index 8d2560a1fa..b65462d8cf 100644
--- a/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesSpringContextTest.java
+++ b/server/apps/spring-app/src/test/java/org/apache/james/app/spring/JamesSpringContextTest.java
@@ -21,6 +21,9 @@ package org.apache.james.app.spring;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.io.File;
+import java.io.FileOutputStream;
+
 import org.apache.james.container.spring.context.JamesServerApplicationContext;
 import org.apache.james.events.InVMEventBus;
 import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex;
@@ -34,7 +37,20 @@ class JamesSpringContextTest {
     private JamesServerApplicationContext context;
 
     @BeforeEach
-    void setup() {
+    void setup() throws Exception {
+        File accessFile = new File("../conf/jmxremote.access");
+        accessFile.getParentFile().mkdirs();
+        accessFile.createNewFile();
+        try (FileOutputStream out = new FileOutputStream(accessFile)) {
+            out.write("james-admin readwrite\r\n".getBytes());
+            out.flush();
+        }
+        File passwordFile = new File("../conf/jmxremote.password");
+        passwordFile.createNewFile();
+        try (FileOutputStream out = new FileOutputStream(passwordFile)) {
+            out.write("james-admin changeme\r\n".getBytes());
+            out.flush();
+        }
         context = new JamesServerApplicationContext(new String[] { "META-INF/org/apache/james/spring-server.xml" });
         context.registerShutdownHook();
         context.start();
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index 4d4168fe2f..39910f4fb6 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -221,6 +221,13 @@
         <property name="objectName" value="connector:name=rmi"/>
         <property name="serviceUrl"
                   value="service:jmx:rmi://${jmx.address}/jndi/rmi://${jmx.address}:${jmx.port}/jmxrmi"/>
+        <property name="environment">
+            <map>
+                <entry key="jmx.remote.x.password.file" value="../conf/jmxremote.password" />
+                <entry key="jmx.remote.x.access.file" value="../conf/jmxremote.access" />
+                <entry key="jmx.remote.rmi.server.credentials.filter.pattern" value="java.lang.String;!*"/>
+            </map>
+        </property>
     </bean>
 
     <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


(james-project) 01/02: [FIX] Set up JMX auth filter for Guice

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch 3.7.x
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3d221561761a0ab7c86896cc0028f21b65cc2b4d
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Tue Dec 19 16:55:52 2023 +0100

    [FIX] Set up JMX auth filter for Guice
    
    This prevents un-authenticated user from triggering
    deserialization exploits which could be exploited
    for privilege escalation.
---
 .../jmx/src/main/java/org/apache/james/modules/server/JMXServer.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
index 901926dad2..d880208f35 100644
--- a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
+++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
@@ -129,8 +129,9 @@ public class JMXServer implements Startable {
             Map<String, String> environment = Optional.of(existJmxPasswordFile())
                 .filter(FunctionalUtils.identityPredicate())
                 .map(hasJmxPasswordFile -> ImmutableMap.of("jmx.remote.x.password.file", jmxPasswordFilePath,
-                    "jmx.remote.x.access.file", jmxAccessFilePath))
-                .orElse(ImmutableMap.of());
+                    "jmx.remote.x.access.file", jmxAccessFilePath,
+                    "jmx.remote.rmi.server.credentials.filter.pattern", "java.lang.String;!*"))
+                .orElse(ImmutableMap.of("jmx.remote.rmi.server.credentials.filter.pattern", "java.lang.String;!*"));
 
             jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL),
                 environment,


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org