diff --git a/app/controllers/ldap/omniauth_callbacks_controller.rb b/app/controllers/ldap/omniauth_callbacks_controller.rb index 1c79bd3a668e1283ec7ebe8f84af03e9442ac32b..1dad923eae6d6ce354f4faa5ab8ae707afe66e74 100644 --- a/app/controllers/ldap/omniauth_callbacks_controller.rb +++ b/app/controllers/ldap/omniauth_callbacks_controller.rb @@ -50,6 +50,11 @@ def available_providers server['provider_name'] end end + + override :log_audit_event + def log_audit_event(user, options = {}) + super(user, options, 'authenticated_with_ldap') + end end Ldap::OmniauthCallbacksController.prepend_mod_with('Ldap::OmniauthCallbacksController') diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 95c5ab399203656097db0bdb46f44b603ed9f22b..0a72d94a5336425598cab032cd96523e6b32d9ca 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -365,9 +365,23 @@ def handle_disabled_provider redirect_to new_user_session_path end - def log_audit_event(user, options = {}) - AuditEventService.new(user, user, options) - .for_authentication.security_event + def log_audit_event(user, options = {}, name = 'authenticated_with_oauth') + return if options[:with].blank? + + provider = options[:with] + audit_context = { + name: name, + author: user, + scope: user, + target: user, + message: "Signed in with #{provider.upcase} authentication", + authentication_event: true, + authentication_provider: provider, + additional_details: { + with: provider + } + } + ::Gitlab::Audit::Auditor.audit(audit_context) end def set_remember_me(user, auth_user) diff --git a/config/audit_events/types/authenticated_with_ldap.yml b/config/audit_events/types/authenticated_with_ldap.yml new file mode 100644 index 0000000000000000000000000000000000000000..8f192b86c30e9c21b49a2b4b3394739ea37be9a9 --- /dev/null +++ b/config/audit_events/types/authenticated_with_ldap.yml @@ -0,0 +1,10 @@ +--- +name: authenticated_with_ldap +description: User successfully signed in with LDAP +introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/issues/509377 +introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/175763 +milestone: '17.11' +feature_category: system_access +saved_to_database: true +streamed: true +scope: [User] \ No newline at end of file diff --git a/config/audit_events/types/authenticated_with_oauth.yml b/config/audit_events/types/authenticated_with_oauth.yml new file mode 100644 index 0000000000000000000000000000000000000000..cb9213936600cd6c67653e9728a87bf78057afbc --- /dev/null +++ b/config/audit_events/types/authenticated_with_oauth.yml @@ -0,0 +1,10 @@ +--- +name: authenticated_with_oauth +description: User successfully signed in with OAuth +introduced_by_issue: https://gitlab.com/gitlab-org/gitlab/-/issues/509377 +introduced_by_mr: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/175763 +milestone: '17.11' +feature_category: system_access +saved_to_database: true +streamed: true +scope: [User] \ No newline at end of file diff --git a/doc/user/compliance/audit_event_types.md b/doc/user/compliance/audit_event_types.md index 1d324ddff409399c785835b2c1968930c069194b..487e48a818658649476b413b2f34d6c128e56ed7 100644 --- a/doc/user/compliance/audit_event_types.md +++ b/doc/user/compliance/audit_event_types.md @@ -622,6 +622,8 @@ Audit event types belong to the following product categories. | [`user_access_unlocked`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/124973) | User access to the instance is unlocked | {{< icon name="check-circle" >}} Yes | GitLab [16.2](https://gitlab.com/gitlab-org/modelops/anti-abuse/team-tasks/-/issues/244) | User | | [`user_disable_two_factor`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/89598) | A user disables two factor authentication. Group scope was [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/171988) in GitLab 17.6. | {{< icon name="check-circle" >}} Yes | GitLab [15.1](https://gitlab.com/gitlab-org/gitlab/-/issues/238177) | User, Group | | [`user_enable_admin_mode`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/104754) | Admin Mode enabled | {{< icon name="check-circle" >}} Yes | GitLab [15.7](https://gitlab.com/gitlab-org/gitlab/-/issues/362101) | User | +| [`authenticated_with_ldap`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/175763) | User successfully signed in with LDAP | {{< icon name="check-circle" >}} Yes | GitLab [17.11](https://gitlab.com/gitlab-org/gitlab/-/issues/509377) | User | +| [`authenticated_with_oauth`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/175763) | User successfully signed in with OAuth | {{< icon name="check-circle" >}} Yes | GitLab [17.11](https://gitlab.com/gitlab-org/gitlab/-/issues/509377) | User | ### Team planning diff --git a/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb b/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb index b16f8ad1a5811ee7ab55b773d3b5b0009449b535..7c5da98ab333ab68b3470db5a84d6289bc6ebaeb 100644 --- a/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/ldap/omniauth_callbacks_controller_spec.rb @@ -16,6 +16,12 @@ expect(AuthenticationEvent.last.provider).to eq(provider.to_s) end + it 'creates an authentication audit event' do + expect { post provider }.to change { + AuditEvent.where("details LIKE '%authenticated_with_ldap%'").count + }.by(1) + end + context 'with sign in prevented' do let(:ldap_settings) { ldap_setting_defaults.merge(prevent_ldap_sign_in: true) } diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index 7c86bca02a035a0c8bb16e6da1f6dc86efdde17c..3eb19a0693d02b0909f665e85dcb709239ae6309 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -129,11 +129,17 @@ expect { post(provider) }.to( change do Gitlab::Metrics.registry - .get(:gitlab_omniauth_login_total) - .get(omniauth_provider: 'github', status: 'succeeded') + .get(:gitlab_omniauth_login_total) + .get(omniauth_provider: 'github', status: 'succeeded') end.by(1) ) end + + it 'creates an authentication audit event' do + expect { post provider }.to change { + AuditEvent.where("details LIKE '%authenticated_with_oauth%'").count + }.by(1) + end end context 'with signed-in user' do