-
Notifications
You must be signed in to change notification settings - Fork 222
rfc: add initial draft of pcap-cf #1309
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,141 @@ | ||||||||||||||||||||||
# Meta | ||||||||||||||||||||||
[meta]: #meta | ||||||||||||||||||||||
- Name: Integrate pcap feature for Cloud Foundry applications | ||||||||||||||||||||||
- Start Date: 2025-09-10 | ||||||||||||||||||||||
- Author(s): @maxmoehl @peanball | ||||||||||||||||||||||
- Status: Draft | ||||||||||||||||||||||
- RFC Pull Request: [community#1309](https://github.com/cloudfoundry/community/issues/1309) | ||||||||||||||||||||||
|
||||||||||||||||||||||
## Summary | ||||||||||||||||||||||
|
||||||||||||||||||||||
Add a feature to Cloud Foundry that provides application developers with the | ||||||||||||||||||||||
ability to perform packet capture (tcpdump) operations within their | ||||||||||||||||||||||
application containers for debugging purposes. This RFC complements | ||||||||||||||||||||||
[RFC-0019 (pcap-bosh)](rfc-0019-pcap-bosh.md) by extending packet capture | ||||||||||||||||||||||
capabilities from BOSH-level infrastructure debugging to application-level | ||||||||||||||||||||||
debugging. | ||||||||||||||||||||||
|
||||||||||||||||||||||
The main goal is to allow app developers to capture network traffic from | ||||||||||||||||||||||
their applications when troubleshooting issues that require elevated | ||||||||||||||||||||||
privileges, while maintaining security through operator controls and a | ||||||||||||||||||||||
reduced-functionality custom tool. | ||||||||||||||||||||||
|
||||||||||||||||||||||
## Problem | ||||||||||||||||||||||
|
||||||||||||||||||||||
Application developers frequently need to perform in-depth troubleshooting | ||||||||||||||||||||||
of their applications when deployed via Cloud Foundry buildpacks. Network analysis | ||||||||||||||||||||||
tasks, such as packet captures (tcpdump), connectivity checks and performance | ||||||||||||||||||||||
checks, require elevated privileges as the captured data may be sensitive. | ||||||||||||||||||||||
Currently, there is no possibility for app developers to perform any privileged | ||||||||||||||||||||||
actions within their application containers, which also excludes such network | ||||||||||||||||||||||
analysis tasks. | ||||||||||||||||||||||
|
||||||||||||||||||||||
[RFC-0019 (pcap-bosh)](rfc-0019-pcap-bosh.md) addresses packet capture | ||||||||||||||||||||||
at the BOSH infrastructure level for platform operators. Application developers | ||||||||||||||||||||||
and operators, an equally important group of users, need similar capabilities, | ||||||||||||||||||||||
scoped to their individual applications. | ||||||||||||||||||||||
|
||||||||||||||||||||||
The challenge is providing this functionality while maintaining the security | ||||||||||||||||||||||
model of Cloud Foundry, where applications run in isolated, unprivileged | ||||||||||||||||||||||
containers. | ||||||||||||||||||||||
|
||||||||||||||||||||||
## Proposal: Custom Packet Capturing Tool | ||||||||||||||||||||||
|
||||||||||||||||||||||
This RFC proposes implementing a reduced-functionality packet capturing tool | ||||||||||||||||||||||
written in Go using the [gopacket][gopacket] library. This custom tool would be | ||||||||||||||||||||||
injected into application containers via Diego, similar to how [diego-ssh][diego-ssh] | ||||||||||||||||||||||
currently provides SSH access. | ||||||||||||||||||||||
|
||||||||||||||||||||||
maxmoehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
### Key Features | ||||||||||||||||||||||
|
||||||||||||||||||||||
The tool reduces the attack surface to a minimum by only exposing the options | ||||||||||||||||||||||
which are strictly necessary to capture packets, namely: | ||||||||||||||||||||||
* Specifying a network interface | ||||||||||||||||||||||
* Applying packet filters (pcap-filter format) | ||||||||||||||||||||||
* Setting snapshot length (snaplen) | ||||||||||||||||||||||
|
||||||||||||||||||||||
The tool would be injected via Diego using a mechanism similar to | ||||||||||||||||||||||
[diego-ssh][diego-ssh]. This ensures that the tool is available in all apps | ||||||||||||||||||||||
regardeless of the deployment method and it follows established patterns that | ||||||||||||||||||||||
are already known by maintainers. | ||||||||||||||||||||||
|
||||||||||||||||||||||
The tool has the necessary file capabilities assigned (`CAP_NET_RAW` and | ||||||||||||||||||||||
`CAP_NET_ADMIN`) to be able to capture packets. It remains in the namespaces of | ||||||||||||||||||||||
the application to ensure a vulnerability in the tool does not enable a | ||||||||||||||||||||||
container escape. | ||||||||||||||||||||||
|
||||||||||||||||||||||
The tool is only accessible if SSH is enabled for the application. | ||||||||||||||||||||||
|
||||||||||||||||||||||
## Other Options Considered | ||||||||||||||||||||||
|
||||||||||||||||||||||
#### Option 1: `sudo` Access | ||||||||||||||||||||||
|
||||||||||||||||||||||
Adding a platform switch to make the `vcap` user a sudoer was considered but | ||||||||||||||||||||||
maxmoehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
discarded due to: | ||||||||||||||||||||||
* Significant security risks of providing full root access in the app container. | ||||||||||||||||||||||
* Potential for privilege escalation beyond intended packet capture use | ||||||||||||||||||||||
* Inconsistency with Cloud Foundry's [security-first design principles][cf-sec] | ||||||||||||||||||||||
|
||||||||||||||||||||||
Even considering that we could configure sudo in a way that the vcap user is | ||||||||||||||||||||||
only allowed to perform verify specific tasks (like running tcpdump) this still | ||||||||||||||||||||||
suffers from potential privilege escalation as explained in the next section. | ||||||||||||||||||||||
|
||||||||||||||||||||||
#### Option 2: `setcap` on `tcpdump` Binary | ||||||||||||||||||||||
|
||||||||||||||||||||||
Setting capabilities on the existing `tcpdump` binary was considered but | ||||||||||||||||||||||
discarded because: | ||||||||||||||||||||||
* `tcpdump` offers functionality to run arbitrary code in its security | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a link here would be really helpful. On its own we need to believe the author's word. With a link to a security research paper/article we have independent sources. I also know that we have this source. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cloudfoundry/diego-release#1023 (comment) @thomasthal do you have a source for what you've shared in the linked comment? |
||||||||||||||||||||||
context | ||||||||||||||||||||||
* Broader attack surface compared to a purpose-built tool | ||||||||||||||||||||||
|
||||||||||||||||||||||
## Implementation Considerations | ||||||||||||||||||||||
|
||||||||||||||||||||||
maxmoehl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
Based on the proposed solution the following sections detail out the changes | ||||||||||||||||||||||
which have to be made to the individual components of Cloud Foundry to implement | ||||||||||||||||||||||
it. | ||||||||||||||||||||||
|
||||||||||||||||||||||
### diego-release: Custom Packet Capturing Tool | ||||||||||||||||||||||
|
||||||||||||||||||||||
A new package will be added to diego-release which implements packet capturing | ||||||||||||||||||||||
in go through the [gopacket][gopacket] library. The resulting binary will be included in | ||||||||||||||||||||||
the various lifecycle archives that are added to the final app container and | ||||||||||||||||||||||
the necessary capabilities (`CAP_NET_RAW` and `CAP_NET_ADMIN`) will be assigned | ||||||||||||||||||||||
to the executable via file capabilities. This allows regular users to gain those | ||||||||||||||||||||||
capabilities when executing the binary. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(if it's important, repeat it ;-) ) |
||||||||||||||||||||||
|
||||||||||||||||||||||
### CF CLI: New `pcap` command | ||||||||||||||||||||||
|
||||||||||||||||||||||
Similar to the `bosh pcap` command a `cf pcap` command will be added. Like its | ||||||||||||||||||||||
predecessor it will connect to the desired instances via SSH and execute the new | ||||||||||||||||||||||
packet capturing tool and stream back the captured packets via stdout. If there | ||||||||||||||||||||||
are multiple streams, the CLI will merge them and write them out to a single | ||||||||||||||||||||||
file in the pcap format. | ||||||||||||||||||||||
Comment on lines
+108
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
"predecessor" makes it look like bosh pcap might be going away. |
||||||||||||||||||||||
|
||||||||||||||||||||||
Examples usages and output: | ||||||||||||||||||||||
|
||||||||||||||||||||||
```bash | ||||||||||||||||||||||
$ cf pcap myapp --output capture.pcap --interface eth0 --filter "tcp port 80" --snaplen 1500 | ||||||||||||||||||||||
Starting capture on all instances. | ||||||||||||||||||||||
Capturing, press ^C to stop... | ||||||||||||||||||||||
^C | ||||||||||||||||||||||
Saved capture to 'capture.pcap'. | ||||||||||||||||||||||
$ cf pcap myapp -o capture.pcap -i 1 -f "host database.example.com" | ||||||||||||||||||||||
Starting capture on instances: 1. | ||||||||||||||||||||||
Capturing, press ^C to stop... | ||||||||||||||||||||||
^C | ||||||||||||||||||||||
Saved capture to 'capture.pcap'. | ||||||||||||||||||||||
``` | ||||||||||||||||||||||
|
||||||||||||||||||||||
## References | ||||||||||||||||||||||
|
||||||||||||||||||||||
* Prior discussions: | ||||||||||||||||||||||
* https://github.com/cloudfoundry/diego-release/issues/1023 | ||||||||||||||||||||||
* https://cloudfoundry.slack.com/archives/C0DEQSW9W/p1744034414856129?thread_ts=1744034414.856129&cid=C0DEQSW9W | ||||||||||||||||||||||
* https://cloudfoundry.slack.com/archives/C033RE5D6/p1744299390390049 | ||||||||||||||||||||||
* https://github.com/cloudfoundry/pcap-release | ||||||||||||||||||||||
* https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0019-pcap-bosh.md | ||||||||||||||||||||||
* https://github.com/gopacket/gopacket | ||||||||||||||||||||||
|
||||||||||||||||||||||
[gopacket]: https://github.com/gopacket/gopacket | ||||||||||||||||||||||
[diego-ssh]: https://github.com/cloudfoundry/diego-ssh | ||||||||||||||||||||||
[cf-sec]: https://docs.cloudfoundry.org/concepts/security.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we highlight here that this could be achieved by not generally elevating privileges but elevating privileges for clearly defined, narrow use cases?
Or rather: "Elevated privileges can easily be misused and it is paramount (or some less fancy word) that the security model of CF remains intact, while giving app developers and operators the choice and tools to be able to asses network traffic."
This also alludes to this feature being opt-in. You might not want to enable it permanently, and you may not want to enable it for some specific apps at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this?