Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

auth: add Audit to log user interactions #536

Merged
merged 5 commits into from
Nov 7, 2018

Conversation

jfontan
Copy link
Contributor

@jfontan jfontan commented Nov 6, 2018

Audit is an auth.Auth wrapper that does audit trail calls to log user
interaction. An AuditMethod implements functions that are called when
authentication, authorization or query is used.

userAuth, _ := auth.NewNativeFile(userFile)
audit := auth.NewAuditLog(logrus.New())
userAuth = auth.NewAudit(userAuth, audit)

Audit can be wrapped by another Audit chaining several AuditMethod. Here
only AuditLog, that sends the data to logrus, is implemented.
Some changes had to be done to previous auth version and context:

  • sql.Context now holds the current query
  • Auth.Allowed now takes sql.Context as argument
  • If Auth is an Audit its Query method is called by engine
  • Authorization check is done in engine instead of analyzer

Fixes: #496

Audit is an auth.Auth wrapper that does audit trail calls to log user
interaction. An AuditMethod implements functions that are called when
authentication, authorization or query is used.

    userAuth, _ := auth.NewNativeFile(userFile)
    audit := auth.NewAuditLog(logrus.New())
    userAuth = auth.NewAudit(userAuth, audit)

Audit can be wrapped by another Audit chaining several AuditMethod. Here
only AuditLog, that sends the data to logrus, is implemented.
Some changes had to be done to previous auth version and context:

* sql.Context now holds the current query
* Auth.Allowed now takes sql.Context as argument

Note: Query is still not used in this code.

Signed-off-by: Javi Fontan <[email protected]>
This makes it more controllable and uses auth from engine. Previously
it had to be added to the rules with the builder.

Signed-off-by: Javi Fontan <[email protected]>
This new call logs queries even when they have an error and show how
much time they took.

Signed-off-by: Javi Fontan <[email protected]>
@jfontan jfontan requested a review from a team November 6, 2018 13:34
auth/audit.go Outdated
}
}

var auditLogMessage = "audit trail"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it be a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@ajnavarro ajnavarro merged commit 5749664 into src-d:master Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants