Network Security ของแอปพลิเคชัน (App Network Security) คืออะไร?
หมายถึงการตั้งค่าความปลอดภัยระดับเครือข่ายที่เกี่ยวข้องกับแอปพลิเคชันเฉพาะ เช่น Network Security Configuration (Android), App Transport Security (iOS), Network Policies (Kubernetes), Service Mesh mTLS, Firewall Rules, WAF Policies
1. Android: Network Security Configuration (XML)
ไฟล์: res/xml/network_security_config.xml อ้างอิงใน AndroidManifest.xml
<manifest>
<application
android:networkSecurityConfig="@xml/network_security_config"
... >
</application>
</manifest>
เนื้อหาไฟล์ (ตัวอย่าง):
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">api.myapp.com</domain>
<pin-set expiration="2025-01-01">
<pin digest="SHA-256">Base64EncodedHash...</pin>
</pin-set>
</domain-config>
<debug-overrides>
<trust-anchors>
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
คุณสมบัติหลัก: Certificate Pinning, Cleartext Traffic Control, Custom Trust Anchors, Debug Overrides
2. iOS: App Transport Security (ATS) - Info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><false/>
<key>NSExceptionDomains</key>
<dict>
<key>api.myapp.com</key>
<dict>
<key>NSIncludesSubdomains</key><true/>
<key>NSExceptionRequiresForwardSecrecy</key><true/>
<key>NSExceptionMinimumTLSVersion</key><string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key><true/>
</dict>
</dict>
</dict>
3. Kubernetes: Network Policies (K8s NetworkPolicy Resource)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: backend-allow-frontend
namespace: production
spec:
podSelector:
matchLabels:
app: backend
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
ports:
- protocol: TCP
port: 8080
ต้องมี CNI ที่รองรับ: Calico, Cilium, Weave, Antrea (ไม่ใช่ kubenet/flannel default)
4. Service Mesh: mTLS & Authorization Policies (Istio/Linkerd/Consul Connect)
- PeerAuthentication: REQUIRE_MTLS (STRICT/PERMISSIVE)
- AuthorizationPolicy: RBAC ระดับ Service/Workload (JWT, Headers, IP)
- Sidecar Injection: Auto-inject Envoy Proxy
5. Cloud: Security Groups / Firewall Rules / WAF
- AWS: Security Groups (SG), NACL, AWS WAF, Network Firewall, VPC Endpoints
- Azure: NSG, Azure Firewall, Application Gateway WAF, Private Endpoints
- GCP: Firewall Rules, Cloud Armor (WAF), VPC Service Controls, Private Service Connect
6. ตรวจสอบ Network Security ของแอปที่รันอยู่ (Runtime)
| Platform | Tools/Commands |
|---|---|
| Android | adb shell dumpsys network_security_config, Network Security Config Validator |
| iOS | nscurl --ats-diagnostics https://api.myapp.com, Xcode Network Link Conditioner |
| Kubernetes | kubectl get networkpolicies, calicoctl policy get, cilium policy get, kubectl auth can-i |
| Linux/Container | ss -tulpn, netstat -tulpn, iptables-save, nft list ruleset, bpftrace, tetragon |
| Cloud | AWS: VPC Reachability Analyzer, Azure: Network Watcher, GCP: Connectivity Tests |
Best Practices
- Default Deny: Block All, Allow Specific (Zero Trust)
- Certificate Pinning: ป้องกัน MITM (แต่ต้องจัดการ Rotation)
- mTLS Everywhere: Service Mesh หรือ Manual Cert Rotation
- Egress Control: ควบคุม Outbound Traffic (DNS, NTP, Updates, API Partners เท่านั้น)
- Testing: CI/CD Pipeline รวม Network Policy Test, TLS Test, Port Scan