oracle只能在辅助组关联时读取本地文件吗?

Pau*_*aul 16 oracle oracle12c

我试图从Oracle运行一个非常简单的python脚本.Oracle与脚本位于同一个Linux机器上.它会打开一个文件并创建一个校验和.它由oracle中的'recon'用户触发.

只要文件所有者是'oracle',或者组是'oinstall'(oracle的默认组),或者public设置为rx,脚本就可以正常工作,从Oracle内部运行脚本就可以正常工作.

问题是我们必须使用不同的用户:组,我们不能使用公共权限.我们将oracle用户添加到文件的组中.

uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),202175(efs_data)
Run Code Online (Sandbox Code Playgroud)

当我们像以前一样从Oracle内部运行时,它现在失败了,但是,当sudo进入oracle用户并直接运行脚本时,它可以工作,所以我们知道linux权限是可以的.

什么可能导致这个?我猜Oracle正在进行一些覆盖linux权限的其他类型的访问检查,这会忽略辅助组并仅查看gid.

作为'recon'架构:

set serveroutput on size unlimited
declare
 x number;
begin
 x := run_cmd('/home/oracle/bin_dir/pytest.py');
 dbms_output.put_line('return:' || x);
end;
Run Code Online (Sandbox Code Playgroud)

RUN_CMD:

create or replace function RUN_CMD( p_cmd  in varchar2) return number as
language java
name 'Util.RunThis(java.lang.String) return integer';
Run Code Online (Sandbox Code Playgroud)

Util.RunThis:

import java.io.*;
  import java.lang.*;

  public class Util extends Object
  {

    public static int RunThis(java.lang.String args)
    {
    Runtime rt = Runtime.getRuntime();
    int        rc = -1;

    try
    {
       Process p = rt.exec(args);

       int bufSize = 4096;
       BufferedInputStream bis =
        new BufferedInputStream(p.getInputStream(), bufSize);
       int len;
       byte buffer[] = new byte[bufSize];

       // Echo back what the program spit out
       while ((len = bis.read(buffer, 0, bufSize)) != -1)
          System.out.write(buffer, 0, len);

       rc = p.waitFor();
    }
    catch (Exception e)
    {
       e.printStackTrace();
       rc = -1;
    }
    finally
    {
       return rc;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

/home/oracle/bin_dir/pytest.py:

#! /usr/bin/python -W ignore::DeprecationWarning
import paramiko
import logging
import datetime
import pwd
import md5
import os

def test_file_open(local_file):
  print 'Trying to open: '+ local_file
  logging.info('Trying to open: ' + local_file)
  local_file_data = open(local_file, "rb").read()
  checksum = md5.new(local_file_data).hexdigest()
  return checksum

def main():
  logging.basicConfig(filename='/mounts/users/dmz/pytest.log', level=logging.INFO)
  logging.info('==========================================')
  logging.info('START: ' + str(datetime.datetime.now()))
  logging.info('getuid: ' + pwd.getpwuid( os.getuid() ).pw_name)
  logging.info('geteuid: ' + pwd.getpwuid( os.geteuid() ).pw_name)

  checksum = test_file_open('/test.txt')

  print 'Success!, checksum: ' + checksum
  logging.info('Success! checksum: ' + checksum)
  logging.info('END: ' + str(datetime.datetime.now()))

if __name__ == '__main__':
  main()
Run Code Online (Sandbox Code Playgroud)

输出(以oracle作为文件所有者):

-rwxrwx---. 1 oracle efs_data 0 Jun  7 19:56 /test.txt

INFO:root:==========================================
INFO:root:START: 2018-06-07 19:45:32.005429
INFO:root:getuid: oracle
INFO:root:geteuid: oracle
INFO:root:Trying to open: /test.txt
INFO:root:Success! checksum: 9f1e1404fd72b59121d45a8beb4dab5d
INFO:root:END: 2018-06-07 19:45:32.007078
Run Code Online (Sandbox Code Playgroud)

输出(仅通过组关联具有权限):

-rwxrwx---. 1 root efs_data 0 Jun  7 19:57 /test.txt

INFO:root:==========================================
INFO:root:START: 2018-06-07 19:44:15.748559
INFO:root:getuid: oracle
INFO:root:geteuid: oracle
INFO:root:Trying to open: /test.txt
Run Code Online (Sandbox Code Playgroud)

小智 4

我对 DIRECTORY 和外部表也有类似的问题,其中 linux 组访问似乎被忽略了。我能够通过使用 acl 并让 oracle 用户拥有所需的权限,同时让文件的所有权保留给另一个用户来解决。

ll test.txt
-rwx------. 1 lunc users 940 Jun 13 09:34 test.txt

setfacl -m u:oracle:rwx test.txt

getfacl test.txt

# file: test.txt
# owner: lunc
# group: users
user::rwx
user:oracle:rwx
group::---
mask::rwx
other::---

ll test.txt
-rwxrwx---+ 1 lunc users 940 Jun 13 09:34 test.txt
Run Code Online (Sandbox Code Playgroud)

Oracle 接受这一点(至少对于外部表而言)并且能够访问该文件。