Skip to content

ZOOKEEPER-1260:Audit logging in ZooKeeper servers. - #1105

Closed
arshadmohammad wants to merge 4 commits into
apache:branch-3.5from
arshadmohammad:ZOOKEEPER-1260-AuditLog
Closed

ZOOKEEPER-1260:Audit logging in ZooKeeper servers.#1105
arshadmohammad wants to merge 4 commits into
apache:branch-3.5from
arshadmohammad:ZOOKEEPER-1260-AuditLog

Conversation

@arshadmohammad

Copy link
Copy Markdown
Contributor

Original PR: #338

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very interesting and useful.

I left a few comments, please take a look


public class ZKUtil {
private static final Logger LOG = LoggerFactory.getLogger(ZKUtil.class);
private static final Map<Integer, String> permCache = new HashMap<Integer, String>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ConcurrentHashMap?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.


## ZooKeeper Audit Logs

Apache ZooKeeper supports audit logs form version 3.5.7. By default audit logs are disabled. To enable audit logs configure audit.enable=true in conf/zoo.cfg. Audit logs are not logged on all the ZooKeeper servers, but logged only on the servers where client is connected as depicted in below figure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: form -> from.

I think we should say 3.6.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR I have raised for branch-3.5. After commit I will raise PR for master branch that time I will change this to 3.6.0. Branch releases are independent. I think this way we can be bit more accurate. In last PR was discussed but on second thought this would be the better way.
are you ok with 3.5.7 for branch-5 and 3.6..0 for master?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

corrected typo


public String getUserName() {
if (principal == null || principal.isEmpty()) {
return System.getProperty("user.name", "<NA>");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can sample the value as a static variable. You will save an access to the system properties map

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* @return string representation of permissions
*/
public static String getPermString(int perms) {
String permString = permCache.get(perms);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about using computeIfAbsent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nice

*/
package org.apache.zookeeper.audit;

public class AuditConstants {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

final

Please also add a private constructor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

}

private String getACLs(Request request) {
ByteBuffer reqData = request.request.duplicate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about 'slice'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, done

String address = null;
String acls = null;
String createMode = null;
ByteBuffer reqData = request.request.duplicate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

*/
static final ByteBuffer closeConn = ByteBuffer.allocate(0);

private static String loginUser = System.getProperty("user.name", "<NA>");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

final?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think loginUser can not be marked as final

/**
* Audit log performance reading
*/
public class AuditLogPerfReading {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

final?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

return parentPath + "zNode" + i;
}

public static void main(String[] args) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this program really needed? Or is it just a tool you used to profile this new code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This program was just to see the performance impact of audit log. I added here so anybody can run and see the audit log impact on their environment. Also it is added test folder.

@anmolnar anmolnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@arshadmohammad This is a very useful and long awaited feature. Thanks for working on this.
Without going into the implementation details, I believe it would be better to finalize and submit the code into master and we can talk about backporting to 3.5 after that. We have to ask the community, because 3.5 is already locked down for new features and release process of 3.6 has already been started.

@anmolnar

anmolnar commented Oct 4, 2019

Copy link
Copy Markdown
Contributor

In terms of the implementation: would you please make the ZKAuditLogger implementation pluggable similarly to zookeeper.clientCnxnSocket. Later we might start to work on Ranger integration and a pluggable audit logger would be very useful.

@anmolnar

anmolnar commented Oct 8, 2019

Copy link
Copy Markdown
Contributor

@arshadmohammad Fyi. I'm happy to take this over and continue working on it, if you don't have cycles for that. Please let me know.

@arshadmohammad

arshadmohammad commented Oct 11, 2019

Copy link
Copy Markdown
Contributor Author

... because 3.5 is already locked down for new features and release process of 3.6 has already been started.

I think it is locked for backward incompatible features, not for all features and this feature is not backward incompatible.

@arshadmohammad

Copy link
Copy Markdown
Contributor Author

In terms of the implementation: would you please make the ZKAuditLogger implementation pluggable similarly to zookeeper.clientCnxnSocket. Later we might start to work on Ranger integration and a pluggable audit logger would be very useful.

Sure, I will make it configurable.

@anmolnar

anmolnar commented Nov 3, 2019

Copy link
Copy Markdown
Contributor

@arshadmohammad PR hasn't been updated for 24 days. How are you getting on?
I'm still happy to take this over and move forward.

@arshadmohammad

Copy link
Copy Markdown
Contributor Author

@anmolnar, I will update the patch soon, hopefully by tomorrow. Will try to wind up this work by this weekend

@arshadmohammad

Copy link
Copy Markdown
Contributor Author

Addressed all the comments and created PR for master branch.
#1133

@arshadmohammad

Copy link
Copy Markdown
Contributor Author

Feature is merged in PR #1133

@arshadmohammad
arshadmohammad deleted the ZOOKEEPER-1260-AuditLog branch December 25, 2019 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants