-
Notifications
You must be signed in to change notification settings - Fork 38
Description
What happened:
I have cli script in one namespace and I applied this network policy:
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: default-deny-all
spec:
podSelector: {}
ingress: []
Script is PHP application that use aws-php-sdk. It uses service account to assume role to access s3 bucket. We also have interface endpoint for STS. After I applied that policy I see that my container is stuck and cannot assume role.
strace:
# strace -p 1
strace: Process 1 attached
restart_syscall(<... resuming interrupted read ...>) = 0
rt_sigaction(SIGPIPE, NULL, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, NULL, 8) = 0
poll([{fd=7, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, NULL, 8) = 0
poll([{fd=7, events=POLLIN}], 1, 1000) = 0 (Timeout)
rt_sigaction(SIGPIPE, NULL, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, 8) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, NULL, 8) = 0
poll([{fd=7, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f30ea728c83}, NULL, 8) = 0
poll([{fd=7, events=POLLIN}], 1, 1000^Cstrace: Process 1 detached
<detached ...>
lsof:
/ # lsof -p 1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php 1 nobody cwd DIR 0,636 4096 393047 /usr/local/parser
php 1 nobody rtd DIR 0,636 4096 1087892 /
php 1 nobody txt REG 0,636 18892400 394323 /usr/local/bin/php
php 1 nobody mem REG 259,16 394323 /usr/local/bin/php (stat: Operation not permitted)
php 1 nobody mem REG 259,16 395012 /usr/lib/libzstd.so.1.5.2 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 395008 /usr/lib/libbz2.so.1.0.8 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 395010 /usr/lib/libzip.so.5.4 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 395025 /usr/local/lib/php/extensions/no-debug-non-zts-20210902/zip.so (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394310 /usr/lib/libsodium.so.23.3.0 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394858 /usr/local/lib/php/extensions/no-debug-non-zts-20210902/sodium.so (stat: Operation not permitted)
php 1 nobody mem REG 259,16 395024 /usr/local/lib/php/extensions/no-debug-non-zts-20210902/pdo_mysql.so (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393910 /usr/lib/libbrotlicommon.so.1.0.9 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393912 /usr/lib/libbrotlidec.so.1.0.9 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393920 /usr/lib/libnghttp2.so.14.21.2 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393918 /usr/lib/liblzma.so.5.2.5 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394302 /usr/lib/libncursesw.so.6.3 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394291 /usr/lib/libargon2.so.1 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394304 /usr/lib/libonig.so.5.3.0 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393916 /usr/lib/libcurl.so.4.8.0 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393235 /lib/libz.so.1.2.12 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394312 /usr/lib/libsqlite3.so.0.8.6 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393232 /lib/libcrypto.so.1.1 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393233 /lib/libssl.so.1.1 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394314 /usr/lib/libxml2.so.2.9.14 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394298 /usr/lib/libiconv.so.2.6.1 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 394308 /usr/lib/libreadline.so.8.1 (stat: Operation not permitted)
php 1 nobody mem REG 259,16 393229 /lib/ld-musl-x86_64.so.1 (stat: Operation not permitted)
php 1 nobody 0u CHR 1,3 0t0 6 /dev/null
php 1 nobody 1w FIFO 0,13 0t0 10593738 pipe
php 1 nobody 2w FIFO 0,13 0t0 10593739 pipe
php 1 nobody 3r REG 0,636 3299 395550 /usr/local/parser/sftp.php
php 1 nobody 4u sock 0,8 0t0 10593987 protocol: TCP
php 1 nobody 5u unix 0x0000000000000000 0t0 10594514 type=STREAM (CONNECTED)
php 1 nobody 6u unix 0x0000000000000000 0t0 10594515 type=STREAM (CONNECTED)
php 1 nobody 7u IPv4 10594520 0t0 TCP parser-cronjob-sftp-download-files-28256520-25p9z:59598->ip-10-1-12-220.ec2.internal:https (ESTABLISHED)
As you can see connection is in ESTABLISHED state.
Here is the logs from the instance:
root@admin]# grep "10.1.201.3" network-policy-agent.log | grep "10.1.12.220"
{"level":"info","timestamp":"2023-09-22T13:30:04.299Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.201.3","Src Port":34454,"Dest IP":"10.1.12.220","Dest Port":443,"Proto":"TCP","Verdict":"ACCEPT"}
{"level":"info","timestamp":"2023-09-22T13:35:10.799Z","logger":"ebpf-client","msg":"Conntrack cleanup","Entry - ":"Expired/Delete Conntrack Key : Source IP - 10.1.201.3 Source port - 34454 Dest IP - 10.1.12.220 Dest port - 443 Protocol - 6"}
{"level":"info","timestamp":"2023-09-22T14:00:03.812Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:03.812Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:03.853Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:04.075Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:04.503Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:05.393Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:07.163Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:10.593Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:17.723Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:31.793Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:00:59.323Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
{"level":"info","timestamp":"2023-09-22T14:01:05.811Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.12.220","Src Port":443,"Dest IP":"10.1.201.3","Dest Port":59598,"Proto":"TCP","Verdict":"DENY"}
But from inside the container new command that tests connection to s3 works well:
{"level":"info","timestamp":"2023-09-23T12:00:44.469Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.201.3","Src Port":52301,"Dest IP":"172.20.0.10","Dest Port":53,"Proto":"UDP","Verdict":"ACCEPT"}
{"level":"info","timestamp":"2023-09-23T12:00:44.470Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.201.3","Src Port":53862,"Dest IP":"10.1.12.220","Dest Port":443,"Proto":"TCP","Verdict":"ACCEPT"}
{"level":"info","timestamp":"2023-09-23T12:00:44.696Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.201.3","Src Port":51649,"Dest IP":"172.20.0.10","Dest Port":53,"Proto":"UDP","Verdict":"ACCEPT"}
{"level":"info","timestamp":"2023-09-23T12:00:44.698Z","logger":"ebpf-client","msg":"Flow Info: ","Src IP":"10.1.201.3","Src Port":52654,"Dest IP":"52.216.214.57","Dest Port":443,"Proto":"TCP","Verdict":"ACCEPT"}
Basically 4 requests: DNS -> STS -> DNS -> S3
This is container IP: 10.1.201.3
And this is STS interface IP: 10.1.12.220
And if I remove that network policy everything works well again. Any ideas?
Environment:
Kubernetes version (use kubectl version): Server Version: v1.27.4-eks-2d98532
CNI Version: v1.15.0-eksbuild.2
OS (e.g: cat /etc/os-release): bottlerocket $ cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/"
Kernel (e.g. uname -a): Linux ip-10-1-193-17.ec2.internal 5.15.128 aws/amazon-vpc-cni-k8s#1 SMP Thu Sep 14 21:42:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux