java 为什么UnixSystem().getUsername()返回空值(Docker中的OpenJDK 17)

nhhxz33t  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(199)

以下代码适用于OSX

var hadoopInputFile  = org.apache.parquet.hadoop.util.HadoopInputFile.fromPath(parquetPath, new Configuration())

但在Linux上却不是这样

failure to login: javax.security.auth.login.LoginException: java.lang.NullPointerException: invalid null input: name
    at jdk.security.auth/com.sun.security.auth.UnixPrincipal.<init>(UnixPrincipal.java:67)
    at jdk.security.auth/com.sun.security.auth.module.UnixLoginModule.login(UnixLoginModule.java:134)
    at java.base/javax.security.auth.login.LoginContext.invoke(LoginContext.java:726)
    at java.base/javax.security.auth.login.LoginContext$4.run(LoginContext.java:665)
    at java.base/javax.security.auth.login.LoginContext$4.run(LoginContext.java:663)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    at java.base/javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:663)
    at java.base/javax.security.auth.login.LoginContext.login(LoginContext.java:574)
    at org.apache.hadoop.security.UserGroupInformation$HadoopLoginContext.login(UserGroupInformation.java:2065)
    at org.apache.hadoop.security.UserGroupInformation.doSubjectLogin(UserGroupInformation.java:1975)
    at org.apache.hadoop.security.UserGroupInformation.createLoginUser(UserGroupInformation.java:719)
    at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:669)
    at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:579)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:3746)
    at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:3736)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3520)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:540)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:288)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:524)
    at org.apache.hadoop.fs.Path.getFileSystem(Path.java:365)
    at org.apache.parquet.hadoop.util.HadoopInputFile.fromPath(HadoopInputFile.java:38)
...

我发现new com.sun.security.auth.module.UnixSystem().getUsername()返回null,但它不应该返回
有什么想法可以修复或解决吗?
不间断电源
因为这是在码头集装箱内发生的
停靠文件:

FROM maven:3.8.5-openjdk-17 AS tests
ENV WORKDIR="/application"
WORKDIR ${WORKDIR}
COPY . $WORKDIR/

运行命令:

docker run
        --user 0:1001
        --volume $(command -v docker):/usr/bin/docker
        --volume /var/run/docker.sock:/var/run/docker.sock
        --volume $(pwd):/path/to/project/application
        app_tag bash -c
        "umask 002;
        mvn --settings ./.m2-settings.xml package"

UPD 2
我发现id可以得到uid=1001 gid=1001 groups=1001
以及whoami-whoami: cannot find name for user ID 1001
目前的解决方法是添加到Dockerfile

RUN groupadd -g 1001 sysadmin
RUN useradd appadmin -u 1001 -g 1001 -m -s /bin/bash
v2g6jxz6

v2g6jxz61#

添加到Dockerfile可解决此问题

RUN groupadd -g 1001 sysadmin
RUN useradd appadmin -u 1001 -g 1001 -m -s /bin/bash

相关问题