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

authz: add audit logging APIs #6158

Merged
merged 16 commits into from Apr 18, 2023
Merged

authz: add audit logging APIs #6158

merged 16 commits into from Apr 18, 2023

Conversation

rockspore
Copy link
Contributor

@rockspore rockspore commented Mar 30, 2023

Implements interfaces for pending gRFC A59: https://github.com/grpc/proposal/pull/346/files

RELEASE NOTES: N/A

@rockspore rockspore marked this pull request as ready for review March 30, 2023 18:10
@rockspore rockspore requested a review from dfawley March 30, 2023 18:10
@rockspore
Copy link
Contributor Author

One small thing to note is that I removed context.Context from the Log() method of the logger. It's not really needed and to be consistent with other languages, we will not offer the method any additional information than the AuditInfo.

@dfawley dfawley changed the title [Audit Logging] add audit logging APIs authz: add audit logging APIs Mar 30, 2023
@dfawley dfawley added this to the 1.55 Release milestone Mar 30, 2023
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
@rockspore rockspore requested a review from dfawley March 31, 2023 20:14
@dfawley dfawley assigned dfawley and unassigned rockspore Mar 31, 2023
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
authz/audit_logger.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned rockspore and unassigned dfawley Apr 6, 2023
@rockspore
Copy link
Contributor Author

Regarding a separate auditlog pkg, that was the original proposal and was discussed offline. While I am pretty neutral on this, IIRC, the reasoning was that separate packages always added incremental costs and everything here would only be consumed within authz with no plan to add anything to make audit logging more standalone and separate from authorization. Therefore, although variable and func names have to be more verbose, putting everything in authz actually makes it clear and convenient for users.

Comment on lines 39 to 44
// RegisterAuditLoggerBuilder registers the builder in a global map
// using b.Name() as the key.
// This should only be called during initialization time (i.e. in an init()
// function).
// If multiple builders are registered with the same name, the one registered
// last will take effect.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit

Suggested change
// RegisterAuditLoggerBuilder registers the builder in a global map
// using b.Name() as the key.
// This should only be called during initialization time (i.e. in an init()
// function).
// If multiple builders are registered with the same name, the one registered
// last will take effect.
// RegisterAuditLoggerBuilder registers the builder in a global map
// using b.Name() as the key.
//
// This should only be called during initialization time (i.e. in an init()
// function). If multiple builders are registered with the same name,
// the one registered last will take effect.

Comment on lines 59 to 60
// AuditEvent contains information used by the audit logger during an audit
// logging event.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about?

Suggested change
// AuditEvent contains information used by the audit logger during an audit
// logging event.
// AuditEvent contains information passed to the audit logger as part of
// an audit logging event.

