Control: 3.15 Ensure that the Docker socket file ownership is set to root:docker
Description
You should verify that the Docker socket file is owned by root and group owned by
docker.
The Docker daemon runs as root. The default Unix socket therefore must be owned by
root. If any other user or process owns this socket, it might be possible for that nonprivileged user or process to interact with the Docker daemon. Additionally, in this case a non-privileged user or process might be able to interact with containers which is neither a secure nor desired behavior.
Additionally, the Docker installer creates a Unix group called docker. You can add users to this group, and in this case, those users would be able to read and write to the default Docker Unix socket. The membership of the docker group is tightly controlled by the system administrator. However, ff any other group owns this socket, then it might be possible for members of that group to interact with the Docker daemon. Such a group might not be as tightly controlled as the docker group. Again, this is not in line with good security practice.
For these reason, the default Docker Unix socket file should be owned by root and group owned by docker to maintain the integrity of the socket file.
Remediation
The following command could be executed:
chown root:docker /var/run/docker.sock
This sets the ownership to root and group ownership to docker for the default Docker socket file.
Default Value
By default, the ownership and group ownership for the Docker socket file is correctly set to root:docker.
Usage
Run the control in your terminal:
powerpipe control run docker_compliance.control.cis_v160_3_15Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run docker_compliance.control.cis_v160_3_15 --shareSQL
This control uses a named query:
with os_output as (  select    btrim(stdout_output, E' \n\r\t') as os,    _ctx ->> 'connection_name' as os_conn  from    exec_command  where    command = 'uname -s'), hostname as (  select    btrim(stdout_output, E' \n\r\t') as host,    _ctx ->> 'connection_name' as host_conn,    _ctx  from    exec_command  where    command = 'hostname'),
linux_output as (  select    stdout_output,    _ctx ->> 'connection_name' as conn  from    exec_command,    os_output  where    os_conn = _ctx ->> 'connection_name'    and os_output.os = 'Linux'    and command = 'stat -c %U:%G /var/run/docker.sock | grep -v root:docker'),darwin_output as (  select    stdout_output,    _ctx ->> 'connection_name' as conn  from    exec_command,    os_output  where    os_conn = _ctx ->> 'connection_name'    and os_output.os = 'Darwin'    and command = 'stat -f %Su:%Sg /var/run/docker.sock | grep -v root:docker'),command_output as (  select * from darwin_output  union all  select * from linux_output)select  host as resource,  case    when o.stdout_output = '' then 'ok'    else 'alarm'  end as status,  case    when o.stdout_output = '' then host || ' Docker socket file ownership is set to root:docker.'    else host || ' Docker socket file ownership is not set to root:docker.'  end as reason  , h._ctx ->> 'connection_name' as connection_namefrom  hostname as h,  os_output as os,  command_output as owhere  os.os_conn = h.host_conn  and h.host_conn = o.conn;