Skip to content

Commit

Permalink
Add extra logging for requests without ACL tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclement committed Sep 11, 2024
1 parent 27bf10e commit 10d9055
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
ACLDownPolicy: stringVal(c.ACL.DownPolicy),
ACLDefaultPolicy: stringVal(c.ACL.DefaultPolicy),
},
LogACLInfo: boolVal(c.LogACLInfo),

ACLEnableKeyListPolicy: boolVal(c.ACL.EnableKeyListPolicy),
ACLInitialManagementToken: stringVal(c.ACL.Tokens.InitialManagement),
Expand Down
1 change: 1 addition & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type Config struct {
LicensePath *string `mapstructure:"license_path" json:"license_path,omitempty"`
Limits Limits `mapstructure:"limits" json:"-"`
Locality *Locality `mapstructure:"locality" json:"-"`
LogACLInfo *bool `mapstructure:"log_acl_info" json:"log_acl_info,omitempty"`
LogLevel *string `mapstructure:"log_level" json:"log_level,omitempty"`
LogJSON *bool `mapstructure:"log_json" json:"log_json,omitempty"`
LogFile *string `mapstructure:"log_file" json:"log_file,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type RuntimeConfig struct {

ACLResolverSettings consul.ACLResolverSettings

LogACLInfo bool

// ACLEnableKeyListPolicy is used to opt-in to the "list" policy added to
// KV ACLs in Consul 1.0.
//
Expand Down
10 changes: 10 additions & 0 deletions agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc
fmt.Fprint(resp, msg)
}

t := ""
s.parseToken(req, &t)
if s.agent.config.LogACLInfo && t == "" {
httpLogger.Info("No ACL token in request",
"url", logURL,
"user_agent", req.UserAgent(),
"remote_addr", req.RemoteAddr,
)
}

start := time.Now()
defer func() {
httpLogger.Debug("Request finished",
Expand Down

0 comments on commit 10d9055

Please sign in to comment.