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

Add HTTP cookie capture #147

Merged

Conversation

Miciah
Copy link
Contributor

@Miciah Miciah commented Jul 9, 2020

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.

Depends on #139.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 9, 2020
@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 9, 2020
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.
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2020
@Miciah Miciah changed the title WIP: Add HTTP cookie capture Add HTTP cookie capture Jul 15, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2020
@sgreene570
Copy link

🍪
/lgtm

@openshift-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants