Skip to content

Commit 4848232

Browse files
authored
Merge pull request kubernetes#1690 from verb/ec2
Propose removing and security context for Ephemeral Containers
2 parents 49c7eac + ffa43b5 commit 4848232

File tree

1 file changed

+132
-19
lines changed
  • keps/sig-node/277-ephemeral-containers

1 file changed

+132
-19
lines changed

keps/sig-node/277-ephemeral-containers/README.md

Lines changed: 132 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
- [Non-Goals](#non-goals)
1111
- [Proposal](#proposal)
1212
- [Creating Ephemeral Containers](#creating-ephemeral-containers)
13-
- [Restarting and Reattaching Ephemeral Containers](#restarting-and-reattaching-ephemeral-containers)
13+
- [Identifying Pods with Ephemeral Containers](#identifying-pods-with-ephemeral-containers)
14+
- [Reattaching and Restarting Ephemeral Containers](#reattaching-and-restarting-ephemeral-containers)
15+
- [Configurable Security Policy](#configurable-security-policy)
16+
- [Specifying Security Context](#specifying-security-context)
17+
- [Compatibility with existing Admission Controllers](#compatibility-with-existing-admission-controllers)
1418
- [Killing Ephemeral Containers](#killing-ephemeral-containers)
19+
- [Removing and Re-adding Ephemeral Containers](#removing-and-re-adding-ephemeral-containers)
1520
- [User Stories](#user-stories)
1621
- [Operations](#operations)
1722
- [Debugging](#debugging)
@@ -181,10 +186,12 @@ restrictions:
181186

182187
### Creating Ephemeral Containers
183188

184-
1. A client constructs an `EphemeralContainer` based on command line and
185-
and appends it to `Pod.Spec.EphemeralContainers`. It updates the pod using
186-
the pod's `/ephemeralcontainers` subresource.
187-
1. The apiserver validates and performs the pod update.
189+
1. A client fetches the current list of Ephemeral Containers in a pod using
190+
`GetEphemeralContainers` in the generated client. This returns a
191+
`v1.EphemeralContainers` to which the client appends a new
192+
`EphemeralContainer` and then calls `UpdateEphemeralContainers`.
193+
1. The apiserver validates and performs the pod update, copying the new
194+
ephemeral container into `Pod.Spec.EphemeralContainers`.
188195
1. Pod validation fails if container spec contains fields disallowed for
189196
Ephemeral Containers or the same name as a container in the spec or
190197
`EphemeralContainers`.
@@ -206,29 +213,135 @@ There are no limits on the number of Ephemeral Containers that can be created in
206213
a pod, but exceeding a pod's resource allocation may cause the pod to be
207214
evicted.
208215

209-
### Restarting and Reattaching Ephemeral Containers
216+
### Identifying Pods with Ephemeral Containers
210217

211-
Ephemeral Containers will not be restarted.
218+
The kubelet will set a `PodCondition` when it starts an Ephemeral Container.
219+
This condition may not be cleared: it will exist for the lifetime of the Pod
220+
and continues to exist even if all Ephemeral Containers are removed.
212221

213-
We want to be more user friendly by allowing re-use of the name of an exited
214-
ephemeral container, but this will be left for a future improvement.
222+
The intended use of this `PodCondition` is to enable administrators to enforce
223+
custom policies for pods that have had Ephemeral Containers. For example,
224+
cluster administrators may want to automatically apply a label or delete the pod
225+
after a configurable time. This may be accomplished by a controller watching
226+
for this `PodCondition`, though the implementation of such a controller is out
227+
of scope for this proposal.
228+
229+
### Reattaching and Restarting Ephemeral Containers
215230

216231
One can reattach to a Ephemeral Container using `kubectl attach`. When supported
217232
by a runtime, multiple clients can attach to a single debug container and share
218233
the terminal. This is supported by Docker.
219234

220-
### Killing Ephemeral Containers
235+
Ephemeral Containers will not be restarted automatically, and there is no
236+
method in the API to restart an Ephemeral Container. Creators of Ephemeral
237+
Containers are expected to choose a new, unused name.
238+
239+
### Configurable Security Policy
240+
241+
The ability to add containers to a pod implies security trade offs. We've
242+
received the following requirements and feedback on the alpha implementation:
243+
244+
* Admission controllers should be able to enforce policy based on the
245+
cumulative pod specification, so operations that prune information,
246+
such as removing Ephemeral Containers should not be allowed.
247+
* Restarting a pod is disruptive, so for reasons of operation, security,
248+
and resource hygiene it should be possible to delete Ephemeral Containers
249+
via the API. ([#84764]).
250+
* Ephemeral Containers could allow privilege escalation greater than that
251+
of the initial pod, so setting a custom security context should not be
252+
allowed.
253+
* Ephemeral Containers, which are initiated by humans for debugging purposes,
254+
should be allowed a more permissive security context regular containers.
255+
([#53188])
256+
257+
Security policy is a problem better solved through the existing extension
258+
mechanism for applying custom policy: [Admission Controllers].
259+
260+
Cluster administrators will be expected to choose from one of the following
261+
mechanisms for restricting usage of ephemeral containers:
262+
263+
* Use RBAC to control which users are allowed to access the
264+
`/ephemeralcontainers` subresource.
265+
* Write or use a third-party admission controller to allow or reject
266+
Pod updates that modify ephemeral containers based on the content of
267+
the update.
268+
* Disable the feature using the `EphemeralContainers` feature gate.
269+
270+
This means that all ephemeral container features will be allowed in a default
271+
Kubernetes install.
272+
273+
[Admission Controllers]: https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/
274+
275+
#### Specifying Security Context
276+
277+
The initial implementation of Ephemeral Containers prohibited setting a
278+
`securityContext` for an Ephemeral Container. This is now explicitly allowed.
279+
Cluster administrators wishing to limit this feature should prevent this using
280+
admission control or RBAC.
281+
282+
#### Compatibility with existing Admission Controllers
283+
284+
Existing Admission Controllers concerned with security will need to be updated
285+
to examine the `securityContext` of `ephemeralContainers`. Admission Controllers
286+
configured to fail open (for example, by ignoring updates using the
287+
`/ephemeralcontainers` subresource or not checking ephemeral containers for
288+
a security context) are at risk of no longer protecting against privilege
289+
escalation.
290+
291+
Because the initial implementation of the Ephemeral Containers API specified
292+
that `securityContext` in ephemeral containers is not allowed, some Admission
293+
Controllers may have chosen to ignore this field.
294+
295+
Since it's not feasible to discover how many admission controllers are affected
296+
by this, the best way to move forward is to make the change sooner rather than
297+
later and emphasize the change in release notes. We'll stress that cluster
298+
administrators should ensure that their admission controllers support ephemeral
299+
containers prior to upgrading and provide instructions for how to disable
300+
ephemeral container creation in a cluster.
221301

222-
Ephemeral Containers will not be killed automatically unless the pod is
223-
destroyed. Ephemeral Containers will stop when their command exits, such as
224-
exiting a shell. Unlike `kubectl exec`, processes in Ephemeral Containers will
225-
not receive an EOF if their connection is interrupted.
302+
### Killing Ephemeral Containers
226303

227-
A future improvement could allow killing Ephemeral Containers when they're
228-
removed from `EphemeralContainers`, but it's not clear that we want to allow
229-
this. Removing an Ephemeral Container spec makes it unavailable for future
230-
authorization decisions (e.g. whether to authorize exec in a pod that had a
231-
privileged Ephemeral Container).
304+
Ephemeral Containers will stop when their command exits, such as exiting a
305+
shell, and they will not be restarted. Unlike `kubectl exec`, processes in
306+
Ephemeral Containers will not receive an EOF if their connection is
307+
interrupted, so shells won't automatically exit on disconnect. Without the
308+
ability to remove an Ephemeral Container via the API, the only way to exit the
309+
container is to send it an OS signal.
310+
311+
Killing an Ephemeral Container is supported by removing it from the list of
312+
Ephemeral Containers in the Pod spec. The kubelet will then kill the container
313+
and cease publishing a `ContainerStatus` for this container.
314+
315+
#### Removing and Re-adding Ephemeral Containers
316+
317+
An edge case worth considering is what happens when a user removes and re-adds
318+
a Ephemeral Container with the same name. This presents a synchronization
319+
problem not present in the immutable container lists, which we resolve by
320+
enforcing the following constraints:
321+
322+
- The client MUST NOT add an Ephemeral Container with the same name as
323+
a container listed in `Pod.Status.EphemeralContainerStatuses`. This is an
324+
error and will be rejected by the API server.
325+
- The kubelet MAY continue publishing an `EphemeralContainerStatus` for
326+
an Ephemeral Container that no longer appears in
327+
`Pod.Spec.EphemeralContainers`.
328+
- The kubelet MUST start a new container for any container in
329+
`Pod.Spec.EphemeralContainers` that does not also appear in
330+
`Pod.Status.EphemeralContainerStatuses.
331+
332+
In this way the kubelet is able to signal to clients the set of container names
333+
which are unavailable because they correspond to containers still running on
334+
the node. The procedure for replacing a container then becomes:
335+
336+
1. A client removes an Ephemeral Container from `Pod.Spec.EphemeralContainers`.
337+
2. The client waits for the Ephemeral Container to be removed from
338+
`Pod.Status.EphemeralContainerStatuses`.
339+
3. The client adds an Ephemeral Container with the same name to
340+
`Pod.Spec.EphemeralContainers`.
341+
342+
This is not recommended, however, because the kubelet is under no obligation to
343+
remove the Ephemeral Container from `EphemeralContainerStatuses` in a timely
344+
fashion. Clients should choose a new container name instead.
232345

233346
### User Stories
234347

0 commit comments

Comments
 (0)