|
| 1 | +--- |
| 2 | +reviewers: |
| 3 | +- sftim |
| 4 | +- marosset |
| 5 | +- jsturtevant |
| 6 | +- zshihang |
| 7 | +title: Projected Volumes |
| 8 | +content_type: concept |
| 9 | +--- |
| 10 | + |
| 11 | +<!-- overview --> |
| 12 | + |
| 13 | +This document describes the current state of _projected volumes_ in Kubernetes. Familiarity with [volumes](/docs/concepts/storage/volumes/) is suggested. |
| 14 | + |
| 15 | +<!-- body --> |
| 16 | + |
| 17 | +## Introduction |
| 18 | + |
| 19 | +A `projected` volume maps several existing volume sources into the same directory. |
| 20 | + |
| 21 | +Currently, the following types of volume sources can be projected: |
| 22 | + |
| 23 | +* [`secret`](/docs/concepts/storage/volumes/#secret) |
| 24 | +* [`downwardAPI`](/docs/concepts/storage/volumes/#downwardapi) |
| 25 | +* [`configMap`](/docs/concepts/storage/volumes/#configmap) |
| 26 | +* `serviceAccountToken` |
| 27 | + |
| 28 | +All sources are required to be in the same namespace as the Pod. For more details, |
| 29 | +see the [all-in-one volume design document](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/node/all-in-one-volume.md). |
| 30 | + |
| 31 | +### Example configuration with a secret, a downwardAPI, and a configMap {#example-configuration-secret-downwardapi-configmap} |
| 32 | + |
| 33 | +{{< codenew file="pods/storage/projected-secret-downwardapi-configmap.yaml" >}} |
| 34 | + |
| 35 | +### Example configuration: secrets with a non-default permission mode set {#example-configuration-secrets-nondefault-permission-mode} |
| 36 | + |
| 37 | +{{< codenew file="pods/storage/projected-secrets-nondefault-permission-mode.yaml" >}} |
| 38 | + |
| 39 | +Each projected volume source is listed in the spec under `sources`. The |
| 40 | +parameters are nearly the same with two exceptions: |
| 41 | + |
| 42 | +* For secrets, the `secretName` field has been changed to `name` to be consistent |
| 43 | + with ConfigMap naming. |
| 44 | +* The `defaultMode` can only be specified at the projected level and not for each |
| 45 | + volume source. However, as illustrated above, you can explicitly set the `mode` |
| 46 | + for each individual projection. |
| 47 | + |
| 48 | +When the `TokenRequestProjection` feature is enabled, you can inject the token |
| 49 | +for the current [service account](/docs/reference/access-authn-authz/authentication/#service-account-tokens) |
| 50 | +into a Pod at a specified path. For example: |
| 51 | + |
| 52 | +{{< codenew file="pods/storage/projected-service-account-token.yaml" >}} |
| 53 | + |
| 54 | +The example Pod has a projected volume containing the injected service account |
| 55 | +token. This token can be used by a Pod's containers to access the Kubernetes API |
| 56 | +server. The `audience` field contains the intended audience of the |
| 57 | +token. A recipient of the token must identify itself with an identifier specified |
| 58 | +in the audience of the token, and otherwise should reject the token. This field |
| 59 | +is optional and it defaults to the identifier of the API server. |
| 60 | + |
| 61 | +The `expirationSeconds` is the expected duration of validity of the service account |
| 62 | +token. It defaults to 1 hour and must be at least 10 minutes (600 seconds). An administrator |
| 63 | +can also limit its maximum value by specifying the `--service-account-max-token-expiration` |
| 64 | +option for the API server. The `path` field specifies a relative path to the mount point |
| 65 | +of the projected volume. |
| 66 | + |
| 67 | +{{< note >}} |
| 68 | +A container using a projected volume source as a [`subPath`](/docs/concepts/storage/volumes/#using-subpath) |
| 69 | +volume mount will not receive updates for those volume sources. |
| 70 | +{{< /note >}} |
| 71 | + |
| 72 | +## SecurityContext interactions |
| 73 | + |
| 74 | +The [proposal for file permission handling in projected service account volume](https://github.com/kubernetes/enhancements/pull/1598) |
| 75 | +enhancement introduced the projected files having the the correct owner |
| 76 | +permissions set. |
| 77 | + |
| 78 | +### Linux |
| 79 | + |
| 80 | +In Linux pods that have a projected volume and `RunAsUser` set in the Pod |
| 81 | +[`SecurityContext`](/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context), |
| 82 | +the projected files have the correct ownership set including container user |
| 83 | +ownership. |
| 84 | + |
| 85 | +### Windows |
| 86 | + |
| 87 | +In Windows pods that have a projected volume and `RunAsUsername` set in the |
| 88 | +Pod `SecurityContext`, the ownership is not enforced due to the way user |
| 89 | +accounts are managed in Windows. Windows stores and manages local user and group |
| 90 | +accounts in a database file called Security Account Manager (SAM). Each |
| 91 | +container maintains its own instance of the SAM database, to which the host has |
| 92 | +no visibility into while the container is running. Windows containers are |
| 93 | +designed to run the user mode portion of the OS in isolation from the host, |
| 94 | +hence the maintenance of a virtual SAM database. As a result, the kubelet running |
| 95 | +on the host does not have the ability to dynamically configure host file |
| 96 | +ownership for virtualized container accounts. It is recommended that if files on |
| 97 | +the host machine are to be shared with the container then they should be placed |
| 98 | +into their own volume mount outside of `C:\`. |
| 99 | + |
| 100 | +By default, the projected files will have the following ownership as shown for |
| 101 | +an example projected volume file: |
| 102 | +```powershell |
| 103 | +Path : Microsoft.PowerShell.Core\FileSystem::C:\var\run\secrets\kubernetes.io\serviceaccount\..2021_08_31_22_22_18.318230061\ca.crt |
| 104 | +Owner : BUILTIN\Administrators |
| 105 | +Group : NT AUTHORITY\SYSTEM |
| 106 | +Access : NT AUTHORITY\SYSTEM Allow FullControl |
| 107 | + BUILTIN\Administrators Allow FullControl |
| 108 | + BUILTIN\Users Allow ReadAndExecute, Synchronize |
| 109 | +Audit : |
| 110 | +Sddl : O:BAG:SYD:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU) |
| 111 | +``` |
| 112 | +This implies all administrator users like `ContainerAdministrator` will have |
| 113 | +read, write and execute access while, non-administrator users will have read and |
| 114 | +execute access. |
| 115 | + |
| 116 | +{{< note >}} |
| 117 | +In general, granting the container access to the host is discouraged as it can |
| 118 | +open the door for potential security exploits. |
| 119 | + |
| 120 | +Creating a Windows Pod with `RunAsUser` in it's `SecurityContext` will result in |
| 121 | +the Pod being stuck at `ContainerCreating` forever. So it is advised to not use |
| 122 | +the Linux only `RunAsUser` option with Windows Pods. |
| 123 | +{{< /note >}} |
0 commit comments