-
Notifications
You must be signed in to change notification settings - Fork 0
configure sensitive fields #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| sensitive_fields: | ||
| - pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| uceap_logging.settings: | ||
| type: config_object | ||
| label: 'UCEAP Logging Settings' | ||
| mapping: | ||
| sensitive_fields: | ||
| type: sequence | ||
| label: 'Sensitive fields' | ||
| sequence: | ||
| type: string | ||
| label: 'Field name' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\uceap_logging\Form; | ||
|
|
||
| use Drupal\Core\Form\ConfigFormBase; | ||
| use Drupal\Core\Form\FormStateInterface; | ||
|
|
||
| /** | ||
| * Configure UCEAP Logging settings. | ||
| */ | ||
| class LoggingSettingsForm extends ConfigFormBase { | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function getFormId() { | ||
| return 'uceap_logging_settings'; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function getEditableConfigNames() { | ||
| return ['uceap_logging.settings']; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function buildForm(array $form, FormStateInterface $form_state) { | ||
| $config = $this->config('uceap_logging.settings'); | ||
|
|
||
| $form['sensitive_fields'] = [ | ||
| '#type' => 'textarea', | ||
| '#title' => $this->t('Sensitive Fields'), | ||
| '#description' => $this->t('Enter field machine names (one per line) that should have their values masked in entity change logs. When these fields are modified, they will appear in logs with masked values (e.g., ***MASKED***) instead of actual values.'), | ||
| '#default_value' => implode("\n", $config->get('sensitive_fields') ?? []), | ||
| '#rows' => 10, | ||
| ]; | ||
|
|
||
| $form['help'] = [ | ||
| '#type' => 'details', | ||
| '#title' => $this->t('Examples'), | ||
| '#open' => FALSE, | ||
| ]; | ||
|
|
||
| $form['help']['examples'] = [ | ||
| '#markup' => $this->t('<p>Common sensitive fields include:</p> | ||
| <ul> | ||
| <li><code>field_ssn</code> - Social Security Numbers</li> | ||
| <li><code>pass</code> - User passwords</li> | ||
| <li><code>field_bank_account</code> - Banking information</li> | ||
| <li><code>field_credit_card</code> - Payment information</li> | ||
| <li><code>field_api_key</code> - API keys or tokens</li> | ||
| </ul> | ||
| <p><strong>Note:</strong> The following fields are automatically excluded from logging: <code>changed</code>, <code>revision_timestamp</code>, <code>revision_uid</code>, <code>revision_log</code>. Additionally, computed and internal fields are never logged.</p>'), | ||
| ]; | ||
|
|
||
| return parent::buildForm($form, $form_state); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function submitForm(array &$form, FormStateInterface $form_state) { | ||
| // Convert textarea input to array. | ||
| $sensitive_fields_raw = $form_state->getValue('sensitive_fields'); | ||
| $sensitive_fields = array_filter( | ||
| array_map('trim', explode("\n", $sensitive_fields_raw)), | ||
| function ($field) { | ||
| return !empty($field); | ||
| } | ||
| ); | ||
|
|
||
| $this->config('uceap_logging.settings') | ||
| ->set('sensitive_fields', array_values($sensitive_fields)) | ||
| ->save(); | ||
|
|
||
| parent::submitForm($form, $form_state); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Create a default tab for the system logging page | ||
| system.logging_settings_default: | ||
| title: 'Settings' | ||
| route_name: system.logging_settings | ||
| base_route: system.logging_settings | ||
| weight: 0 | ||
|
|
||
| # Add our custom tab | ||
| uceap_logging.settings: | ||
| title: 'UCEAP Logging' | ||
| route_name: uceap_logging.settings | ||
| base_route: system.logging_settings | ||
| weight: 10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,12 +115,8 @@ function _uceap_logging_get_entity_field_changes(ContentEntityInterface $entity, | |
| ]; | ||
|
|
||
| // Sensitive fields that should have values masked in logs. | ||
| // TODO make this configurable. | ||
| $sensitive_fields = [ | ||
| 'field_ssn', | ||
| 'field_confirm_ssn', | ||
| 'pass', | ||
| ]; | ||
| $config = \Drupal::config('uceap_logging.settings'); | ||
| $sensitive_fields = $config->get('sensitive_fields') ?? []; | ||
|
Comment on lines
+118
to
+119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a benefit to using config over state? I guess with config you can review the file directly versus have to look in the binary blob of the database.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the fields themselves exist in config it feels like the field list does too. Lets us cleanly deploy updates to both (new sensitive field added? new |
||
|
|
||
| $changes = []; | ||
| $field_definitions = $entity->getFieldDefinitions(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| uceap_logging.settings: | ||
| path: '/admin/config/development/logging/uceap' | ||
| defaults: | ||
| _form: '\Drupal\uceap_logging\Form\LoggingSettingsForm' | ||
| _title: 'Logging Settings' | ||
| requirements: | ||
| _permission: 'administer site configuration' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a PR with a suggestion to make the list selectable #3