Package org.apache.hadoop.io
Class SecureIOUtils
java.lang.Object
org.apache.hadoop.io.SecureIOUtils
This class provides secure APIs for opening and creating files on the local
disk. The main issue this class tries to handle is that of symlink traversal.
An example of such an attack is:
An example of such an attack is:
- Malicious user removes his task's syslog file, and puts a link to the jobToken file of a target user.
- Malicious user tries to open the syslog file via the servlet on the tasktracker.
- The tasktracker is unaware of the symlink, and simply streams the contents of the jobToken file. The malicious user can now access potentially sensitive map outputs, etc. of the target user's job.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSignals that an attempt to create a file at a given pathname has failed because another file already existed at that path. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FileOutputStreamcreateForWrite(File f, int permissions) Open the specified File for write access, ensuring that it does not exist.protected static RandomAccessFileforceSecureOpenForRandomRead(File f, String mode, String expectedOwner, String expectedGroup) protected static FileInputStreamforceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) protected static FSDataInputStreamforceSecureOpenFSDataInputStream(File file, String expectedOwner, String expectedGroup) Same as openFSDataInputStream except that it will run even if security is off.static RandomAccessFileopenForRandomRead(File f, String mode, String expectedOwner, String expectedGroup) static FileInputStreamopenForRead(File f, String expectedOwner, String expectedGroup) Open the given File for read access, verifying the expected user/group constraints if security is enabled.static FSDataInputStreamopenFSDataInputStream(File file, String expectedOwner, String expectedGroup) Opens theFSDataInputStreamon the requested file on local file system, verifying the expected user/group constraints if security is enabled.
-
Constructor Details
-
SecureIOUtils
public SecureIOUtils()
-
-
Method Details
-
openForRandomRead
public static RandomAccessFile openForRandomRead(File f, String mode, String expectedOwner, String expectedGroup) throws IOException - Parameters:
f- file that we are trying to openmode- mode in which we want to open the random access fileexpectedOwner- the expected user owner for the fileexpectedGroup- the expected group owner for the file- Returns:
- Open the given File for random read access, verifying the expected user/ group constraints if security is enabled. Note that this function provides no additional security checks if hadoop security is disabled, since doing the checks would be too expensive when native libraries are not available.
- Throws:
IOException- if an IO error occurred or if the user/group does not match when security is enabled.
-
forceSecureOpenForRandomRead
@VisibleForTesting protected static RandomAccessFile forceSecureOpenForRandomRead(File f, String mode, String expectedOwner, String expectedGroup) throws IOException - Parameters:
f- input f.mode- input mode.expectedOwner- input expectedOwner.expectedGroup- input expectedGroup.- Returns:
- Same as openForRandomRead except that it will run even if security is off. This is used by unit tests.
- Throws:
IOException- raised on errors performing I/O.
-
openFSDataInputStream
public static FSDataInputStream openFSDataInputStream(File file, String expectedOwner, String expectedGroup) throws IOException Opens theFSDataInputStreamon the requested file on local file system, verifying the expected user/group constraints if security is enabled.- Parameters:
file- absolute path of the fileexpectedOwner- the expected user owner for the fileexpectedGroup- the expected group owner for the file- Returns:
- FSDataInputStream.
- Throws:
IOException- if an IO Error occurred or the user/group does not match if security is enabled
-
forceSecureOpenFSDataInputStream
@VisibleForTesting protected static FSDataInputStream forceSecureOpenFSDataInputStream(File file, String expectedOwner, String expectedGroup) throws IOException Same as openFSDataInputStream except that it will run even if security is off. This is used by unit tests.- Parameters:
file- input file.expectedOwner- input expectedOwner.expectedGroup- input expectedGroup.- Returns:
- FSDataInputStream.
- Throws:
IOException- raised on errors performing I/O.
-
openForRead
public static FileInputStream openForRead(File f, String expectedOwner, String expectedGroup) throws IOException Open the given File for read access, verifying the expected user/group constraints if security is enabled.- Parameters:
f- the file that we are trying to openexpectedOwner- the expected user owner for the fileexpectedGroup- the expected group owner for the file- Returns:
- Note that this function provides no additional checks if Hadoop security is disabled, since doing the checks would be too expensive when native libraries are not available.
- Throws:
IOException- if an IO Error occurred, or security is enabled and the user/group does not match
-
forceSecureOpenForRead
@VisibleForTesting protected static FileInputStream forceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) throws IOException - Parameters:
f- input f.expectedOwner- input expectedOwner.expectedGroup- input expectedGroup.- Returns:
- Same as openForRead() except that it will run even if security is off. This is used by unit tests.
- Throws:
IOException- raised on errors performing I/O.
-
createForWrite
Open the specified File for write access, ensuring that it does not exist.- Parameters:
f- the file that we want to createpermissions- we want to have on the file (if security is enabled)- Returns:
- createForWrite FileOutputStream.
- Throws:
SecureIOUtils.AlreadyExistsException- if the file already existsIOException- if any other error occurred
-