chaosblade-io / chaosblade

An easy to use and powerful chaos engineering experiment toolkit.(阿里巴巴开源的一款简单易用、功能强大的混沌实验注入工具)
https://chaosblade.io
Apache License 2.0
5.86k stars 934 forks source link

get username failed by the process id, err: user: unknown userid #1038

Open ygxxii opened 2 months ago

ygxxii commented 2 months ago

Issue Description

Type: bug report

Describe what happened (or what feature you want)

JVM experiments drill failed. Run following commands got error in container (Kubernetes Pod):

./blade prepare jvm --pid 1
{"code":63014,"success":false,"error":"`1`: get username failed by the process id, err: user: unknown userid 1000","result":"cdff374fa5e330be"}
./blade create jvm OutOfMemoryError --pid 1 --area HEAP
{"code":63014,"success":false,"error":"`1`: get username failed by the process id, err: user: unknown userid 1000","result":"3f8f49aeac1f5347"}

Describe what you expected to happen

JVM experiments drill succeed.

How to reproduce it (as minimally and precisely as possible)

  1. Dockerfile (do not create user that userid=1000):
FROM eclipse-temurin:8-jdk-centos7
RUN mkdir /opt/app
COPY math-game.jar /opt/app
CMD ["java", "-jar", "/opt/app/math-game.jar"]

math-game.jar is from Arthas.

  1. Deployment.yaml (NOTE runAsUser):
apiVersion: apps/v1
kind: Deployment
metadata:
  name: math-game
spec:
  selector:
    matchLabels:
      app: math-game
  template:
    metadata:
      labels:
        app: math-game
    spec:
      containers:
        - name: math-game
          image: <image-url>
          command: ["java"]
          args: ["-jar","/opt/app/math-game.jar"]
          resources:
            limits:
              cpu: "1"
              memory: 100Mi
            requests:
              cpu: 200m
              memory: 20Mi
      securityContext:
        fsGroup: 1000
        runAsGroup: 1000
        runAsUser: 1000
  1. kubectl exec login to container ;

  2. Change current dir to somewhere can write. e.g. /var/tmp:

cd /var/tmp
  1. Download and unpack ChaosBlade CLI:
wget https://github.com/chaosblade-io/chaosblade/releases/download/v1.7.3/chaosblade-1.7.3-linux-amd64.tar.gz -O chaos.tar.gz && tar -zxvf chaos.tar.gz
  1. Run ChaosBlade CLI:
./blade prepare jvm --pid 1

Tell us your environment

Kubernetes: 1.28.9-aliyun.1 Worker Node: Alibaba Cloud Linux 3.2104 LTS 64-bit

Anything else we need to know?

ChaosBlade use os/user to get current user's username. So I tested following code in this container:

package main

import (
   "fmt"
   "log"
   "os/user"
)

func main() {
   currentUser, err := user.Current()
   if err != nil {
      log.Fatalf(err.Error())
   }

   name := currentUser.Name
   id := currentUser.Uid
   username := currentUser.Username

   fmt.Printf("Username is: %s\n", username)
   fmt.Printf("name is: %s\n", name)
   fmt.Printf("id is: %s\n", id)
}

Got a same error:

user: unknown userid 1000