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
Add HTTP cookie capture #147
Add HTTP cookie capture #147
Conversation
Add a --capture-http-cookie command-line flag, as well as ROUTER_CAPTURE_HTTP_COOKIE environment variable, to allow specifying an HTTP cookie that should be captured for logging. The flag and environment variable each accept a name:maxLength value, where name is an HTTP cookie and maxLength is a maximum length. The router captures the named cookie, which may be referenced in a custom ROUTER_SYSLOG_FORMAT string or is included in the default log message format if no custom format string is provided. A cookie value that exceeds its maximum length is truncated to that length. The value of the first cookie that matches the provided name captured. By default, names are compared using a prefix match. An equals sign ("=") may be appended to the name to indicate that the comparison should use an exact match. * images/router/haproxy/conf/haproxy-config.template: Add "capture cookie" stanzas to the "public", "fe_sni", and "fe_no_sni" frontends. * pkg/cmd/infra/router/template.go (TemplateRouter): Add CaptureHTTPCookieString and CaptureHTTPCookie fields. (Bind): Add the --capture-http-cookie flag, which defaults to the value of the ROUTER_CAPTURE_HTTP_COOKIE environment variable. (parseCaptureCookie): New function. Parse a string value (such as provided with the newly added command-line flag) into a CaptureHTTPCookie value. (Complete): Use parseCaptureCookie to parse CaptureHTTPCookieString into CaptureHTTPCookie. (Run): Specify CaptureHTTPCookie in the plugin config. * pkg/router/template/plugin.go (TemplatePluginConfig): Add CaptureHTTPCookie field. (NewTemplatePlugin): Specify CaptureHTTPCookie in the internal template router config. * pkg/router/template/router.go (templateRouter): (templateRouterCfg): Add captureHTTPCookie field. (templateData): Add CaptureHTTPCookie field. (newTemplateRouter): Specify captureHTTPCookie in the template router. (writeConfig): Specify CaptureHTTPCookie in the template parameters. * pkg/router/template/types.go (CaptureHTTPCookie): New type. Specify an HTTP cookie name, maximum value length, and match type. (CookieMatchType): New type. (CookieMatchTypeExact, CookieMatchTypePrefix): New constants.
a7d1917
to
2353425
Compare
🍪 |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Miciah, sgreene570 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
Add a
--capture-http-cookie
command-line flag, as well asROUTER_CAPTURE_HTTP_COOKIE
environment variable, to allow specifying an HTTP cookie that should be captured for logging.The flag and environment variable each accept a
name:maxLength
value, wherename
is an HTTP cookie andmaxLength
is a maximum length. The router captures the named cookie, which may be referenced in a customROUTER_SYSLOG_FORMAT
string or is included in the default log message format if no custom format string is provided. A cookie value that exceeds its maximum length is truncated to that length. The value of the first cookie that matches the provided name captured. By default, names are compared using a prefix match. An equals sign ("=") may be appended to the name to indicate that the comparison should use an exact match.images/router/haproxy/conf/haproxy-config.template
: Addcapture cookie
stanzas to thepublic
,fe_sni
, andfe_no_sni
frontends.pkg/cmd/infra/router/template.go
(TemplateRouter
): AddCaptureHTTPCookieString
andCaptureHTTPCookie
fields.(
Bind
): Add the--capture-http-cookie
flag, which defaults to the value of theROUTER_CAPTURE_HTTP_COOKIE
environment variable.(
parseCaptureCookie
): New function. Parse a string value (such as provided with the newly added command-line flag) into aCaptureHTTPCookie
value.(
Complete
): UseparseCaptureCookie
to parseCaptureHTTPCookieString
intoCaptureHTTPCookie
.(
Run
): SpecifyCaptureHTTPCookie
in the plugin config.pkg/router/template/plugin.go
(TemplatePluginConfig
): AddCaptureHTTPCookie
field.(
NewTemplatePlugin
): SpecifyCaptureHTTPCookie
in the internal template router config.pkg/router/template/router.go
(templateRouter
):(
templateRouterCfg
): AddcaptureHTTPCookie
field.(
templateData
): AddCaptureHTTPCookie
field.(
newTemplateRouter
): SpecifycaptureHTTPCookie
in the template router.(
writeConfig
): SpecifyCaptureHTTPCookie
in the template parameters.pkg/router/template/types.go
(CaptureHTTPCookie
): New type. Specify an HTTP cookie name, maximum value length, and match type.(
CookieMatchType
): New type.(
CookieMatchTypeExact
,CookieMatchTypePrefix
): New constants.Depends on #139.