Comment on lines 77 to 83
// AuditLoggerConfig defines the configuration for a particular implementation
// of audit logger.
type AuditLoggerConfig interface {
// auditLoggerConfig is a dummy interface requiring users to embed this
// interface to implement it.
auditLoggerConfig()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This would currently show up as follows in the godoc:

// AuditLoggerConfig defines the configuration for a particular implementation
// of audit logger.
type AuditLoggerConfig interface {
    // contains filtered or unexported methods
}

Consider changing this to:

// AuditLoggerConfig represents an opaque data structure holding an audit
// logger configuration. Concrete types representing configuration of specific
// audit loggers must embed this interface to implement it.
type AuditLoggerConfig interface {
	// auditLoggerConfig is a dummy interface requiring users to embed this
	// interface to implement it.
	auditLoggerConfig()
}

Comment on lines 97 to 101
// Log does audit logging with the given information in the audit event.
// This method will be executed synchronously by gRPC so implementers must
// keep in mind it must not block the RPC. Specifically, time-consuming
// processes should be fired asynchronously such that this method can
// return immediately.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

Suggested change
// Log does audit logging with the given information in the audit event.
// This method will be executed synchronously by gRPC so implementers must
// keep in mind it must not block the RPC. Specifically, time-consuming
// processes should be fired asynchronously such that this method can
// return immediately.
// Log performs audit logging for the provided audit event.
//
// This method is invoked in the RPC path and therefore implementations
// must not block.

Comment on lines 85 to 92
// AuditLogger is the interface for an audit logger.
// An audit logger is a logger instance that can be configured to use via the
// authorization policy or xDS HTTP RBAC filters. When the authorization
// decision meets the condition for audit, all the configured audit loggers'
// Log() method will be invoked to log that event with the AuditInfo.
// The method will be executed synchronously before the authorization is
// complete and the call is denied or allowed.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AuditLogger is the interface for an audit logger.
// An audit logger is a logger instance that can be configured to use via the
// authorization policy or xDS HTTP RBAC filters. When the authorization
// decision meets the condition for audit, all the configured audit loggers'
// Log() method will be invoked to log that event with the AuditInfo.
// The method will be executed synchronously before the authorization is
// complete and the call is denied or allowed.
//
// AuditLogger is the interface to be implemented by audit loggers.
//
// An audit logger is a logger instance that can be configured via the
// authorization policy API or xDS HTTP RBAC filters. When the authorization
// decision meets the condition for audit, all the configured audit loggers'
// Log() method will be invoked to log that event.

Skipping the line about the method being invoked inline since the same is mentioned in the docstring for Log.

Comment on lines 105 to 112
// AuditLoggerBuilder is the interface for an audit logger builder.
// It parses and validates a config, and builds an audit logger from the parsed
// config. This enables configuring and instantiating audit loggers in the
// runtime. Users that want to implement their own audit logging logic should
// implement this along with the AuditLogger interface and register this
// builder by calling RegisterAuditLoggerBuilder() before they start the gRPC
// server.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// AuditLoggerBuilder is the interface for an audit logger builder.
// It parses and validates a config, and builds an audit logger from the parsed
// config. This enables configuring and instantiating audit loggers in the
// runtime. Users that want to implement their own audit logging logic should
// implement this along with the AuditLogger interface and register this
// builder by calling RegisterAuditLoggerBuilder() before they start the gRPC
// server.
//
// AuditLoggerBuilder is the interface to be implemented by audit logger
// builders that are used at runtime to configure and instantiate audit loggers.
//
// Users who want to implement their own audit logging logic should
// implement this interface, along with the AuditLogger interface, and register it
// by calling RegisterAuditLoggerBuilder() at init time.
//

Comment on lines 119 to 120
// When users implement this method, its return type must embed the
// AuditLoggerConfig interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is mentioned in the docstring of the AuditLoggerConfig. I would consider skipping it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rockspore
Copy link
Contributor Author

Thanks a lot for the suggested revision of those comments! They definitely document the APIs in a clearer way. I took all the suggestions. @easwars

Copy link
Contributor

@gtcooke94 gtcooke94 left a comment

Choose a reason for hiding this comment

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

LGTM

@rockspore rockspore requested a review from easwars April 11, 2023 20:55
Comment on lines 81 to 82
// auditLoggerConfig is a dummy interface requiring users to embed this
// interface to implement it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: these two lines can be removed.

@easwars
Copy link
Contributor

easwars commented Apr 11, 2023

@rockspore
How soon do you want this merged? I see that @dfawley had requested some changes and I think you have handled all of those. If this can wait till next week, then we can wait for him to come back, take another look and then merge. If this needs to go in asap, I will have to dismiss his review to be able to merge this. Let me know how you want to proceed. Thanks.

@rockspore
Copy link
Contributor Author

@rockspore How soon do you want this merged? I see that @dfawley had requested some changes and I think you have handled all of those. If this can wait till next week, then we can wait for him to come back, take another look and then merge. If this needs to go in asap, I will have to dismiss his review to be able to merge this. Let me know how you want to proceed. Thanks.

Thanks. I'll leave this to @gtcooke94 who will follow up with the rest of work in Go.

@rockspore rockspore assigned gtcooke94 and unassigned rockspore Apr 11, 2023
@gtcooke94
Copy link
Contributor

I'm good to wait for @dfawley, shouldn't be a diff of more than a few days

@dfawley dfawley merged commit aa8c137 into grpc:master Apr 18, 2023
11 checks passed
@rockspore rockspore deleted the audit-log-api branch April 18, 2023 17:28
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants