Skip to content
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

Added Audit logging to new user creation #17852

Merged
merged 3 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/models/authenticator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def authenticate(username, password, request = nil, options = {})
user_or_taskid = nil

begin
audit = {:event => audit_event, :userid => username}

username = normalize_username(username)
audit = {:event => audit_event, :userid => username}

authenticated = options[:authorize_only] || _authenticate(username, password, request)
if authenticated
Expand Down Expand Up @@ -124,6 +123,7 @@ def authorize(taskid, username, *args)
matching_groups = match_groups(groups_for(identity))
userid, user = find_or_initialize_user(identity, username)
update_user_attributes(user, userid, identity)
audit_new_user(audit, user) if user.new_record?
user.miq_groups = matching_groups

if matching_groups.empty?
Expand Down Expand Up @@ -195,6 +195,10 @@ def audit_event
"authenticate_#{self.class.short_name}"
end

def audit_new_user(audit, user)
audit_success(audit.merge(:message => "User creation successful for User: #{user.name} with ID: #{user.userid}"))
end

def authorize?
config[:"#{self.class.short_name}_role"] == true
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/authenticator/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def authenticate
it "records two successful audit entries" do
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_database',
:userid => 'vInCeNt',
:userid => 'vincent',
:message => "User vincent successfully validated by EVM",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_database',
:userid => 'vInCeNt',
:userid => 'vincent',
:message => "Authentication successful for user vincent",
)
expect(AuditEvent).not_to receive(:failure)
Expand Down
27 changes: 19 additions & 8 deletions spec/models/authenticator/httpd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ def authenticate
it "records one successful and one failing audit entry" do
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "User bob successfully validated by External httpd",
)
expect(AuditEvent).to receive(:failure).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "User bob authenticated but not defined in EVM",
)
authenticate rescue nil
Expand All @@ -370,15 +370,21 @@ def authenticate
expect(authenticate).to eq(123)
end

it "records two successful audit entries" do
it "records three successful audit entries" do
expect(AuditEvent).to receive(:success).with(
:event => 'authorize',
:userid => 'bob',
:message => "User creation successful for User: Bob Builderson with ID: [email protected]",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "User bob successfully validated by External httpd",
)

expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "Authentication successful for user bob",
)
expect(AuditEvent).not_to receive(:failure)
Expand All @@ -405,15 +411,20 @@ def authenticate
expect(authenticate).to eq(123)
end

it "records two successful audit entries plus one failure" do
it "records three successful audit entries plus one failure" do
expect(AuditEvent).to receive(:success).with(
:event => 'authorize',
:userid => 'bob',
:message => "User creation successful for User: Bob Builderson with ID: [email protected]",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "User bob successfully validated by External httpd",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_httpd',
:userid => 'bOb',
:userid => 'bob',
:message => "Authentication successful for user bob",
)
expect(AuditEvent).to receive(:failure).with(
Expand Down
16 changes: 13 additions & 3 deletions spec/models/authenticator/ldap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def authenticate
expect(authenticate).to eq(123)
end

it "records two successful audit entries" do
it "records three successful audit entries" do
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_ldap',
:userid => 'alice',
Expand Down Expand Up @@ -408,12 +408,17 @@ def authenticate
expect(authenticate).to eq(123)
end

it "records two successful audit entries" do
it "records three successful audit entries" do
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_ldap',
:userid => 'bob',
:message => "User bob successfully validated by LDAP",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authorize',
:userid => 'bob',
:message => "User creation successful for User: Bob Builderson with ID: bob",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_ldap',
:userid => 'bob',
Expand Down Expand Up @@ -443,12 +448,17 @@ def authenticate
expect(authenticate).to eq(123)
end

it "records two successful audit entries plus one failure" do
it "records three successful audit entries plus one failure" do
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_ldap',
:userid => 'bob',
:message => "User bob successfully validated by LDAP",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authorize',
:userid => 'bob',
:message => "User creation successful for User: Bob Builderson with ID: bob",
)
expect(AuditEvent).to receive(:success).with(
:event => 'authenticate_ldap',
:userid => 'bob',
Expand Down