Resolve "[Backend] Set instance-level external audit event destination"
What does this MR do and why?
What?
This MR does following things:
- Adds following columns to
application_settings table
:-
audit_events_external_destination
text field with character limit of 255, this will hold the url for instance level external audit events. -
enable_external_audit_events
which is a boolean field and determines whether instance level audit events should be sent or not to external destination.
-
- Changes in EE application settings API for updating and fetching the values of these attributes.
- Added these feature behind a new feature flag
ff_external_audit_events
. - Adds documentation for the change in API.
Why?
- We want to send instance level audit events to external destination so for that we need to first configure the instance with the url of remote destination.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
- After checking out the branch, run
bin/rails db:migrate RAILS_ENV=development
for running the migration added in this MR. - Since we are making changes in application settings API, it can only be accessed by the instance admin so please use private token of instance admin only in the mentioned APIs.
- Curl command for fetching the application settings is
curl --location 'http://gitlab.localdev:3000/api/v4/application/settings' --header 'PRIVATE-TOKEN: 3mayNtX-aGEiPnumayhz' --header 'Content-Type: application/json'
- Curl command for updating application settings is
curl --location --request PUT 'http://gitlab.localdev:3000/api/v4/application/settings?audit_events_external_destination=https%3A%2F%2Fwww.example1.com&enable_external_audit_events=true' --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' --header 'Content-Type: application/json'
. - When the feature flag
ff_external_audit_events
is enabled and the instance has the ULTIMATE license, then only the admin will be able to fetch and update the parametersaudit_events_external_destination
andenable_external_audit_events
, otherwise these params will not be returned in the GET call and while updating them, the response will be with error code 400. - Feature flag can be enabled and disabled by running
Feature.enable(:ff_external_audit_events)
andFeature.disable(:ff_external_audit_events)
respectively in rails console.
Migration output
Up
RAILS_ENV=development bin/rails db:migrate:up:main VERSION=20230302180816
main: == 20230302180816 AddAuditExternalDestinationToApplicationSettings: migrating =
main: -- add_column(:application_settings, :audit_events_external_destination, :text, {:if_not_exists=>true})
main: -> 0.1738s
main: -- transaction_open?()
main: -> 0.0000s
main: -- transaction_open?()
main: -> 0.0000s
main: -- execute("ALTER TABLE application_settings\nADD CONSTRAINT check_04131de188\nCHECK ( char_length(audit_events_external_destination) <= 255 )\nNOT VALID;\n")
main: -> 0.0012s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0002s
main: -- execute("ALTER TABLE application_settings VALIDATE CONSTRAINT check_04131de188;")
main: -> 0.0006s
main: -- execute("RESET statement_timeout")
main: -> 0.0002s
main: -- add_column(:application_settings, :enable_external_audit_events, :boolean, {:default=>false, :null=>false})
main: -> 0.0016s
main: == 20230302180816 AddAuditExternalDestinationToApplicationSettings: migrated (0.1955s)
Down
RAILS_ENV=development bin/rails db:migrate:down:main VERSION=20230302180816
main: == 20230302180816 AddAuditExternalDestinationToApplicationSettings: reverting =
main: -- remove_column(:application_settings, :audit_events_external_destination)
main: -> 0.0050s
main: -- remove_column(:application_settings, :enable_external_audit_events)
main: -> 0.0032s
main: == 20230302180816 AddAuditExternalDestinationToApplicationSettings: reverted (0.0329s)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #335175 (closed)
Edited by Hitesh Raghuvanshi