Slide 1

Slide 1 text

© 2024 Fujitsu Limited 2024/10/23 Kenji Kazumura Troubleshooting Cloud-Native Java Applications in Container Environments While Maintaining Security OCX 2024 @kkzr

Slide 2

Slide 2 text

© 2024 Fujitsu Limited 2 Dilemma of Java Container Troubleshooting Java Container Wrap-up Agenda

Slide 3

Slide 3 text

Who Am I © 2024 Fujitsu Limited Work for Fujitsu • FUJITSU Software Enterprise Application Platform • Launcher Member of Jakarta EE SC Member of JCP Executive Committee Board of Director of Eclipse Foundation 3

Slide 4

Slide 4 text

© 2024 Fujitsu Limited 4 Dilemma of Java Container Troubleshooting Java Container Wrap-up Agenda

Slide 5

Slide 5 text

5 Motivation for Using Container Easy Packaging Everything needed are in a package Portability Can be deployed anywhere, production and testing Lightweight Faster start-up than VM Isolation Easily scaled ・・・ Troubleshooting and security are not motivation © 2024 Fujitsu Limited

Slide 6

Slide 6 text

6 Theme of this session Start-up time is desired on container Security is also vital In reality, troubleshooting are usually needed Look for the way to meet all three requirements © 2024 Fujitsu Limited

Slide 7

Slide 7 text

© 2024 Fujitsu Limited 7 Container Position (1) troubleshooting security (1) IDEAL start-up

Slide 8

Slide 8 text

8 Smaller Container Image Demand Faster start-up time reduce down-time reduce time of scaling out High Security fewer OS libraries, lower security risk still no motivation derived from troubleshooting © 2024 Fujitsu Limited

Slide 9

Slide 9 text

9 Container Start-up Time https://niravshah2705.medium.com/kubernetes-image-pull-optimisation-part-i-exploring-options-f79d79c3fe45 Almost image pull ‘pull’ consists of ‘fetch’ and ‘uncompress’ Bigger image size, longer uncompress time © 2024 Fujitsu Limited

Slide 10

Slide 10 text

10 Container Security Practice Smaller base image minimize user privileges monitor vulnerable information don’t include tokens / keys in ・・・ https://res.cloudinary.com/snyk/image/upload/v1551798390/Docker_Image_Security_Best_Practices_.pdf © 2024 Fujitsu Limited image

Slide 11

Slide 11 text

When vulnerability detected at a library in the base image, need to re-build image even if this library are not used. 11 Vulnerabilities of Libraries in Image Even using latest image when build and deploy, vulnerabilities increase Re-build with latest image Container Image Need action, even if not used © 2024 Fujitsu Limited base image application

Slide 12

Slide 12 text

12 Example vulnerabilities at Docker Hub © 2024 Fujitsu Limited

Slide 13

Slide 13 text

13 Ways to make Java image smaller © 2024 Fujitsu Limited distroless Minimize base image there are some Java image jlink Package only necessary modules for applications JRE No tools in JDK (jshell, jar …)

Slide 14

Slide 14 text

Available at gcr.io/distroless Java distroless: `gcr.io/distroless/java21-debian12` Microsoft also provides `mcr.microsoft.com/openjdk/jdk:21-distroless` No tools for troubleshooting No `ls`, No `ps` 14 Distroless Image © 2024 Fujitsu Limited No way to investigate OS provied features

Slide 15

Slide 15 text

No way to investigate Java troubles 15 JRE © 2024 Fujitsu Limited JRE does not include most of tools in JDK jcmd / jstack / jar / javac / jdb / javadoc / ・・・ tools not included in JRE tools included in JRE java / keytool / rmiregistry / jfr / ・・・

Slide 16

Slide 16 text

16 Dilemma of Java Container © 2024 Fujitsu Limited Methodology to realize Start-up Security trouble shooting not compatible with each other cannot use JDK tools , OS tools smaller image

Slide 17

Slide 17 text

© 2024 Fujitsu Limited 17 Container Position (2) troubleshooting security (1) IDEAL start-up (2)

Slide 18

Slide 18 text

© 2024 Fujitsu Limited 18 Dilemma of Java Container Troubleshooting Java Container Wrap-up Agenda

Slide 19

Slide 19 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 19

Slide 20

Slide 20 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 20

Slide 21

Slide 21 text

‘docker exec’ / ‘kubectl exec’ Can access container internal system and process as if you are in the container No guarantee to be available necessary troubleshooting tools in container Feels like login system using ssh, but actually just changing namespace 21 ‘exec’ sub-command © 2024 Fujitsu Limited

