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

Redact http header values in logs #343

Merged
merged 10 commits into from
Oct 11, 2023
Merged

Redact http header values in logs #343

merged 10 commits into from
Oct 11, 2023

Conversation

sfc-gh-elinardi
Copy link
Collaborator

@sfc-gh-elinardi sfc-gh-elinardi commented Oct 9, 2023

Introducing redaction to rpc authz evaluation logs.

This leverages protobuf's debug_redact annotation. In the protobuf definition, fields which need redaction are annotated with debug_redact. Then, before logging the protobuf message, we look for the annotation and replace the value with --REDACTED--

In this PR I'm only adding the redaction to httpoverrpc header values.

Testing

{"logger":"sansshell-proxy","ts":"2023-10-09 14:17:51.528922","caller":{"file":"rpcauth.go","line":215},"level":2,"msg":"evaluating authz policy","method":"/Proxy.Proxy/Proxy","peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"input":{"method":"/HTTPOverRPC.HTTPOverRPC/Host","message":{"request":{"method":"POST", "request_uri":"/session", "headers":[{"key":"Content-Type", "values":["--REDACTED--"]}, {"key":"Accept", "values":["--REDACTED--"]}, {"key":"User-Agent", "values":["--REDACTED--"]}, {"key":"Authorization", "values":["--REDACTED--"]}]}, "port":8082, "hostname":"localhost", "protocol":"http"},"type":"HTTPOverRPC.HostHTTPRequest","metadata":{":authority":["test.example.com"],"content-type":["application/grpc"],"user-agent":["grpc-go/1.52.3"],"grpc-accept-encoding":["gzip"]},"peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"host":{"net":{"network":"tcp","address":"127.0.0.1","port":"50042"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"environment":{"non_host_policy_check":true},"extensions":null}}
{"logger":"sansshell-proxy","ts":"2023-10-09 14:17:51.529090","caller":{"file":"rpcauth.go","line":237},"level":2,"msg":"evaluating authz policy post hooks","method":"/Proxy.Proxy/Proxy","peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"input":{"method":"/HTTPOverRPC.HTTPOverRPC/Host","message":{"request":{"method":"POST", "request_uri":"/session", "headers":[{"key":"Content-Type", "values":["--REDACTED--"]}, {"key":"Accept", "values":["--REDACTED--"]}, {"key":"User-Agent", "values":["--REDACTED--"]}, {"key":"Authorization", "values":["--REDACTED--"]}]}, "port":8082, "hostname":"localhost", "protocol":"http"},"type":"HTTPOverRPC.HostHTTPRequest","metadata":{"user-agent":["grpc-go/1.52.3"],"grpc-accept-encoding":["gzip"],":authority":["test.example.com"],"content-type":["application/grpc"]},"peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"host":{"net":{"network":"tcp","address":"127.0.0.1","port":"50042"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"environment":{"non_host_policy_check":true},"extensions":null}}
{"logger":"sansshell-proxy","ts":"2023-10-09 14:17:51.529295","caller":{"file":"rpcauth.go","line":255},"level":0,"msg":"authz policy evaluation result","method":"/Proxy.Proxy/Proxy","peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"authorizationResult":true,"input":{"method":"/HTTPOverRPC.HTTPOverRPC/Host","message":{"request":{"method":"POST", "request_uri":"/session", "headers":[{"key":"Content-Type", "values":["--REDACTED--"]}, {"key":"Accept", "values":["--REDACTED--"]}, {"key":"User-Agent", "values":["--REDACTED--"]}, {"key":"Authorization", "values":["--REDACTED--"]}]}, "port":8082, "hostname":"localhost", "protocol":"http"},"type":"HTTPOverRPC.HostHTTPRequest","metadata":{"user-agent":["grpc-go/1.52.3"],"grpc-accept-encoding":["gzip"],":authority":["test.example.com"],"content-type":["application/grpc"]},"peer":{"net":{"network":"tcp","address":"127.0.0.1","port":"64348"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"host":{"net":{"network":"tcp","address":"127.0.0.1","port":"50042"},"cert":{"subject":"CN=test.example.com","issuer":"CN=example.com","dnsnames":["test.example.com"],"spiffeid":""},"principal":null},"environment":{"non_host_policy_check":true},"extensions":null},"denialHints":[]}

@sfc-gh-elinardi sfc-gh-elinardi changed the title redact http header values Redact http header values in logs Oct 9, 2023
@sfc-gh-elinardi sfc-gh-elinardi marked this pull request as ready for review October 9, 2023 20:11
Copy link
Collaborator

@sfc-gh-srhodes sfc-gh-srhodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay overall. Could you add tests for getRedactedInput()?

auth/opa/rpcauth/rpcauth.go Outdated Show resolved Hide resolved
auth/opa/rpcauth/rpcauth.go Outdated Show resolved Hide resolved
@sfc-gh-elinardi
Copy link
Collaborator Author

Looks okay overall. Could you add tests for getRedactedInput()?

Added tests for getRedactedInput

auth/opa/rpcauth/redact_test.go Outdated Show resolved Hide resolved
auth/opa/rpcauth/rpcauth_test.go Outdated Show resolved Hide resolved
@sfc-gh-elinardi sfc-gh-elinardi merged commit 0f9d7d7 into main Oct 11, 2023
4 checks passed
@sfc-gh-elinardi sfc-gh-elinardi deleted the elinardi-redact branch October 11, 2023 21:03
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.

2 participants