-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: add plugin metadata to audit logging #19814
feat: add plugin metadata to audit logging #19814
Conversation
fee59cf
to
bbac92c
Compare
c3ff2e9
to
2206548
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good to me. It would be great to get some tests. There is an example of a test that enables audit logging to a file here that you could use as a basis:
vault/vault/logical_system_test.go
Lines 3432 to 3445 in 3c2faf2
tempDir := t.TempDir() | |
f, err := os.CreateTemp(tempDir, "") | |
if err != nil { | |
t.Fatal(err) | |
} | |
// Enable audit logging. | |
req := logical.TestRequest(t, logical.UpdateOperation, "audit/file") | |
req.Data = map[string]any{ | |
"type": "file", | |
"options": map[string]any{ | |
"file_path": f.Name(), | |
}, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Echoing what Tom said, adding some tests would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Just a question and a few small nits.
audit/format.go
Outdated
|
||
// getMountClass returns the mount class based the mount accessor of a logical.Request. | ||
func getMountClass(req *logical.Request) string { | ||
if req.MountAccessor == "" || strings.HasPrefix(req.Path, "sys/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if the request is under a namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this works if the request is under a namespace since req.Path
has the namespace trimmed further up in the call stack. For example, in buildLogicalRequestNoAuth()
that constructs logical.Request
, logical.Request.Path
is made from namespace-trimmed http.Request.URL.Path
https://github.com/hashicorp/vault/blob/main/http/logical.go#L53.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to use add MountClass()
to MountEntry
instead of using logical.Request.Path
as MountEntry.Path
doesn't have a namespace.
// APIPath returns the full API Path for the given mount entry
func (e *MountEntry) APIPath() string {
path := e.Path
if e.Table == credentialTableType {
path = credentialRoutePrefix + path
}
return e.namespace.Path + path
}
// APIPathNoNamespace returns the API Path without the namespace for the given mount entry
func (e *MountEntry) APIPathNoNamespace() string {
path := e.Path
if e.Table == credentialTableType {
path = credentialRoutePrefix + path
}
return path
}
e67dfff
to
a0891d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I pulled this down and tested it locally with namespaces as well, and it seems to work,
e.g.,
$ VAULT_NAMESPACE=testns vault write auth/approle/role/example-dot-com ...
...
"request": {
"id": "9bd6a564-6046-6e16-5ccb-5b40dbdad29d",
"client_id": "0DHqvq2D77kL2/JTPSZkTMJbkFVmUu0TzMi0jiXcFy8=",
"operation": "create",
"mount_type": "approle",
"mount_accessor": "auth_approle_316cf542",
"mount_running_version": "v1.14.0+builtin.vault",
"mount_class": "auth",
"client_token": "hmac-sha256:70849cbddaebad80649e4d1845fccfd2c4a12694b590a627d6d12d21ec34a5b4",
"client_token_accessor": "hmac-sha256:6bdd69aa740335b8a0d2b9588c60f79b7907c51091301d6a5f0d5289ed243e59",
"namespace": {
"id": "x3PCA",
"path": "testns/"
},
...
"response": {
"mount_type": "approle",
"mount_accessor": "auth_approle_316cf542",
"mount_running_plugin_version": "v1.14.0+builtin.vault",
"mount_class": "auth"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests! 👍
Add plugin metadata (name, type, version, sha256, whether the plugin is running externally) to audit logging