Skip to content
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

New container locator for docker/k8s on linux #5076

Merged
merged 11 commits into from
Apr 24, 2024

Commits on Apr 18, 2024

  1. New container locator for docker/k8s on linux

    The docker and k8s workload attestors work backwards from pid to
    container by inspecting the proc filesystem. Today, this happens by
    inspecting the cgroup file. Identifying the container ID (and pod UID)
    from the cgroup file has been a continual arms race. The k8s and docker
    workload attestors grew different mechanisms for trying to deal with the
    large variety in the output.
    
    Further, with cgroups v2 and private namespaces, the cgroup file might
    not have the container ID or pod UID information within it.
    
    This PR unifies the container ID (and pod UID) extraction for both the
    docker and k8s workload attestors. The new implementation searches the
    mountinfo file first for cgroups mounts. If not found, it will fall back
    to the cgroup file (typically necessary only when the workload is
    running in the same container as the agent).
    
    The extraction algorithm is the same for both mountinfo and cgroup
    entries, and is as follows:
    1. Iterator over each entry in the file being searched, extracting
       either the cgroup mount root (mountinfo) or the cgroup group
       path (cgroup) as the source path.
    2. Walk backwards through the segments in the source path looking for
       the 64-bit hex digit container ID.
    3. If looking for the pod UID (K8s only), then walk backwards through
       the segments in the path looking for the pod UID pattern used by
       kubelet. Start with the segment the container ID was found in
       (truncated to remove the container ID portion).
    4. If there are pod UID/container ID conflicts after searching these
       files then log and abort. Entries that have a pod UID override those
       that don't.
    
    The container ID is very often contained in the last segment in the path
    but there are situations where it isn't.
    
    This new functionality is NOT enabled by default, but opted in using the
    `use_new_container_locator` configurable in each plugin. In 1.10, we can
    consider enabling it by default.
    
    The testing for the new code is spread out a little bit. The cgroups
    fallback functionality is mostly tested by the existing tests in the
    k8s and docker plugin tests. The mountinfo tests are only in the new
    containerinfo package.
    
    In the long term, I'd like to see all of the container info extraction
    related tests moved solely to the containerinfo package and removed from
    the individual plugins.
    
    Resolves spiffe#4004, resolves spiffe#4682, resolves spiffe#4917.
    
    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    4afbcbd View commit details
    Browse the repository at this point in the history
  2. missing new arg

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    5e3d401 View commit details
    Browse the repository at this point in the history
  3. fix windows tests

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    5ad232a View commit details
    Browse the repository at this point in the history
  4. fix windows tests and lint

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    37afbec View commit details
    Browse the repository at this point in the history

Commits on Apr 23, 2024

  1. address pr comments

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    1497de7 View commit details
    Browse the repository at this point in the history
  2. Merge remote-tracking branch 'origin/main' into mountinfo

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    f1a046b View commit details
    Browse the repository at this point in the history
  3. markdown lint

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    3722c4d View commit details
    Browse the repository at this point in the history
  4. add agent full conf

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    b245760 View commit details
    Browse the repository at this point in the history
  5. fix labels

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    c00870c View commit details
    Browse the repository at this point in the history
  6. change log to warn

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    bf723d5 View commit details
    Browse the repository at this point in the history
  7. use new locator in it

    Signed-off-by: Andrew Harding <azdagron@gmail.com>
    azdagron committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    5ed0307 View commit details
    Browse the repository at this point in the history