Tutorial Hardening Runtime Linux: Deteksi & Blokir Threat Pakai eBPF Tetragon
Poin Kunci Artikel Ini:
- OS: Ubuntu 22.04 LTS / Debian 12 / RHEL 9
- Kernel Linux: Version 5.4+ (Kernel 5.15+ direkomendasikan)
- Ancaman Runtime Linux & Keterbatasan Security TradisionalKeamanan server Linux fokus pada perimeter: firewall, SSH key, scanning biner statis.
1. Ancaman Runtime Linux & Keterbatasan Security Tradisional
Keamanan server Linux fokus pada perimeter: firewall, SSH key, scanning biner statis. Pendekatan ini gagal saat attacker menembus layer awal via zero-day exploit atau credential leak. Akses awal didapat, attacker jalankan aktivitas runtime: drop biner malicious ke direktori temporer (/tmp, /dev/shm), eskalasi privilege ke root, buat persistence mechanism.
1.1 Mengapa Tool Tradisional Gagal?
Security tool tradisional seperti auditd atau solusi berbasis ptrace memiliki kelemahan mendasar:
- Performance Overhead Tinggi:
ptracehentikan eksekusi proses tiap system call. Latensi melonjak, throughput server drop. - Bypass Context Switch & Race Condition: Attacker kelabui audit log via teknik TOCTOU (Time-of-Check to Time-of-Use) atau ubah inode sebelum log tertera.
- User-space Delay: Detection engine berjalan di user-space. Alert terpicu, payload malicious sudah selesai eksekusi. Reaksi pasif, tidak ada pencegahan sinkron.
1.2 Solusi eBPF dan Cilium Tetragon
Extended Berkeley Packet Filter (eBPF) eksekusi byte-code langsung di kernel Linux tanpa modifikasi kernel source atau load kernel module (kmod). eBPF berikan visibilitas penuh pada kprobe, tracepoint, LSM (Linux Security Modules), dan system call dengan overhead mendekati nol.
Cilium Tetragon adalah runtime security & enforcement tool berbasis eBPF. Tetragon tidak cuma mencatat log observabilitas, tapi melakukan in-kernel enforcement. Proses mencurigakan terdeteksi, Tetragon hentikan (kill) proses di layer kernel sebelum system call return ke user-space.
2. Instalasi dan Setup Tetragon di VPS Linux
2.1 Prasyarat Sistem
Pastikan VPS Linux memenuhi syarat minimal berikut:
- OS: Ubuntu 22.04 LTS / Debian 12 / RHEL 9
- Kernel Linux: Version 5.4+ (Kernel 5.15+ direkomendasikan)
- Kernel Config:
CONFIG_BPF=y,CONFIG_BPF_SYSCALL=y,CONFIG_BPF_EVENTS=y, BTF (BPF Type Format) aktif (/sys/kernel/btf/vmlinuxada) - Akses Root / Sudo
Verifikasi dukungan BTF di VPS:
ls -l /sys/kernel/btf/vmlinux2.2 Langkah Instalasi Tetragon Binary & Systemd
Instalasi Tetragon sebagai systemd service pada host Linux standalone dilakukan melalui langkah-langkah berikut:
# 1. Download release biner Tetragon terbaru
wget https://github.com/cilium/tetragon/releases/download/v1.1.0/tetragon-v1.1.0-amd64.tar.gz
# 2. Ekstrak arsip ke sistem
tar -xvf tetragon-v1.1.0-amd64.tar.gz -C /usr/local/bin/
# 3. Buat direktori konfigurasi dan log
mkdir -p /etc/tetragon/tracingpolicy /var/log/tetragon /etc/tetragon/tetragon.conf.d/
# 4. Buat systemd service unit
cat <<EOF > /etc/systemd/system/tetragon.service
[Unit]
Description=Tetragon eBPF Security Agent
Documentation=https://github.com/cilium/tetragon
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/tetragon --config-dir=/etc/tetragon/tetragon.conf.d/ --export-filename=/var/log/tetragon/tetragon.log
Restart=always
RestartSec=5
LimitMEMLOCK=infinity
[Install]
WantedBy=multi-user.target
EOF
# 5. Buat konfigurasi dasar Tetragon
cat <<EOF > /etc/tetragon/tetragon.conf.d/tetragon.conf
bpf-lib=/usr/local/lib/tetragon/bpf/
tracing-policy-dir=/etc/tetragon/tracingpolicy/
export-filename=/var/log/tetragon/tetragon.log
export-file-max-size-mb=100
export-file-max-backups=5
EOF
# 6. Aktifkan dan jalankan service Tetragon
systemctl daemon-reload
systemctl enable --now tetragon
systemctl status tetragon3. Konfigurasi TracingPolicy eBPF
Tetragon pakai file deklaratif YAML TracingPolicy. File tentukan kernel hook, kondisi pencocokan (selectors), dan aksi (actions).
3.1 Policy 1: Blokir Eksekusi Biner dari Direktori Temporer (/tmp, /dev/shm, /var/tmp)
Attacker unggah exploit script atau reverse shell biner ke /tmp atau /dev/shm karena izin tulis global (world-writable). Policy deteksi panggil system call sys_execve, kirim sinyal SIGKILL instan ke proses yang mencoba eksekusi file dari lokasi tersebut.
Buat file /etc/tetragon/tracingpolicy/block-tmp-exec.yaml:
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: block-tmp-execution
spec:
kprobes:
- call: "sys_execve"
syscall: true
args:
- index: 0
type: "string"
selectors:
- matchArgs:
- index: 0
operator: "Prefix"
values:
- "/tmp/"
- "/dev/shm/"
- "/var/tmp/"
matchActions:
- action: Sigkill3.2 Policy 2: Deteksi & Cegah Privilege Escalation (Unauthorized setuid)
Eskalasi hak akses manfaatkan SUID binary jahat atau kernel exploit panggil system call sys_setuid argumen 0 (root ID) dari proses non-root. Policy deteksi percobaan ubah UID jadi 0, langsung hentikan proses pelaku.
Buat file /etc/tetragon/tracingpolicy/prevent-privesc.yaml:
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: prevent-privilege-escalation
spec:
kprobes:
- call: "sys_setuid"
syscall: true
args:
- index: 0
type: "int"
selectors:
- matchArgs:
- index: 0
operator: "Equal"
values:
- "0"
matchActions:
- action: Sigkill3.3 Policy 3: Proteksi Pembacaan File Credentials Sensitif (/etc/shadow)
Attacker baca file /etc/shadow dump hash password. Policy pantau system call sys_openat pada target file sensitif, blokir akses proses tidak sah.
Buat file /etc/tetragon/tracingpolicy/protect-sensitive-files.yaml:
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: protect-sensitive-files
spec:
kprobes:
- call: "sys_openat"
syscall: true
args:
- index: 1
type: "string"
selectors:
- matchArgs:
- index: 1
operator: "Equal"
values:
- "/etc/shadow"
- "/etc/sudoers"
matchActions:
- action: Sigkill4. Simulasi Serangan & In-Kernel Enforcement Real-Time
Pengujian langsung pastikan Tetragon memblokir eksekusi biner mencurigakan di VPS.
4.1 Penerapan Policy ke Tetragon
Tetragon berjalan sebagai standalone daemon, muat policy pakai CLI tetra atau letakkan file YAML di direktori policy:
tetra tracingpolicy add /etc/tetragon/tracingpolicy/block-tmp-exec.yaml
tetra tracingpolicy add /etc/tetragon/tracingpolicy/prevent-privesc.yaml
tetra tracingpolicy add /etc/tetragon/tracingpolicy/protect-sensitive-files.yaml
tetra tracingpolicy list4.2 Simulasi 1: Eksekusi Biner di Direktori /tmp
Salin biner sistem /bin/ls ke /tmp, lalu eksekusi:
cp /bin/ls /tmp/malicious_ls
chmod +x /tmp/malicious_ls
/tmp/malicious_lsHasil Eksekusi:
KilledProses dihentikan seketika oleh kernel sebelum instruksi pertama biner berjalan di RAM. Kernel kembalikan respon Killed (SIGKILL).
4.3 Analisis Event Log Real-Time
Pantau event log Tetragon pakai CLI tetra:
tetra getevents -o compactOutput tunjukkan intercept kernel:
๐ process /tmp/malicious_ls binary /tmp/malicious_ls args [] /tmp/malicious_ls
๐ฅ process /tmp/malicious_ls binary /tmp/malicious_ls SIGKILL (Killed by Tetragon eBPF enforcement)Struktur log JSON di /var/log/tetragon/tetragon.log:
{
"process_kprobe": {
"process": {
"exec_id": "aW5zdGFuY2UtMToxMjM0NTo2Nzg5",
"pid": 4321,
"uid": 1000,
"cwd": "/home/user",
"binary": "/tmp/malicious_ls",
"arguments": ""
},
"parent": {
"pid": 2100,
"binary": "/bin/bash"
},
"function_name": "sys_execve",
"action": "KPROBE_ACTION_SIGKILL"
},
"time": "2026-03-30T10:15:30.123456789Z"
}4.4 Simulasi 2: Akses Terlarang ke /etc/shadow
Jalankan perintah pembacaan file sensitif oleh user non-root:
cat /etc/shadowProses cat langsung di-kill jika policy pembacaan file aktif dan mencocokkan kriteria pelanggaran akses, mencegah kebocoran hash credential ke attacker.
5. Integrasi Log SIEM & Production Best Practices
5.1 Integrasi Log JSON ke Vector / FluentBit
Tetragon tulis event terstruktur ke file /var/log/tetragon/tetragon.log format JSON Lines. Log shipper seperti Vector atau FluentBit dengan mudah ingest log ini ke SIEM (Elasticsearch, OpenSearch, Grafana Loki).
Contoh konfigurasi Vector ingest log Tetragon:
[sources.tetragon_logs]
type = "file"
include = ["/var/log/tetragon/tetragon.log"]
[transforms.parse_json]
type = "remap"
inputs = ["tetragon_logs"]
source = '''
. = parse_json!(.message)
'''
[sinks.elasticsearch]
type = "elasticsearch"
inputs = ["parse_json"]
endpoint = "http://10.0.0.50:9200"
index = "tetragon-events-%Y.%m.%d"5.2 Best Practices Hardening Production
Penerapan Tetragon di lingkungan produksi memerlukan langkah pengujian untuk mencegah gangguan service resmi:
- Uji Coba Mode Log (Post) Sebelum Enforcement (Sigkill): Jalankan policy baru dengan
action: Postterlebih dahulu. Amati log selama 48 jam untuk mendeteksi False Positive sebelum mengabaikan atau mengganti keaction: Sigkill. - Bypass Whitelist untuk Legitimate Tools: Tambahkan filter
matchProcessataumatchNamespacespada YAML policy untuk mengecualikan biner manajemen sistem legitimate seperti deployment agent atau backup runner. - Proteksi File Konfigurasi Tetragon: Batasi hak akses direktori
/etc/tetragon/hanya untuk akunroot(chmod 700) agar attacker tidak dapat mengubah atau menghapus TracingPolicy. - Rotasi Log Otomatis: Konfigurasikan parameter
export-file-max-size-mbdanexport-file-max-backupspadatetragon.confuntuk menghemat disk I/O dan ruang penyimpanan server.
6. Ringkasan Teknologis
Hardening runtime berbasis eBPF pakai Tetragon ubah paradigma proteksi Linux. Keamanan tidak lagi bergantung pada pencatatan log pasif user-space (auditd) atau pendeteksian bertingkat dengan overhead tinggi (ptrace). Tetragon cegah eksekusi malicious script, eskalasi privilege, dan pembacaan file sensitif langsung di layer kernel real-time sebelum dampak buruk terjadi pada sistem produksi.


