Hello, apsoul!!
I followed through with your recommendations and I could get the
container to run.
Thank you for taking the time to find a solution and helping me out.
In my case, I had to append only one policy. I am highlighting the steps
below for rootful container.
On 11/09/20 3:16 am, apsoul(a)hotmail.com wrote:
Hi Chintan,
I got the envoy container running, but used the example config on envoy's Getting
Started page:
https://www.envoyproxy.io/docs/envoy/latest/start/start
Steps I followed:
1) Created a starter container
2) Created an selinux policy using udica
3) Started the container and monitored /var/log/audit/audit.log for denials
4) Updated the udica generated *.cil file everytime the container failed to start, until
it finally started. This took 3 attempts, starting on the 4th.
Granted, not the most user friendly way of getting the container running, but I think
contained from a security standpoint.
1) Starter Container
```
podman create --name envoy \
--label envoy=envoy \
-p 10000:10000 \
-v ${PWD}/envoy_example.yaml:/etc/envoy/envoy.yaml \
envoyproxy/envoy:v1.15.0
```
2) Create Policy & remove starter container
```
podman inspect envoy > envoy_container.json
udica -j envoy_container.json envoy
semodule -i envoy.cil /usr/share/udica/templates/{base_container.cil,net_container.cil}
podman rm envoy
```
3) Create Final Container, attempt to start and monitor audit.log
```
podman create --name envoy \
--security-opt label=type:envoy.process \
--label envoy=envoy \
-p 10000:10000 \
-v ${PWD}/envoy_example.yaml:/etc/envoy/envoy.yaml:Z \
envoyproxy/envoy:v1.15.0
podman start envoy
```
I followed all the steps till here.
Each time the container failed to start it would log a denial. After each denial I
updated the *.cil policy file to allow the denial, and re-applied the policy with:
`semodule -i envoy.cil /usr/share/udica/templates/{base_container.cil,net_container.cil}`
After running the container I started looking for AVC denials. The
following denial didn't occur in my case. This could be due to rootful
environment.
- Startup 1
```
type=AVC msg=audit(1599771689.994:11166): avc: denied { read } for \
pid=1194200 comm="docker-entrypoi"
path="/lib/x86_64-linux-gnu/libc-2.27.so" \
dev="dm-9" ino=71349652 scontext=system_u:system_r:envoy.process:s0:c76,c889
tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
```
- Results in allow rule
```
(allow process default_t ( file ( read )))
```
The following denial was there in the audit logs.
```
type=AVC msg=audit(1600000744.700:5261): avc: denied { setattr } for
pid=15927 comm="chown" name="" dev="pipefs" ino=96155
scontext=system_u:system_r:envoy.process:s0:c107,c940
tcontext=unconfined_u:system_r:container_runtime_t:s0 tclass=fifo_file
permissive=0
type=AVC msg=audit(1600000744.700:5262): avc: denied { setattr } for
pid=15927 comm="chown" name="" dev="pipefs" ino=96156
scontext=system_u:system_r:envoy.process:s0:c107,c940
tcontext=unconfined_u:system_r:container_runtime_t:s0 tclass=fifo_file
permissive=0
```
In order to confirm that this is the only denial, container were started
multiple times. And the two audit logs above were the only denials.
These are similar to the logs below.
- Startup 2
```
type=AVC msg=audit(1599772073.397:11205): avc: denied { setattr } for \
pid=1218170 comm="chown" name="" dev="pipefs" \
ino=6650489 scontext=system_u:system_r:envoy.process:s0:c76,c889
tcontext=unconfined_u:system_r:container_runtime_t:s0 tclass=fifo_file permissive=0
```
- Results in allow rule
```
(allow process container_runtime_t ( fifo_file ( setattr )))
```
Adding the policy rule above allowed the container to run flawlessly.
- Startup 3
```
type=AVC msg=audit(1599772272.855:11237): avc: denied { name_bind } for \
pid=1232662 comm="envoy" src=9901 \
scontext=system_u:system_r:envoy.process:s0:c76,c889
tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket permissive=0
```
- Results in allow rule
```
(allow process unreserved_port_t ( tcp_socket ( name_bind )))
```
The final *.cil file looked like this:
```
The policy above was already present in the *.cil file generated in my
environment. This could be due to rootful environment.
(block envoy
(blockinherit container)
(blockinherit restricted_net_container)
(allow process process ( capability ( audit_write chown dac_override fowner fsetid
kill mknod net_bind_service net_raw setfcap setgid setpcap setuid sys_chroot )))
(allow process usr_t ( dir ( open read getattr lock search ioctl add_name
remove_name write )))
(allow process usr_t ( file ( getattr read write append ioctl lock map open create
)))
(allow process usr_t ( sock_file ( getattr read write append open )))
(allow process default_t ( file ( read )))
(allow process container_runtime_t ( fifo_file ( setattr )))
(allow process unreserved_port_t ( tcp_socket ( name_bind )))
)
```
Here is the final policy file in the rootful scenario.
```
(block envoy
(blockinherit container)
(blockinherit restricted_net_container)
(allow process process ( capability ( audit_write chown
dac_override fowner fsetid kill mknod net_bind_service net_raw setfcap
setgid setpcap setuid sys_chroot )))
(allow process container_runtime_t (fifo_file ( setattr )))
(allow process unreserved_port_t ( tcp_socket ( name_bind )))
)
```
Thank you.
PS: If you are reading this thread then here is a great resource for
editing *.cil files:
https://github.com/SELinuxProject/selinux-notebook/blob/main/src/cil_over...
--
Chintan Mishra
>
> Container started and a curl test was successful
> ```
> # podman ps -a --filter "label=envoy=envoy"
> CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
> 44f02a9f2ac3 docker.io/envoyproxy/envoy:v1.15.0 envoy -c /etc/env... About a
minute ago Up About a minute ago 0.0.0.0:10000->10000/tcp envoy
>
> # curl -I localhost:10000
> HTTP/1.1 200 OK
> content-type: text/html; charset=ISO-8859-1
> p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
> date: Thu, 10 Sep 2020 21:40:16 GMT
> server: envoy
> x-xss-protection: 0
> x-frame-options: SAMEORIGIN
> expires: Thu, 10 Sep 2020 21:40:16 GMT
> cache-control: private
> set-cookie: 1P_JAR=2020-09-10-21; expires=Sat, 10-Oct-2020 21:40:16 GMT; path=/;
domain=.google.com; Secure
> set-cookie:
NID=204=Py9ONzAvLYe41BNU_HWe88th45fOsxWWmjbh6aodR2wroK8r7gY8blxHV54zG7deSKNmtOT66FQQnyPn8vpk_vb6CwE6ZH-_D3KQgNByttyF2qdUifuYnfzMlirQKv1aWejLrQPdTpt7WDjULDZDTlNpa9BIsvfA4dSShDrfgx4;
expires=Fri, 12-Mar-2021 21:40:16 GMT; path=/;
domain=.google.com; HttpOnly
> alt-svc: h3-29=":443"; ma=2592000,h3-27=":443";
ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443";
ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443";
ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000;
v="46,43"
> x-envoy-upstream-service-time: 64
> transfer-encoding: chunked
> ```
>
> Hope this helps.
> _______________________________________________
> Podman mailing list -- podman(a)lists.podman.io
> To unsubscribe send an email to podman-leave(a)lists.podman.io