Telepresence
repository·release/v2·Indexed 11 days ago
https://github.com/telepresenceio/telepresenceA tool for local Kubernetes development that bridges a developer's workstation and a remote cluster, allowing local processes to act as if they are part of the cluster network. It includes server-side components manageable via Helm for configuring traffic managers, agent injectors, and networking options like QUIC tunnels.
What's inside Telepresence
- Telepresence is a CNCF project designed for fast, local development for Kubernetes. It connects your workstation to a Kubernetes cluster, allowing you to code and debug services locally using your own IDE, debugger, and hot reload capabilities. It enables your local process to receive real traffic from the cluster, bypassing the traditional container build/push/deploy cycle.
Use Telepresence Docker Plugins for isolated development
release/v2When starting a Telepresence client with
telepresence connect --docker, the client runs inside a Docker container. This isolation ensures that the network and volume mounts created by Telepresence do not interfere with your workstation's local network or filesystem.To enable this, Telepresence uses two specialized Docker plugins:
- Teleroute Network Plugin: Allows other Docker containers to reach cluster networks via a dedicated Docker network.
- Telemount Volume Plugin: Allows remote directories (provided via SFTP by traffic agents) to be mounted as standard Docker volumes.
These plugins are installed automatically on demand when you run
telepresence connect --docker.telepresence connect --dockerUnderstand Connections and Networking
release/v2Connection
A connection is the link between your workstation and a cluster, established via
telepresence connect. It makes the cluster's network reachable locally and is a prerequisite for creating any attachment. You can have multiple named connections active simultaneously.Virtual network interface (VIF)
The network device created by the Root daemon upon connection. It routes cluster subnets so that local tools can reach cluster services.
Understand Telepresence session credentials
release/v2Telepresence uses session credentials to secure communication between clients and agents. These credentials are minted by the traffic-manager and expire every 24 hours. There are two forms of credentials used depending on the transport layer:
- Client Certificate: Used for TLS-based transports, specifically the QUIC tunnel's mutual-TLS handshake. The
CommonNameis set to the session ID. - Signed Bearer Token: Used for transports that cannot carry a certificate, such as:
- FTP: Used as the FTP password.
- gRPC Metadata: Used for
tunnelanddial-watchercalls on the agent's gRPC surface.
Credentials are regenerated whenever the traffic-manager restarts, which revokes all outstanding credentials.
- Client Certificate: Used for TLS-based transports, specifically the QUIC tunnel's mutual-TLS handshake. The
Understand Telepresence file-sharing authentication
release/v2Telepresence uses two forms of credentials rooted in a single Certificate Authority (
quictunnel.CA) to secure file-sharing and gRPC communication. The authentication enforcement level is tied to the manager'ssecurity.authentication.mode:- disabled / permissive: Credentials are verified and failures are logged, but connections without credentials are still allowed (maintains backward compatibility).
- enforcing: No valid session credential is permitted for any file operation or connection.
Credential Types
- X.509 session client certificate: Used for TLS-based transports like the QUIC tunnel. The Common Name (CN) is set to the
sessionID. - Signed session token: A compact bearer string used for transports that cannot carry certificates (e.g., FTP
PASScommand or gRPC metadata on plaintext port-forwarded channels). The format isv1.<sessionID>.<expiry>.<base64url ECDSA-sig by the CA key>.
Choose between the sidecar and the node-agent
release/v2Telepresence offers two modes for attaching to workloads:
- Sidecar Mode (Default): Uses a mutating webhook to inject an agent container into your pods. This requires a pod restart and modifies the workload's pod template.
- Node-agent Mode: Runs as a node-pinned Kubernetes
Jobthat enters the existing target pod's Linux namespaces from the outside. This requires no workload mutation and no pod restart.
When to use node-agent
- When mutating or restarting the workload is undesirable or disallowed (e.g., expensive startup times).
- When workloads are managed by an operator that conflicts with the sidecar webhook.
- In clusters where the agent-injector is disabled (
agentInjector.enabled=false).
Trade-offs and Requirements
- Privilege: Node-agents require high privileges (
hostPID: true,SYS_ADMIN,SYS_PTRACE,NET_ADMIN, andNET_RAW). - Security Standards: The
traffic-managernamespace must permit the privileged Pod Security Standard. - Incompatibility: Clusters that reject
hostPID(like GKE Autopilot) cannot run node-agents; you must use the sidecar mode there.
# To use node-agent for a specific attachment, use the --node-agent flag telepresence intercept <service> --node-agent # To use node-agent for wiretap telepresence wiretap <service> --node-agent # To use node-agent for ingest telepresence ingest <service> --node-agentChoose a Telepresence installation method
release/v2Telepresence offers two primary installation methods depending on your needs for privilege management:
- Standalone binaries: Manual installation where the root daemon runs on-demand with elevated privileges. Best for users who want manual control.
- Platform installers: Bundles Telepresence with a system service for the root daemon. This eliminates the need for repeated privilege elevation by running the daemon as a persistent background service.
Installers are available for Windows, macOS, and Linux.
Implement certificate-scoping for QUIC authorization
release/v2To achieve RBAC-equivalent security on the QUIC path, authorization must be embedded within the client certificate, as the agent (which terminates the connection) is the only component that can enforce it.
Two implementation strategies were evaluated:
Option A: Session-wide certificate with namespace list
- Mechanism: The manager embeds an allowed set of namespaces in a single session certificate using
Authorizer.CanPortForward. The agent verifies this list during the TLS handshake. - Pros: Single certificate for the session.
- Cons: The scope is frozen for the certificate's lifetime (e.g., 24h via
clientCertValidity). Revoking RBAC does not take effect until the certificate expires.
Option B: Per-agent certificates (Recommended)
- Mechanism: The manager provides a new RPC
GetQuicAgentClientCert(session, podUID). This mints a short-lived certificate specifically for one agent, naming that agent's identity. The agent verifies that the presented certificate matches its own SNI. - Pros:
- Authorizes against the actual target.
- Supports per-pod-name RBAC via
CanPortForward's fallback. - Naturally short-lived (minutes instead of hours).
- Composes well with session binding requirements.
- Cons: Requires one extra unary RPC per agent per session.
- Mechanism: The manager embeds an allowed set of namespaces in a single session certificate using
How the fixture engine works
release/v2The framework uses
rt.Fixture[T]to manage resources via declarative, memoized specs.Key Concepts
- Memoization:
rt.Get(t, f)returns a resource. If the resource exists and matches the spec, it is reused. If not, it is provisioned. A provisioning failure for a fixture will cause all subsequent tests requiring that fixture to be skipped. - Mutation:
rt.Mutate(t, f)is used when a test needs to change a shared resource (like a manager spec or a workload). It performs aGetfollowed by invalidation at the end of the test, ensuring the next test re-provisions the new state. - Lazy Provisioning: Suites do not provision in
SetupSuite. Resources are only provisioned when an accessor (likes.Manager()) is called. This allows filtered test runs to be extremely fast. - Mutual Exclusivity: Manager specs are mutually exclusive. Provisioning a new spec invalidates all previous specs and connections, as the rollout replaces the pods used for port-forwarding.
- Workload Lifecycle: Workloads are always destroyed at the end of a run (even in dev mode) to prevent node resource exhaustion. If a workload manifest changes, it is deleted and recreated.
- Adoption: In dev mode (without
RTEST_TEARDOWN), the framework attempts to 'adopt' existing namespaces, releases, and connections from previous runs to speed up subsequent tests.
- Memoization:
How the Telemount Volume Plugin works
release/v2The Telemount plugin allows remote directories from Kubernetes traffic agents to be mounted as Docker volumes in your local containers. This is used during attachment commands like
telepresence ingest,intercept,replace, orwiretap.Workflow:
- The daemon starts a bridge mounter that proxies the traffic agent's SFTP server to the daemon's localhost.
- When attaching a container (using
--docker-run,--docker-build, or--docker-debug), Telepresence merges volume flags from the command line (-v,--volume,--mount) with volumes propagated from the remote pod's traffic agent. Command-line flags take priority. - For each volume, Telepresence executes
docker create volume --driver=telemount, passing the SFTP proxy port. - The container is started with the resulting volumes attached.
- Upon detachment, volumes are unmounted and removed, and the SFTP proxy is closed.
Configuration:
- The plugin registry, name, and tag can be configured via
docker.telemountinconfig.yml.
How DNS resolution works in Telepresence
release/v2Telepresence uses a dynamic DNS resolver to map cluster service names to IPs.
Namespace Resolution Rules:
- Current Namespace: Processes running locally can reach services in the currently managed namespace using just the
service-name. - Other Namespaces: To reach services in other managed namespaces, use the format
<service-name>.<namespace>.
Configuration & Customization:
- You can expand the list of names Telepresence resolves by using the
includeSuffixesormappingsoptions in the cluster DNS configuration. - Query Types Supported:
A,AAAA,CNAME,MX,NS,PTR,SRV, andTXT. - Caching: Telepresence uses short TTLs (Time To Live) for records to ensure quick eviction when configurations change. It also maintains an internal cache to minimize the load on the cluster resolver.
- Current Namespace: Processes running locally can reach services in the currently managed namespace using just the
Configure the Traffic Manager agent mode (Sidecar vs Node-agent)
release/v2When a developer attaches to a workload, the Traffic Manager places a
traffic-agentnext to the application. You can choose between two modes:- Sidecar (Default): The
agent-injectorwebhook adds the agent as a sidecar container. This requires restarting the workload's pods once. - Node-agent: A node-hosted agent that attaches to existing pods without modifying or restarting them. This requires running with privileged permissions.
To enable the node-agent during installation:
telepresence helm install --set nodeAgent.enabled=true- Sidecar (Default): The