Part 3: The return of the secrets
The kubelet read-only API on port 10255 was exposed to build pods, allowing an attacker to list all pods on the host and extract Git credentials from their environment variables. This could give access to private repositories of other tenants if builds were running in the same GKE account.
assetnote.io
Published on assetnote.io
Following on from our 2nd story, we’ll be continuing the epic tale of our research into Cloudflare pages in this third installment. If you haven’t read part 1&2, you can read them here and here.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is the third part of a series on Cloudflare Pages. Parts 1 and 2 covered earlier findings against the platform; after those, Cloudflare concluded that the best way forward was to re-architect the platform. This part picks up after the researchers had escaped from the previous container environment and describes what they found on the rebuilt, opt-in Pages environment.
Cloudflare Pages is a build-and-host product: a user connects a repository, and the platform runs a build in a container and serves the output. The interesting surface for a researcher is the build container itself, because it runs code derived from the user's repository and sits inside Cloudflare's infrastructure.
Setup
The researchers had previously been invited to test the new platform. Later, the Cloudflare program on HackerOne received an update indicating that there was a new Pages environment that HackerOne users could opt in to. The researchers opted in and tested that environment.
The starting position was the same as in the earlier parts: a reverse shell spawned from a build script inside the build container. The tools used were:
- A reverse shell placed in the repository, executed by the build.
- Nmap for port scanning.
- curl for probing individual services.
- Kiterunner for enumerating API endpoints on the discovered services.
Finding it
On the new environment the researchers immediately noticed several changes, which they list as follows:
- The build scripts could not be read: the new user has no permission to read them.
- The environment runs in GKE, a different cloud and infrastructure from before.
- The container is a gVisor container, running as a non-root user.
- Kubernetes API endpoints are reachable with the anonymous role, which by itself is not useful.
- Instance metadata is not accessible.
Losing read access to the build scripts and resources meant the researchers were flying blind: they could no longer audit the implementation for command injection or understand how the other build steps worked.
Running on GKE changed the picture in two ways. First, the platform had moved off Azure entirely, so the pipeline techniques from the earlier parts no longer applied. Second, GKE security features, if enabled properly, cut off many avenues for privilege escalation in the cluster; workload identity installs a metadata API proxy and other controls that severely limit leaking tokens or secrets through the metadata API.
Finally, gVisor is a container runtime, like containerd (which powers Docker), that provides defence in depth. It acts as a syscall proxy and emulation layer: syscalls are emulated and evaluated against a granted set of capabilities, so only a restricted set of syscalls and arguments reach the kernel. The researchers describe it as being able to reach the kernel only through a proxy with a very strict access control list.
With those mitigations in place, the researchers set out to escalate privileges and collect secrets again.
Exploitation
Step 1: Port scan the adjacent host
The researchers took the pod's IP address from the network configuration visible in the shell and scanned adjacent hosts on the same subnet. They started with the .1 address, which in a Kubernetes or Docker environment is normally the host.
Scanning [redacted] [65535 ports]
Discovered open port 22/tcp on [redacted]
Discovered open port 10256/tcp on [redacted]
Discovered open port 10250/tcp on [redacted]
Discovered open port 2020/tcp on [redacted]
Discovered open port 10255/tcp on [redacted]
Discovered open port 31501/tcp on [redacted]
Discovered open port 2021/tcp on [redacted]
Completed Connect Scan at 00:06, 4.79s elapsed (65535 total ports)
Nmap scan report for [redacted]
Host is up, received user-set (0.0035s latency).
Scanned at 2022-01-22 00:06:18 UTC for 5s
Not shown: 65528 closed ports
Reason: 65528 conn-refused
PORT STATE SERVICE REASON
22/tcp open ssh syn-ack
2020/tcp open unknown syn-ack
2021/tcp open unknown syn-ack
10250/tcp open unknown syn-ack
10255/tcp open unknown syn-ack
10256/tcp open unknown syn-ack
31501/tcp open unknown syn-ack
In a properly locked-down Kubernetes environment with network policies in place, the researchers expected this scan to yield very little, and certainly not control plane services beyond those needed to operate the build. Instead, multiple ports responded on the host.
Step 2: Probe the open ports
Probing each port gave varying amounts of information. Some returned a plain 404:
curl [redacted]:2021 -v
* Rebuilt URL to: [redacted]:2021/
* Trying 10.124.165.1...
* Connected to [redacted] ([redacted]) port 2021 (#0)
>GET / HTTP/1.1
>Host: [redacted]:2021
>User-Agent: curl/7.47.0
>Accept: **/**
>
<HTTP/1.1 404 Not Found
<Content-Type: text/plain; charset=utf-8
<X-Content-Type-Options: nosniff
<Date: Sat, 22 Jan 2022 00:07:10 GMT
<Content-Length: 19
<
404 page not found
* Connection #0 to host [redacted] left intact
Others revealed what was running. Port 2020 returned a 200 with a Server: Monkey/1.7.0 header and a JSON body describing fluent-bit:
buildbot@build-prod-3330469-v7jkn:~/repo$ curl [redacted]:2020 -v
curl [redacted]:2020 -v
* Rebuilt URL to: [redacted]:2020/
* Trying 10.124.165.1...
* Connected to [redacted] ([redacted]) port 2020 (
> GET / HTTP/1.1
> Host: [redacted]:2020
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Monkey/1.7.0
< Date: Sat, 22 Jan 2022 00:07:02 GMT
< Transfer-Encoding: chunked
<
* Connection
{"fluent-bit":{"version":"1.5.7","edition":"Community","flags":["FLB_HAVE_PARSER","FLB_HAVE_RECORD_ACCESSOR","FLB_HAVE_STREAM_PROCESSOR","FLB_HAVE_TLS","FLB_HAVE_AWS","FLB_HAVE_SIGNV4","FLB_HAVE_SQLDB","FLB_HAVE_METRICS","FLB_HAVE_HTTP_SERVER","FLB_HAVE_SYSTEMD","FLB_HAVE_FORK","FLB_HAVE_TIMESPEC_GET","FLB_HAVE_GMTOFF","FLB_HAVE_UNIX_SOCKET","FLB_HAVE_PROXY_GO","FLB_HAVE_SYSTEM_STRPTIME","FLB_HAVE_JEMALLOC","FLB_HAVE_LIBBACKTRACE","FLB_HAVE_REGEX","FLB_HAVE_UTF8_ENCODER","FLB_HAVE_LUAJIT","FLB_HAVE_C_TLS","FLB_HAVE_ACCEPT4","FLB_HAVE_INOTIFY"]}}
This confirmed the researchers' suspicion: they were seeing the monitoring and internal services running in the cluster, on the host. Manual probing of these services did not turn up useful information or privileged access that could be used to escape the container again. The services expose specific, limited API paths, often appearing to be Go binaries serving API endpoints, so the next step was to discover what each service was.
Step 3: Enumerate API endpoints with Kiterunner
The researchers set up Kiterunner and pointed it at each open port. This identified an interesting endpoint on the host, on port 10255, named /pods. A quick search confirms this is the internal kubelet API used by Kubernetes.
Step 4: Dump pod details from the kubelet API
The kubelet API differs from the Kubernetes API in that it cannot modify Kubernetes objects. However, the output let the researchers dump the details of each pod running on the host:
curl -v -k http://[redacted]:10255/pods
Grepping this output for CREDS found GIT_CREDS, which the researchers describe as an atomic-level bout of deja vu, echoing the Git credential finding from the earlier part of the series.
Step 5: Test the Git credentials and widen the scope
Testing the Git credentials, the researchers could only see their own private repositories this time. That still means private repository access from outside their organisation, which is potentially sensitive for large organisations with multiple private repositories.
To see whether the finding could be widened, they ran an nmap scan for port 10255 across [redacted]/16, in case other tenants or hosts were reachable. A number of different hosts were accessible and returned the same data. That indicates that if other builds were running anywhere in this GKE account for other users and organisations, their Git credentials could also be stolen.
In the HackerOne report, Sean quoted:
guess who's back. back again. shady's back. call a friend
Root cause
The build pods could reach the host's kubelet read-only endpoint on port 10255, and that endpoint exposed pod details including Git credentials. The network boundary between the build pod and the host was not enforced, so a user-controlled build script could scan the subnet, find the kubelet API, and read pod details including Git credentials. The scan across [redacted]/16 showing multiple hosts with the same data suggests the exposure was not limited to a single tenant's build.
The earlier mitigations did not stop this. The build scripts were no longer readable, the container ran as non-root under gVisor, and instance metadata was blocked, but none of those controls addressed pod-to-host network reachability. The kubelet read-only API was reachable from the build pod and was enough to disclose pod details.
Impact
An attacker who controls a build script could read Git credentials for builds running on reachable hosts. In this instance the credentials only gave access to the researchers' own private repositories, but the same data was returned by a number of hosts across the scanned range, so other users' and organisations' Git credentials would be exposed under the same conditions. For a large organisation with multiple private repositories, that access is potentially sensitive.
Fix
Cloudflare remediated the issue quickly. The researchers presume the remedy was a judicious application of iptables rules or pod network security policies; they could not confirm the exact change because access was locked down again afterwards. Once appropriate network isolation was in place, the problem was effectively mitigated.
The takeaway for defenders is to ensure appropriate network segregation and firewalling in complex network environments, reflecting the security boundaries of the application. Isolating different tenant networks at build time would be enough for this case, but preventing all communication from pod to host was the more effective and airtight fix.
Variants to test
- Scan the default gateway of a build or CI container for the kubelet read-only port. A positive result is a response on port 10255 that returns pod data.
- Request
/podson any discovered kubelet endpoint and grep the output for credential-like strings such asGIT_CREDS. A positive result is credentials belonging to a build other than your own. - Scan the wider pod subnet for the same port to check whether other hosts are reachable. A positive result is multiple hosts returning the same pod data, which indicates cross-tenant exposure.
- Run Kiterunner against other open ports on the host to find undocumented API endpoints. A positive result is an endpoint that returns internal service or build information.
- Probe monitoring services such as fluent-bit's HTTP server for version and configuration details. A positive result is a version banner or configuration that helps identify further attack paths.
What happened, in plain words
Cloudflare Pages is a service that builds and hosts websites for you. You connect a code repository (a folder of your project's files, stored online), Cloudflare runs a build (a set of commands that turns your source files into a finished website) inside a container, and then serves the result to visitors. A container is a sealed-off mini-computer inside a bigger computer: it has its own files and processes, but it shares the underlying machine with other containers.
This article is the third part of a series about that build container. In parts 1 and 2, the researchers found ways to break out of the container and reach things they should not. After that, Cloudflare decided the best way forward was to rebuild the platform from scratch, a process called re-architecting. This part describes what the researchers found on the rebuilt platform, which HackerOne users (HackerOne is a bug bounty platform where companies invite researchers to test their systems) could opt in to test.
The short version: even after the rebuild, a build script controlled by a user could look around the network, find an internal service on the host machine, and read Git credentials exposed through it. Cloudflare fixed it quickly by cutting off the network path.
Background: what the researchers already had
Before this part begins, the researchers already had a foothold. They had placed a reverse shell in a repository. A reverse shell is a small program that, when run, connects back out to the attacker's own computer and gives them a command prompt inside the target machine. Because Cloudflare Pages runs whatever build commands the repository contains, the build itself executed the reverse shell, and the researchers got a shell inside the build container.
The tools they used in this part were:
- A reverse shell placed in the repository, executed by the build.
- Nmap, a program that scans a network to see which ports (numbered doorways on a computer) are open and what might be listening behind them.
- curl, a command-line tool for fetching a URL, useful for poking individual services and seeing what they answer.
- Kiterunner, a tool that guesses common API paths on a web service to discover endpoints that are not advertised.
An API (application programming interface) is the set of URLs and rules a program exposes so other programs can talk to it. Think of a restaurant menu: the kitchen can cook many things, but the menu lists exactly what you are allowed to order and how to ask for it. An endpoint is one line on that menu, one specific URL path such as /pods.
The new environment
When the researchers got a shell on the rebuilt platform, they immediately noticed several changes. They listed them like this:
- The build scripts could not be read: the new user has no permission to read them.
- The environment runs in GKE, a different cloud and infrastructure from before.
- The container is a gVisor container, running as a non-root user.
- Kubernetes API endpoints are reachable with the anonymous role, which by itself is not useful.
- Instance metadata is not accessible.
Each of these deserves a plain explanation.
GKE stands for Google Kubernetes Engine. Kubernetes is a system for running and managing many containers across many machines; it decides where each container runs and keeps them alive. GKE is Google's hosted version of it. Moving to GKE meant the platform had left Microsoft's Azure cloud entirely, so the tricks from the earlier parts, which relied on Azure pipelines, no longer applied.
gVisor is a container runtime, a piece of software that runs containers. Docker's usual runtime is called containerd; gVisor is an alternative that adds an extra layer of protection. Normally a container's programs talk almost directly to the operating system kernel, the core of the machine that controls files, memory and network. gVisor intercepts those calls (called syscalls, short for system calls) and emulates them, checking each one against a list of what the container is allowed to do. The researchers compare it to being able to reach the kernel only through a proxy server with a very strict access control list. A proxy is a middleman that forwards requests; an access control list is a list of who may do what.
Running as a non-root user means the container's user is not the all-powerful administrator account. On Linux, root can do anything; an ordinary user is limited. This is a basic safety measure, like not giving every hotel guest a master key.
Kubernetes API endpoints reachable with the anonymous role means the container could talk to parts of Kubernetes without logging in, but only as an anonymous visitor with almost no rights. By itself that was not useful.
Instance metadata is a special internal address that cloud machines use to hand out information about themselves, sometimes including temporary credentials. Blocking it removes an easy way to steal secrets.
The most important change for the researchers was that they could no longer read the build scripts. In the earlier parts they could read the implementation and audit the source code for vulnerabilities. Audit here means reading code carefully looking for mistakes. Now they were flying blind: they could not see how the other build steps worked, and they could not look for easy command injection bugs. Command injection is a vulnerability where untrusted input is pasted into a system command, so an attacker can add their own commands. Losing that visibility was, in the researchers' words, a total bummer for a researcher.
With all these mitigations in place, they set out once more to escalate privileges (gain more power than they started with) and collect secrets.
Step 1: Scan the neighbouring machine
The first move was to find out what else was on the network. The researchers read their own container's IP address from the network configuration visible in the shell. An IP address is a machine's number on a network, like a street address. They then scanned nearby addresses on the same subnet. A subnet is a block of addresses that belong together, like a street of houses.
They started with the .1 address in the subnet, because in a Kubernetes or Docker environment that address is normally the host, the physical or virtual machine that the containers are running on. Think of the host as the building and the containers as flats inside it; .1 is the front door.
In a properly locked-down Kubernetes environment with network policies in place, the researchers expected this scan to yield very little. A network policy is a rule that says which containers may talk to which other machines. They certainly did not expect to find control plane services, the management parts of Kubernetes, beyond those needed to run the build. Instead, several ports answered:
Scanning [redacted] [65535 ports]
Discovered open port 22/tcp on [redacted]
Discovered open port 10256/tcp on [redacted]
Discovered open port 10250/tcp on [redacted]
Discovered open port 2020/tcp on [redacted]
Discovered open port 10255/tcp on [redacted]
Discovered open port 31501/tcp on [redacted]
Discovered open port 2021/tcp on [redacted]
Completed Connect Scan at 00:06, 4.79s elapsed (65535 total ports)
Nmap scan report for [redacted]
Host is up, received user-set (0.0035s latency).
Scanned at 2022-01-22 00:06:18 UTC for 5s
Not shown: 65528 closed ports
Reason: 65528 conn-refused
PORT STATE SERVICE REASON
22/tcp open ssh syn-ack
2020/tcp open unknown syn-ack
2021/tcp open unknown syn-ack
10250/tcp open unknown syn-ack
10255/tcp open unknown syn-ack
10256/tcp open unknown syn-ack
31501/tcp open unknown syn-ack
Line by line:
Scanning [redacted] [65535 ports]says Nmap is checking every port on that one address. A computer has 65,535 possible port numbers; each is a doorway a service can listen on.- Each
Discovered open port ...line reports a doorway that answered.22/tcpmeans port 22 using TCP, the standard protocol for reliable connections. Port 22 is traditionally SSH, the secure remote login service. Completed Connect Scan at 00:06, 4.79s elapsed (65535 total ports)says the scan finished in under five seconds.Nmap scan report for [redacted]begins the summary.Host is up, received user-set (0.0035s latency)means the machine answered and the round trip took about 3.5 milliseconds.Not shown: 65528 closed portsandReason: 65528 conn-refusedmean the other 65,528 doorways refused the connection, so only seven were open.- The table lists each open port, its state (
open), a guessed service name (sshfor 22,unknownfor the rest) and the reason (syn-ack, the network handshake that proves something is listening).
Seven open ports on the host was far more than expected. The researchers now had a list of doors to knock on.
Step 2: Knock on each port
Probing each port gave varying amounts of information. Some returned a plain 404. A 404 is the standard web response for "not found", the same code a browser shows when you visit a page that does not exist.
curl [redacted]:2021 -v
* Rebuilt URL to: [redacted]:2021/
* Trying 10.124.165.1...
* Connected to [redacted] ([redacted]) port 2021 (#0)
>GET / HTTP/1.1
>Host: [redacted]:2021
>User-Agent: curl/7.47.0
>Accept: **/**
>
<HTTP/1.1 404 Not Found
<Content-Type: text/plain; charset=utf-8
<X-Content-Type-Options: nosniff
<Date: Sat, 22 Jan 2022 00:07:10 GMT
<Content-Length: 19
<
404 page not found
* Connection #0 to host [redacted] left intact
Line by line:
curl [redacted]:2021 -vasks curl to fetch the root page from port 2021 on that address. The-vmeans verbose: show the whole conversation, not just the page.- The lines starting with
*are curl's own notes: it rebuilt the URL, tried the address, connected to port 2021, and numbered the connection#0. - Lines starting with
>are what curl sent.GET / HTTP/1.1means "give me the root page using version 1.1 of HTTP", the language browsers and servers speak.Hosttells the server which name was requested.User-Agentidentifies the client as curl version 7.47.0.Acceptlists what content types are welcome. - Lines starting with
<are the server's reply.HTTP/1.1 404 Not Foundis the status: the page does not exist.Content-Type: text/plain; charset=utf-8says the body is plain text.X-Content-Type-Options: nosnifftells browsers not to second-guess the content type.Dateis the server's clock.Content-Length: 19says the body is 19 bytes long. 404 page not foundis the body itself.* Connection #0 to host [redacted] left intactis curl noting the connection closed cleanly.
Other ports revealed what was running. Port 2020 returned a 200, the standard "OK" response, with a Server: Monkey/1.7.0 header and a JSON body describing a program called fluent-bit. JSON is a simple text format for structured data, made of names and values in curly braces.
buildbot@build-prod-3330469-v7jkn:~/repo$ curl [redacted]:2020 -v
curl [redacted]:2020 -v
* Rebuilt URL to: [redacted]:2020/
* Trying 10.124.165.1...
* Connected to [redacted] ([redacted]) port 2020 (
> GET / HTTP/1.1
> Host: [redacted]:2020
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Monkey/1.7.0
< Date: Sat, 22 Jan 2022 00:07:02 GMT
< Transfer-Encoding: chunked
<
* Connection
{"fluent-bit":{"version":"1.5.7","edition":"Community","flags":["FLB_HAVE_PARSER","FLB_HAVE_RECORD_ACCESSOR","FLB_HAVE_STREAM_PROCESSOR","FLB_HAVE_TLS","FLB_HAVE_AWS","FLB_HAVE_SIGNV4","FLB_HAVE_SQLDB","FLB_HAVE_METRICS","FLB_HAVE_HTTP_SERVER","FLB_HAVE_SYSTEMD","FLB_HAVE_FORK","FLB_HAVE_TIMESPEC_GET","FLB_HAVE_GMTOFF","FLB_HAVE_UNIX_SOCKET","FLB_HAVE_PROXY_GO","FLB_HAVE_SYSTEM_STRPTIME","FLB_HAVE_JEMALLOC","FLB_HAVE_LIBBACKTRACE","FLB_HAVE_REGEX","FLB_HAVE_UTF8_ENCODER","FLB_HAVE_LUAJIT","FLB_HAVE_C_TLS","FLB_HAVE_ACCEPT4","FLB_HAVE_INOTIFY"]}}
Line by line:
buildbot@build-prod-3330469-v7jkn:~/repo$is the shell prompt: the user isbuildbot, the machine isbuild-prod-3330469-v7jkn, and the current folder is~/repo. This shows the command was run from inside the build container.- The curl command and its
*notes work as before, this time against port 2020. > GET / HTTP/1.1and the following>lines are the request, identical in shape to the previous one.< HTTP/1.1 200 OKis the success status.< Server: Monkey/1.7.0names the web server software and version.< Transfer-Encoding: chunkedmeans the body is sent in pieces rather than with a fixed length.- The JSON body says fluent-bit is version 1.5.7, Community edition, and lists its compiled-in features as
flags. fluent-bit is a log collector: software that gathers log messages from other programs. The flags are simply the capabilities it was built with.
This confirmed the researchers' suspicion: they were seeing the monitoring and internal services running in the cluster, on the host. Manual probing of these services did not turn up useful information or privileged access that could be used to escape the container again. The services expose specific, limited API paths, often appearing to be Go binaries serving API endpoints. Go is a programming language; a binary is a compiled program. So the next step was to discover what each service was, which is hard without knowing the paths in advance.
Step 3: Guess the API paths with Kiterunner
The researchers set up Kiterunner and pointed it at each open port. Kiterunner works by trying a large list of common API paths against a service and noting which ones answer differently from the rest. This identified an interesting endpoint on the host, on port 10255, named /pods. A quick search confirms this is the internal kubelet API used by Kubernetes.
Kubelet is the Kubernetes agent that runs on every machine in a cluster and manages the containers on it. It has its own small API, separate from the main Kubernetes API, and /pods is the path that lists the pods. A pod is the smallest unit Kubernetes runs: usually one container, wrapped with some settings. Think of the kubelet as the building supervisor and /pods as the list of residents.
Step 4: Read the pod list and find credentials
The kubelet API differs from the Kubernetes API in that it cannot modify Kubernetes objects. It is read-only, so it cannot be used to change anything. However, the output let the researchers dump the details of each pod running on the host:
curl -v -k http://[redacted]:10255/pods
Line by line:
curlis the fetching tool.-vmeans verbose, show the whole conversation.-kmeans insecure: accept a TLS certificate without checking it. TLS is the encryption that puts the S in HTTPS; normally curl refuses to talk to a server whose certificate it cannot verify, and-koverrides that.http://[redacted]:10255/podsis the address: plain HTTP, the host at[redacted], port 10255, path/pods.
Grepping this output for CREDS found GIT_CREDS. Grep is a command-line search tool: it prints the lines of its input that match a pattern. CREDS is short for credentials. GIT_CREDS is the name of a setting that holds Git credentials. Git is the version-control system that stores code repositories; credentials are what prove you are allowed to read or write a repository, like a library card. The researchers describe finding this as an atomic-level bout of deja vu, because it echoed the Git credential finding from the earlier part of the series.
Step 5: Test the credentials and widen the scope
Testing the Git credentials, the researchers could only see their own private repositories this time. That still means private repository access from outside their organisation, which is potentially sensitive for large organisations with multiple private repositories. A private repository is one only invited people can read; if its credentials leak, an outsider can read the code.
To see whether the finding could be widened, they ran an nmap scan for port 10255 across [redacted]/16, in case other tenants or hosts were reachable. The /16 is a size notation: it describes a block of addresses, here a very large one covering many machines. A tenant is one customer sharing the platform with others. A number of different hosts were accessible and returned the same data. That indicates that if other builds were running anywhere in this GKE account for other users and organisations, their Git credentials could also be stolen.
In the HackerOne report, Sean quoted:
guess who's back. back again. shady's back. call a friend
Why it worked
The build pods could reach the host's kubelet read-only endpoint on port 10255, and that endpoint exposed pod details including Git credentials. The network boundary between the build pod and the host was not enforced, so a user-controlled build script could scan the subnet, find the kubelet API, and read pod details including Git credentials. The scan across [redacted]/16 showing multiple hosts with the same data suggests the exposure was not limited to a single tenant's build.
The earlier mitigations did not stop this. The build scripts were no longer readable, the container ran as non-root under gVisor, and instance metadata was blocked, but none of those controls addressed pod-to-host network reachability. The kubelet read-only API was reachable from the build pod and was enough to disclose pod details.
In plain terms: the platform had locked the doors and windows of each flat, but had left a shared corridor connecting every flat to the building supervisor's office, and the supervisor's noticeboard listed everyone's keys.
What an attacker could do
An attacker who controls a build script could read Git credentials for builds running on reachable hosts. In this instance the credentials only gave access to the researchers' own private repositories, but the same data was returned by a number of hosts across the scanned range, so other users' and organisations' Git credentials would be exposed under the same conditions. For a large organisation with multiple private repositories, that access is potentially sensitive.
The fix
Cloudflare remediated the issue quickly. The researchers presume the remedy was a judicious application of iptables rules or pod network security policies; they could not confirm the exact change because access was locked down again afterwards. iptables is the Linux firewall: a list of rules saying which network traffic is allowed in or out. A pod network security policy is the Kubernetes equivalent, applied to pods.
Once appropriate network isolation was in place, the problem was effectively mitigated. The takeaway for defenders is to ensure appropriate network segregation and firewalling in complex network environments, reflecting the security boundaries of the application. Isolating different tenant networks at build time would be enough for this case, but preventing all communication from pod to host was the more effective and airtight fix.
Things to try if you test similar systems
- Scan the default gateway of a build or CI container for the kubelet read-only port. A positive result is a response on port 10255 that returns pod data.
- Request
/podson any discovered kubelet endpoint and grep the output for credential-like strings such asGIT_CREDS. A positive result is credentials belonging to a build other than your own. - Scan the wider pod subnet for the same port to check whether other hosts are reachable. A positive result is multiple hosts returning the same pod data, which indicates cross-tenant exposure.
- Run Kiterunner against other open ports on the host to find undocumented API endpoints. A positive result is an endpoint that returns internal service or build information.
- Probe monitoring services such as fluent-bit's HTTP server for version and configuration details. A positive result is a version banner or configuration that helps identify further attack paths.
Glossary
- API: the set of URLs and rules a program exposes so other programs can talk to it, like a restaurant menu.
- API endpoint: one specific URL path on an API, such as
/pods. - Audit: reading code carefully looking for mistakes.
- Binary: a compiled program, ready to run.
- Build: the set of commands that turns source files into a finished website or program.
- Build container: the sealed-off mini-computer where a build runs.
- Command injection: a vulnerability where untrusted input is pasted into a system command, letting an attacker add their own commands.
- Container: a sealed-off mini-computer inside a bigger computer, with its own files and processes.
- Container runtime: the software that runs containers, such as containerd or gVisor.
- Control plane: the management parts of Kubernetes that decide what runs where.
- Credentials: secrets that prove who you are and what you may access, like a library card.
- curl: a command-line tool for fetching a URL.
- Endpoint: see API endpoint.
- Escalate privileges: gain more power than you started with.
- Firewall: a list of rules saying which network traffic is allowed in or out.
- fluent-bit: a log collector, software that gathers log messages from other programs.
- Git: the version-control system that stores code repositories.
- GKE: Google Kubernetes Engine, Google's hosted Kubernetes service.
- Go: a programming language.
- grep: a command-line search tool that prints lines matching a pattern.
- gVisor: a container runtime that intercepts and emulates system calls for extra protection.
- HackerOne: a bug bounty platform where companies invite researchers to test their systems.
- Host: the physical or virtual machine that containers run on.
- HTTP: the language browsers and servers speak to exchange pages and data.
- Instance metadata: a special internal address cloud machines use to hand out information about themselves, sometimes including temporary credentials.
- IP address: a machine's number on a network, like a street address.
- iptables: the Linux firewall.
- JSON: a simple text format for structured data, made of names and values in curly braces.
- Kiterunner: a tool that guesses common API paths on a web service to discover endpoints.
- Kubelet: the Kubernetes agent on each machine that manages the containers on it.
- Kubernetes: a system for running and managing many containers across many machines.
- Network policy: a rule saying which containers may talk to which other machines.
- Nmap: a program that scans a network to see which ports are open.
- Non-root user: an ordinary user account, not the all-powerful administrator.
- Pod: the smallest unit Kubernetes runs, usually one container with some settings.
- Port: a numbered doorway on a computer that a service can listen on.
- Private repository: a code repository only invited people can read.
- Proxy: a middleman that forwards requests.
- Re-architect: rebuild a system from scratch with a different design.
- Repository: a folder of a project's files, stored online, usually with its history.
- Reverse shell: a small program that connects back out to the attacker's computer and gives them a command prompt inside the target machine.
- Root: the all-powerful administrator account on Linux.
- SSH: the secure remote login service, traditionally on port 22.
- Subnet: a block of IP addresses that belong together, like a street of houses.
- Syscall: short for system call, a request from a program to the operating system kernel.
- TCP: the standard protocol for reliable network connections.
- Tenant: one customer sharing a platform with others.
- TLS: the encryption that puts the S in HTTPS.
- Vulnerability: a weakness that lets someone do something they should not be able to do.