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

cloudflare: move HTTP request debugging to httputil #1164

Conversation

jacobbednarz
Copy link
Member

Within the library, we provide a way to output the HTTP interactions that the library makes. We previously used a custom approach and format the output. Even though it works, there are better approaches using httputil.DumpRequestOut and httputil.DumpResponseOut for dumping the HTTP interactions.

Alongside this work, we're adding support for redacting sensitive values in the HTTP interactions. This is useful for both this library and the consumers of this library (like the Terraform Provider) to prevent leaking sensitive information in logs.

Closes #1143

Within the library, we provide a way to output the HTTP interactions
that the library makes. We previously used a custom approach and format
the output. Even though it works, there are better approaches using
`httputil.DumpRequestOut` and `httputil.DumpResponseOut` for dumping the
HTTP interactions.

Alongside this work, we're adding support for redacting sensitive values
in the HTTP interactions. This is useful for both this library and the
consumers of this library (like the Terraform Provider) to prevent
leaking sensitive information in logs.

Closes cloudflare#1143
@jacobbednarz jacobbednarz force-pushed the automatically-redact-known-sensitive-http-headers branch from 09e67f6 to fdc3a7d Compare January 4, 2023 20:35
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

changelog detected ✅

@codecov-commenter
Copy link

Codecov Report

Merging #1164 (fdc3a7d) into master (6153c1e) will decrease coverage by 0.12%.
The diff coverage is 46.94%.

@@            Coverage Diff             @@
##           master    #1164      +/-   ##
==========================================
- Coverage   49.40%   49.28%   -0.13%     
==========================================
  Files         127      128       +1     
  Lines       12290    12416     +126     
==========================================
+ Hits         6072     6119      +47     
- Misses       4840     4896      +56     
- Partials     1378     1401      +23     
Impacted Files Coverage Δ
cloudflare_experimental.go 0.00% <0.00%> (ø)
utils.go 72.72% <ø> (ø)
cloudflare.go 68.37% <14.28%> (-0.34%) ⬇️
mtls_certificates.go 26.59% <26.59%> (ø)
origin_ca.go 57.26% <90.90%> (-2.09%) ⬇️
dns.go 68.69% <92.45%> (+4.97%) ⬆️
email_routing_destination.go 66.66% <100.00%> (+0.41%) ⬆️
email_routing_rules.go 65.64% <100.00%> (+0.26%) ⬆️
filter.go 43.38% <100.00%> (+0.41%) ⬆️
firewall_rules.go 54.38% <100.00%> (+0.40%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jacobbednarz jacobbednarz merged commit c6c2b7e into cloudflare:master Jan 4, 2023
@jacobbednarz jacobbednarz deleted the automatically-redact-known-sensitive-http-headers branch January 4, 2023 20:41
@github-actions github-actions bot added this to the v0.59.0 milestone Jan 4, 2023
github-actions bot pushed a commit that referenced this pull request Jan 4, 2023
@jacobbednarz jacobbednarz modified the milestones: v0.59.0, v0.58.1 Jan 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

This functionality has been released in v0.58.1.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this pull request Jan 4, 2023
As of cloudflare/cloudflare-go#1164 we have the ability to use the
inbuilt logger for redacting sensitive HTTP headers.

Previously, we were discarding the provided logger due to instantiating
a new `cleanhttp` client to use however, with this change we are now
using the cloudflare-go logger for HTTP interactions inside the
Terraform Core sink.

By default we redact the values found in the following HTTP headers (not
the headers themselves) in the entire HTTP interaction:

- `X-Auth-Email`
- `X-Auth-Key`
- `X-Auth-User-Service-Key`
- `Authorization`

And here is an example of the logger in action for `TF_LOG=DEBUG`.

```
2023-01-05T06:49:41.208221+11:00 [DEBUG] cloudflare
GET /client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/access/apps/dec500cc-4eb3-4c64-b10d-1fce8f686339 HTTP/1.1
Host: api.cloudflare.com
User-Agent: terraform/1.3.6 terraform-plugin-sdk/2.10.1 terraform-provider-cloudflare/dev
Content-Type: application/json
X-Auth-Email: [redacted]
X-Auth-Key: [redacted]
Accept-Encoding: gzip

2023-01-05T06:49:41.208221+11:00 [DEBUG] cloudflare
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cf-Cache-Status: DYNAMIC
Cf-Ray: 78467fb52e4baaf9-SYD
Connection: keep-alive

...

{
  "result": {
    "id": "dec500cc-4eb3-4c64-b10d-1fce8f686339",
    "uid": "dec500cc-4eb3-4c64-b10d-1fce8f686339",
    // ..
    "http_only_cookie_attribute": false
  },
  "success": true,
  "errors": [],
  "messages": []
}
```
ivan-section-io pushed a commit to section/cloudflare-go that referenced this pull request Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X-Auth-Key header should be redacted in debug logs
2 participants