Slide 22

Slide 22 text

Managed by i-node Separate resources by using 8 namespaces ✓ cgroup/net/ipc/uts/user/pid/time/mnt ✓ By setting share or not to each namespace, container can be isolated flexibly. Namespace related commands lsns nsenter ・・・ `docker exec` is just changing namespace same as `nsenter --target ${PID} --all` 22 Linux namespace © 2024 Fujitsu Limited

Slide 23

Slide 23 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 23

Slide 24

Slide 24 text

24 Access from Node © 2024 Fujitsu Limited Process in container can be seen as process of node. But PID are different. Difficult to know which process belongs to which container. Difficult to troubleshooting from viewpoint of container Usually accessing node is limited Node container JDK jstack Java Application

Slide 25

Slide 25 text

25 Create Debug Container on Node © 2024 Fujitsu Limited container running with host namespace on K8S node kubectl debug node/{node-name} -it \ --image={image} -- bash Pod Debuggee Container Debugger Container Pod Node jstack run with node namespace Java Application

Slide 26

Slide 26 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 26

Slide 27

Slide 27 text

Sharing Pod namespace © 2024 Fujitsu Limited K8S Pod 27 pid share share cannot access process of another container pid uts net share share Container Main Container Sidecar mnt mnt

Slide 28

Slide 28 text

Share namespace using side car © 2024 Fujitsu Limited Pod 28 mnt share share can access process of another container mnt uts net share share Container Application(JRE) Container Debugger(JDK) pid shareprocess

Slide 29

Slide 29 text

29 Sidecar © 2024 Fujitsu Limited Run trouble shooting image in Pod as a sidecar specify following in pod definition ‘spec.shareProcessNamespace:true’ No need to install tools in application image, but need to run always even if no trouble useful for development environment which you know trouble will surely happen

Slide 30

Slide 30 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 30

Slide 31

Slide 31 text

Sharing namespace using COPY © 2024 Fujitsu Limited Pod 31 can access process Pod net COPY Pod net uts Container Debugger(JDK) Container net uts App(JRE) Container App(JRE) Container pid App(JRE) mnt pid mnt mnt pid uts mnt shareprocess

Slide 32

Slide 32 text

32 COPY © 2024 Fujitsu Limited Copy application and add debugger container to pod when trouble Resource efficiency compare to Sidecar No live migration kubectl debug -it debuggee-pod \ --copy-to debugger-pod \ –share-processes debuggee-pod \ --image JDK-image -- bash

Slide 33

Slide 33 text

‘exec’ sub-command Access from Node Sidecar COPY Ephemeral Container How to Troubleshoot Containers © 2024 Fujitsu Limited 33

Slide 34

Slide 34 text

Sharing by ephemeral container © 2024 Fujitsu Limited Pod 34 Can access process Pod net uts mnt Container net uts mnt App(JRE) Ephemeral Container Debugger(JDK) Container mnt App(JRE) pid add pid Debugger(JDK)

Slide 35

Slide 35 text

35 Ephemeral Container © 2024 Fujitsu Limited add a container which namespace is same as debuggee container to the existing Pod using Docker using Kubernetes docker run \ -it --name=debugger --pid=container:jre \ jdk-image bash kubectl debug -it -c debugger --target debuggee \ --image=jdk-image debuggee -- bash

Slide 36

Slide 36 text

© 2024 Fujitsu Limited 36 Agenda Dilemma of Java Container Troubleshooting Java Container Wrap-up

Slide 37

Slide 37 text

37 Comparison © 2024 Fujitsu Limited Pros Cons ‘exec’ sub-command Easy Tools may not be available Access from Node N/A Need host privilege Different namespace Side Car Separate debugger container from application container Waist resource COPY Copy only when troubles Cannot debug actual container trouble happens Ephemeral Container Can access actual troubled container only when trouble happens Cannot delete ephemeral container

Slide 38

Slide 38 text

© 2024 Fujitsu Limited 38 Container Position (3) troubleshooting security start-up (1) (2) IDEAL (3)

Slide 39

Slide 39 text

Wrap-up © 2024 Fujitsu Limited 39 Tools which are used at on-premises may not be used (dilemma of Java container) There are several ways such as ephemeral container to detour dilemma Isolating troubleshooting container keeps application container secure start-up security trouble shooting

Slide 40

Slide 40 text

© 2024 Fujitsu Limited Question? 40

Slide 41

Slide 41 text

Thank you © 2024 Fujitsu Limited