Skip to content

Commit

Permalink
Add text field attribute to hide sensitive input config (#13873)
Browse files Browse the repository at this point in the history
(cherry picked from commit ee646a4)
  • Loading branch information
thll committed Nov 9, 2022
1 parent e573909 commit 2a72eb5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
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 2a72eb5

Please sign in to comment.