Skip to content

Commit

Permalink
Backport: Add text field attribute to hide sensitive input config (#1…
Browse files Browse the repository at this point in the history
…3922)

* Add text field attribute to hide sensitive input config (#13873)

(cherry picked from commit ee646a4)

* Add changelog snippet for #13837
  • Loading branch information
thll authored Nov 10, 2022
1 parent e573909 commit 4ad8f5d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-13873.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "changed"
message = "Mask custom properties for Kafka inputs on the inputs page to hide sensitive information."

issues = ["13383"]
pulls = ["13873"]
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,9 @@ public ConfigurationRequest getRequestedConfiguration() {
"A newline separated list of Kafka properties. (e.g.: \"ssl.keystore.location=/etc/graylog/server/kafka.keystore.jks\").",
ConfigurationField.Optional.OPTIONAL,
ConfigurationField.PLACE_AT_END_POSITION,
TextField.Attribute.TEXTAREA
));
TextField.Attribute.TEXTAREA,
TextField.Attribute.IS_SENSITIVE
));

return cr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class TextField extends AbstractConfigurationField {

public enum Attribute {
IS_PASSWORD,
TEXTAREA
TEXTAREA,
IS_SENSITIVE
}

private String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,27 @@ protected Map<String, Object> maskPasswordsInConfiguration(Map<String, Object> c
HashMap::new,
(map, entry) -> {
final ConfigurationField field = configurationRequest.getField(entry.getKey());
if (field instanceof TextField) {
final TextField textField = (TextField) field;
if (textField.getAttributes().contains(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH))
&& !Strings.isNullOrEmpty((String) entry.getValue())) {
if (field instanceof TextField && !Strings.isNullOrEmpty((String) entry.getValue())) {
if (isPassword(field)) {
map.put(entry.getKey(), "<password set>");
return;
}
if (isSensitive(field)) {
map.put(entry.getKey(), "<value hidden>");
return;
}
}
map.put(entry.getKey(), entry.getValue());
},
HashMap::putAll
);
}

private static boolean isPassword(ConfigurationField field) {
return field.getAttributes().contains(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH));
}

private static boolean isSensitive(ConfigurationField field) {
return field.getAttributes().contains(TextField.Attribute.IS_SENSITIVE.toString().toLowerCase(Locale.ENGLISH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ConfigurationWell extends React.Component {
const value = config[key];
const requestedConfiguration = (typeDefinition && typeDefinition.requested_configuration ? typeDefinition.requested_configuration[key] : undefined);

if (requestedConfiguration && requestedConfiguration.attributes.indexOf('is_password') > -1) {
if (requestedConfiguration
&& (requestedConfiguration.attributes.indexOf('is_password') > -1 || requestedConfiguration.attributes.indexOf('is_sensitive') > -1)) {
return this._formatPasswordField(value, key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
type NumberFieldAttributes = 'only_negative' | 'only_positive' | 'is_port_number';
type TextFieldAttributes = 'is_password' | 'textarea';
type TextFieldAttributes = 'is_password' | 'textarea' | 'is_sensitive';
type ListFieldAttributes = 'allow_create';

export type NumberField = {
Expand Down

0 comments on commit 4ad8f5d

Please sign in to comment.