-
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
Provide token ttl and issue time in the audit log. #9091
Changes from 1 commit
6b8a00d
b8735b4
844b6d9
fa21119
a11dd3e
687c71c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |
"context" | ||
"crypto/tls" | ||
"fmt" | ||
"github.com/hashicorp/vault/sdk/helper/salt" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
"io" | ||
"strings" | ||
"time" | ||
|
@@ -12,8 +14,6 @@ import ( | |
|
||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/vault/helper/namespace" | ||
"github.com/hashicorp/vault/sdk/helper/salt" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
type AuditFormatWriter interface { | ||
|
@@ -106,6 +106,7 @@ func (f *AuditFormatter) FormatRequest(ctx context.Context, w io.Writer, config | |
EntityID: auth.EntityID, | ||
RemainingUses: req.ClientTokenRemainingUses, | ||
TokenType: auth.TokenType.String(), | ||
TokenTTL: int64(auth.TTL.Seconds()), | ||
}, | ||
|
||
Request: &AuditRequest{ | ||
|
@@ -127,6 +128,11 @@ func (f *AuditFormatter) FormatRequest(ctx context.Context, w io.Writer, config | |
}, | ||
} | ||
|
||
var zt time.Time | ||
if auth.IssueTime != zt { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to do this all the time, but I think you can now use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, much better. Was not liking that construct. |
||
reqEntry.Auth.TokenIssueTime = auth.IssueTime.Format(time.RFC3339) | ||
ncabatoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if req.WrapInfo != nil { | ||
reqEntry.Request.WrapTTL = int(req.WrapInfo.TTL / time.Second) | ||
} | ||
|
@@ -212,6 +218,11 @@ func (f *AuditFormatter) FormatResponse(ctx context.Context, w io.Writer, config | |
NumUses: resp.Auth.NumUses, | ||
EntityID: resp.Auth.EntityID, | ||
TokenType: resp.Auth.TokenType.String(), | ||
TokenTTL: int64(resp.Auth.TTL.Seconds()), | ||
} | ||
var zt time.Time | ||
if resp.Auth.IssueTime != zt { | ||
respAuth.TokenIssueTime = resp.Auth.IssueTime.Format(time.RFC3339) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why this is useful to include? Does it differ significantly from the time on the response itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, could be useful for renew calls, I guess? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a login I guess it would be a similar time. I was just trying to add it consistently. |
||
} | ||
} | ||
|
||
|
@@ -258,6 +269,7 @@ func (f *AuditFormatter) FormatResponse(ctx context.Context, w io.Writer, config | |
RemainingUses: req.ClientTokenRemainingUses, | ||
EntityID: auth.EntityID, | ||
TokenType: auth.TokenType.String(), | ||
TokenTTL: int64(auth.TTL.Seconds()), | ||
}, | ||
|
||
Request: &AuditRequest{ | ||
|
@@ -289,6 +301,10 @@ func (f *AuditFormatter) FormatResponse(ctx context.Context, w io.Writer, config | |
}, | ||
} | ||
|
||
var zt time.Time | ||
if auth.IssueTime != zt { | ||
respEntry.Auth.TokenIssueTime = auth.IssueTime.Format(time.RFC3339) | ||
} | ||
if req.WrapInfo != nil { | ||
respEntry.Request.WrapTTL = int(req.WrapInfo.TTL / time.Second) | ||
} | ||
|
@@ -359,6 +375,8 @@ type AuditAuth struct { | |
RemainingUses int `json:"remaining_uses,omitempty"` | ||
EntityID string `json:"entity_id,omitempty"` | ||
TokenType string `json:"token_type,omitempty"` | ||
TokenTTL int64 `json:"token_ttl,omitempty"` | ||
TokenIssueTime string `json:"token_issue_time,omitempty"` | ||
} | ||
|
||
type AuditSecret struct { | ||
|
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.
Can you revert this rearrangement of imports please?
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.
Sure.