Skip to content

Commit

Permalink
[security] Remove sensitive msg from consumer/producer stats log (apa…
Browse files Browse the repository at this point in the history
…che#15483)

### Motivation
Currently, we are print password field to consumer/producer stats log

### Modification
- add missed `@JsonIgnore` on field and getMethod
- delete unused `withoutAttribute` call
  • Loading branch information
ZhangJian He authored May 8, 2022
1 parent 8bf6785 commit 8b2f3dd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ private void init(ConsumerConfigurationData<?> conf) {

try {
log.info("Starting Pulsar consumer status recorder with config: {}", w.writeValueAsString(conf));
log.info("Pulsar client config: {}", w.withoutAttribute("authentication")
.writeValueAsString(pulsarClient.getConfiguration()));
log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration()));
} catch (IOException e) {
log.error("Failed to dump config info", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ private void init(ProducerConfigurationData conf) {

try {
log.info("Starting Pulsar producer perf with config: {}", w.writeValueAsString(conf));
log.info("Pulsar client config: {}",
w.withoutAttribute("authentication").writeValueAsString(pulsarClient.getConfiguration()));
log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration()));
} catch (IOException e) {
log.error("Failed to dump config info", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.TimeUnit;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.ProxyProtocol;
Expand All @@ -58,6 +59,7 @@ public class ClientConfigurationData implements Serializable, Cloneable {
value = "The implementation class of ServiceUrlProvider used to generate ServiceUrl."
)
@JsonIgnore
@Getter(onMethod_ = @JsonIgnore)
private transient ServiceUrlProvider serviceUrlProvider;

@ApiModelProperty(
Expand Down Expand Up @@ -254,6 +256,8 @@ public class ClientConfigurationData implements Serializable, Cloneable {
value = "Password of TLS TrustStore."
)
@Secret
@JsonIgnore
@Getter(onMethod_ = @JsonIgnore)
private String tlsTrustStorePassword = null;

@ApiModelProperty(
Expand Down Expand Up @@ -326,8 +330,10 @@ public class ClientConfigurationData implements Serializable, Cloneable {
value = "Password of SOCKS5 proxy."
)
@Secret
@JsonIgnore
private String socks5ProxyPassword;

@JsonIgnore
public Authentication getAuthentication() {
if (authentication == null) {
this.authentication = AuthenticationDisabled.INSTANCE;
Expand Down Expand Up @@ -385,6 +391,7 @@ public String getSocks5ProxyUsername() {
return Objects.nonNull(socks5ProxyUsername) ? socks5ProxyUsername : System.getProperty("socks5Proxy.username");
}

@JsonIgnore
public String getSocks5ProxyPassword() {
return Objects.nonNull(socks5ProxyPassword) ? socks5ProxyPassword : System.getProperty("socks5Proxy.password");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.pulsar.client.impl.conf;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.pulsar.client.impl.auth.AuthenticationToken;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* Unit test {@link ClientConfigurationData}.
*/
public class ClientConfigurationDataTest {

private final ObjectWriter w;

{
ObjectMapper m = new ObjectMapper();
m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
w = m.writer();
}


@Test
public void testDoNotPrintSensitiveInfo() throws JsonProcessingException {
ClientConfigurationData clientConfigurationData = new ClientConfigurationData();
clientConfigurationData.setTlsTrustStorePassword("xxxx");
clientConfigurationData.setSocks5ProxyPassword("yyyy");
clientConfigurationData.setAuthentication(new AuthenticationToken("zzzz"));
String s = w.writeValueAsString(clientConfigurationData);
Assert.assertFalse(s.contains("Password"));
Assert.assertFalse(s.contains("xxxx"));
Assert.assertFalse(s.contains("yyyy"));
Assert.assertFalse(s.contains("zzzz"));
}

}

0 comments on commit 8b2f3dd

Please sign in to comment.