-1

From a Spark job which is written in Java, I am trying to get the list of all the linux/centos users who have access to a particular hdfs file.

Currently tring out below Java code to get the info:

result = Shell.execCommand("sudo","bash","-c","lid","-g","-n", fileOwnersGroup);

but it is not working out. It is throwing:

sudo: no tty present and no askpass program specified

Tried various option including updating /etc/sudoer but no luck.

pheeleeppoo
  • 1,491
  • 6
  • 25
  • 29
Sunny Gupta
  • 191
  • 1
  • 4
  • 14
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Oct 29 '17 at 14:55
  • Adding "in a shell script" or "in my program" is usually not enough to make the question a programming and development question. Please show your Java code and explain where the problem lies. – jww Oct 29 '17 at 15:51
  • HDFS is not a POSIX filesystem. Your HDFS "user accounts" aren't (typically) mapped to Linux users. **Especially** if you aren't using Kerberos – OneCricketeer Oct 29 '17 at 18:47
  • Yeah, but if i have them mapped, how we can achieve it. – Sunny Gupta Oct 30 '17 at 09:27

1 Answers1

0

A FileStatus object has getOwner() and getGroup() methods.

You can get a status with a FileSystem object and a Path to a file.

For example, Spark Scala list folders in directory

However, you will need some external query to find what Unix accounts map into a group. For example, such an operation would typically be controlled by an LDAP search.

it is throwing sudo: no tty present and no askpass program specified

Clearly the problem is that sudo is prompting for a password and Spark processes shouldn't be able to execute elevated commands on the local filesystem

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Using the same to get the owner and group, but once I have the group, I wanted to get the list of all the user belongs to that group. from java i am using below command result = Shell.execCommand("sudo","bash","-c","lid","-g","-n", fileOwnersGroup); But it is not working out. – Sunny Gupta Oct 30 '17 at 09:24
  • You don't need `sudo bash -c` to read account information. Plus, you're spark applications should really not be able to run with elevated privileges anyway. Spark is a distributed execution framework, and you cannot control what server an executor runs on. User/group mapping is out of scope of the Hadoop project. As mentioned, group management is commonly controlled by LDAP. And to sync LDAP to unix accounts, one uses sssd – OneCricketeer Oct 30 '17 at 13:18
  • In any case `getent group ${group}` is the command you'd want, I believe – OneCricketeer Oct 30 '17 at 13:27