Skip to content
代码片段 群组 项目
未验证 提交 7a76a2c6 编辑于 作者: Smriti Garg's avatar Smriti Garg 提交者: GitLab
浏览文件

Changes for allowed_email_domain update audit event

Group setting allowed_email_domains update is an admin action
and must be audited

Changelog: added
上级 97cbd304
No related branches found
No related tags found
无相关合并请求
...@@ -298,6 +298,7 @@ Audit event types belong to the following product categories. ...@@ -298,6 +298,7 @@ Audit event types belong to the following product categories.
|:------------|:------------|:------------------|:---------|:--------------|:--------------| |:------------|:------------|:------------------|:---------|:--------------|:--------------|
| [`allow_mfa_for_subgroups_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when setting for Subgroups can set up their own two-factor authentication rules updated | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [17.4](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group | | [`allow_mfa_for_subgroups_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when setting for Subgroups can set up their own two-factor authentication rules updated | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [17.4](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group |
| [`allow_runner_registration_token_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when setting Allow members of projects and groups to create runners with runner registration tokens is updated | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.0](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group, Project | | [`allow_runner_registration_token_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when setting Allow members of projects and groups to create runners with runner registration tokens is updated | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.0](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group, Project |
| [`allowed_email_domain_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/166105) | Triggered when group setting allowed email domain entry is updated | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [17.5](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group |
| [`create_ssh_certificate`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/134556) | Triggered when an SSH certificate is created | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.6](https://gitlab.com/gitlab-org/gitlab/-/issues/427413) | Group | | [`create_ssh_certificate`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/134556) | Triggered when an SSH certificate is created | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.6](https://gitlab.com/gitlab-org/gitlab/-/issues/427413) | Group |
| [`default_branch_name_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when default branch name for the group repository is changed | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [17.4](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group | | [`default_branch_name_updated`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/164973) | Triggered when default branch name for the group repository is changed | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [17.4](https://gitlab.com/gitlab-org/gitlab/-/issues/486532) | Group |
| [`delete_ssh_certificate`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/134556) | Triggered when an SSH certificate is deleted | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.6](https://gitlab.com/gitlab-org/gitlab/-/issues/427413) | Group | | [`delete_ssh_certificate`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/134556) | Triggered when an SSH certificate is deleted | **{check-circle}** Yes | **{check-circle}** Yes | GitLab [16.6](https://gitlab.com/gitlab-org/gitlab/-/issues/427413) | Group |
......
...@@ -30,6 +30,23 @@ def execute ...@@ -30,6 +30,23 @@ def execute
build_new_allowed_emails_domains_records build_new_allowed_emails_domains_records
end end
def log_audit_event(updated_domain_list)
return unless existing_domains && updated_domain_list
return if updated_domain_list.sort == existing_domains.sort
message = "Allowed email domain names updated from '#{existing_domains.join(',')}' to '#{updated_domain_list.join(',')}'"
::Gitlab::Audit::Auditor.audit({
name: "allowed_email_domain_updated",
author: current_user,
scope: group,
target: group,
target_details: group.path,
message: _(message)
})
end
private private
attr_reader :current_user, :group, :current_domains attr_reader :current_user, :group, :current_domains
......
...@@ -133,7 +133,10 @@ def handle_allowed_email_domains_update ...@@ -133,7 +133,10 @@ def handle_allowed_email_domains_update
comma_separated_domains = params.delete(:allowed_email_domains_list) comma_separated_domains = params.delete(:allowed_email_domains_list)
AllowedEmailDomains::UpdateService.new(current_user, group, comma_separated_domains).execute # rubocop:disable Gitlab/ModuleWithInstanceVariables -- Reason: We need this instance to log audit event post save
@allowed_email_domains_update_service = AllowedEmailDomains::UpdateService.new(current_user, group, comma_separated_domains)
@allowed_email_domains_update_service.execute
# rubocop:enable Gitlab/ModuleWithInstanceVariables
end end
override :allowed_settings_params override :allowed_settings_params
...@@ -143,6 +146,7 @@ def allowed_settings_params ...@@ -143,6 +146,7 @@ def allowed_settings_params
def log_audit_events def log_audit_events
@ip_restriction_update_service&.log_audit_event # rubocop:disable Gitlab/ModuleWithInstanceVariables @ip_restriction_update_service&.log_audit_event # rubocop:disable Gitlab/ModuleWithInstanceVariables
@allowed_email_domains_update_service&.log_audit_event(group.allowed_email_domains.map(&:domain)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
Audit::GroupChangesAuditor.new(current_user, group).execute Audit::GroupChangesAuditor.new(current_user, group).execute
end end
......
---
name: allowed_email_domain_updated
description: Triggered when group setting allowed email domain entry is updated
introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/issues/486532
introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/166105
feature_category: groups_and_projects
milestone: '17.5'
saved_to_database: true
streamed: true
scope: [Group]
...@@ -32,9 +32,7 @@ ...@@ -32,9 +32,7 @@
allow(group).to receive(:save).and_return(false) allow(group).to receive(:save).and_return(false)
end end
def operation let(:operation_params) { { visibility_level: Gitlab::VisibilityLevel::PRIVATE } }
update_group(group, user, visibility_level: Gitlab::VisibilityLevel::PRIVATE)
end
let(:attributes) do let(:attributes) do
audit_event_params.tap do |param| audit_event_params.tap do |param|
...@@ -61,9 +59,7 @@ def operation ...@@ -61,9 +59,7 @@ def operation
allow(group).to receive(:save).and_return(false) allow(group).to receive(:save).and_return(false)
end end
def operation let(:operation_params) { { ip_restriction_ranges: '192.168.0.0/24,10.0.0.0/8' } }
update_group(group, user, ip_restriction_ranges: '192.168.0.0/24,10.0.0.0/8')
end
let(:attributes) do let(:attributes) do
audit_event_params.tap do |param| audit_event_params.tap do |param|
...@@ -76,6 +72,35 @@ def operation ...@@ -76,6 +72,35 @@ def operation
end end
end end
end end
describe 'allowed email domain' do
context 'when allowed email domains were changed' do
before do
group.add_owner(user)
end
include_examples 'audit event logging' do
let(:fail_condition!) do
allow(group).to receive(:save).and_return(false)
end
let(:operation_params) { { allowed_email_domains_list: 'abcd.com,test.com' } }
let(:attributes) do
audit_event_params.tap do |param|
param[:details].merge!(
event_name: 'allowed_email_domain_updated',
custom_message: "Allowed email domain names updated from '' to 'abcd.com,test.com'"
)
end
end
end
end
end
def operation(update_params = operation_params)
update_group(group, user, **update_params)
end
end end
context 'sub group' do context 'sub group' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册