expdp로 지정하는 디렉토리의 권한으로 조금 빠진 이야기 (초보자 용)

안녕하세요. hrkii123이라고 합니다.

이 항목은 JPOUG Advent Calendar 2019의 18일째 기사입니다.

Qiita 최초 투고가 JPOUG 어드벤트 캘린더 2019가 되었습니다.

JPOUG 어드벤트 캘린더 2019
htps : // 아 dゔ ㄇ r. 오 rg / 돈 rs / 4154

소개



이번은 datapump의 expdp 유틸리티로는 전혀 이야기입니다.

어느 날. 개발팀마다 OS 유저, DB 유저, OS 디렉토리등을 나누어, 팀간에 서로 데이터를 참조할 수 없게 한다고 하는 요건중 DB 주위의 설계를 실시하고 있었습니다.
그 중 datapump로 내보내는 OS 디렉토리도 팀별로 준비하고 서로의 덤프 파일을 참조할 수 없도록 해달라고 주문이 들어갔습니다.

나는 그런 OS 디렉토리의 퍼미션으로 간단하게 제어할 수 있다고 생각하고 있었습니다.
(그렇게 간단하지는 않았다.)

그리고, 여러가지 시험한 검증 내용을 정리했습니다.

개요도



datapump에서 user_A 스키마를/var/work/Adir로 내보냅니다.
내보내기 후 Aadmin 사용자 만/var/work/Adir 아래의 덤프 파일에 액세스 할 수 있으며 Badmin 사용자는 액세스 할 수 없습니다.
액세스 여부는 OS 디렉터리의 권한 설정에서 수행됩니다. 또한 다이어그램에는 표시되지 않았지만 DB는 12.1 RAC 환경을 사용했습니다. (우연히 가상 머신이 있었기 때문에 ..)



검증을 위해 DB 사용자 "user_A"와 디렉토리 객체 "dirA"를 작성해 둡니다.
DB 사용자 "user_A"에게 필요한 권한을 부여합니다.
create user user_A identified by welcome1;
CREATE DIRECTORY dirA AS '/var/work/Adir';
grant create session,resource,unlimited tablespace to user_A;
grant read, write on directory dirA to user_A;

자,이 상태에서 expdp를 실행할 수 있습니까?
/u01/app/oracle/product/12.1.0/dbhome_1/bin/expdp user_A/welcome1@testdb directory=dirA dumpfile=expdp_A.log schemas=user_A

아래 출력과 같이 오류가 발생했습니다.
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation

위의 오류는 OS 디렉터리의 권한이 적절하지 않을 때 출력됩니다.

디렉토리 오브젝트로 지정하고 있는 OS 디렉토리는 소유자 Aadmin, 소유 그룹 Aadmin이 되고 있습니다. datapump 스펙으로 내보내는 덤프 파일은 소유자 oracle, 소유 그룹 asmadmin입니다. 즉, datapump를 실행하면 oracle 사용자와 asmadmin 그룹의 액세스가 허용되어야 합니다. OS 디렉토리 권한이 777이면 아무 것도 신경 쓸 필요는 없지만, 이 경우 oracle 사용자는 Aadmin 그룹에 속하지 않으므로 OS 디렉토리에 액세스 할 수 없습니다.

해결책으로, 이번에는 oracle 및 grid 사용자의 보조 그룹에 Aadmin을 추가하기로 결정합니다.
id oracle
uid=54321(oracle) gid=54321(oinstall)groups=54321(oinstall),54322(dba),1101(oper),1102(backupdba),1103(dgdba),1104(kmdba),1201(asmdba),54323(Aadmin)

id grid
uid=1100(grid) gid=54321(oinstall)groups=54321(oinstall),1200(asmadmin),1201(asmdba),1202(asmoper),54323(Aadmin)

이번에는 성공할까요?
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation

다시 나왔습니다. 이 오류! !
OS 디렉토리에 액세스 할 수 있어야하지만,

그건 그렇고, OS 디렉토리의 권한을 777로 변경하면 제대로 작동합니다.
$ /u01/app/oracle/product/12.1.0/dbhome_1/bin/expdp user_A/welcome1@testdb directory=dirA 
dumpfile=expdp_A.log schemas=user_A

Export: Release 12.1.0.2.0 - Production on Sun Dec 15 03:53:01 2019

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options
Starting "USER_A"."SYS_EXPORT_SCHEMA_01":  user_A/********@testdb directory=dirA dumpfile=expdp_A.log schemas=user_A
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Master table "USER_A"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for USER_A.SYS_EXPORT_SCHEMA_01 is:
  /var/work/Adir/expdp_A.log
Job "USER_A"."SYS_EXPORT_SCHEMA_01" successfully completed at Sun Dec 15 03:53:42 2019 elapsed 0 00:00:38

[oracle@node1 ~]$

결국 어떻게 했는가



RAC 환경에서 oracle,grid 사용자의 보조 그룹을 추가할 때는 클러스터웨어에 인식시켜야 합니다! 그룹을 추가한 후 클러스터웨어를 다시 시작하면 인식됩니다.
pmon의 프로세스를 확인하여 사용자 그룹이 추가되었음을 클러스터웨어가 알고 있는지 확인할 수 있습니다.

CRS 재부팅 후


ps -ef | grep pmon
    grid     14417     1  0 05:37 ?        00:00:00 asm_pmon_+ASM1
    oracle   15136     1  0 05:37 ?        00:00:00 ora_pmon_ctestdb1
    grid     15143     1  0 05:37 ?        00:00:00 mdb_pmon_-MGMTDB
    oracle   30528 27106  0 06:06 pts/1    00:00:00 grep pmon

cat /proc/14417/status |grep Groups

    Groups: 1200 1201 1202 54321 54323 ★54323(Aadmin)が認識されている

cat /proc/15136/status |grep Groups

  Groups: 1101 1102 1103 1104 1201 54321 54322 54323 ★54323(Aadmin)が認識されている

이제 마침내 expdp가 가능해졌습니다.
$ /u01/app/oracle/product/12.1.0/dbhome_1/bin/expdp user_A/welcome1@testdb directory=dirA dumpfile=expdp_A.log schemas=user_A

Export: Release 12.1.0.2.0 - Production on Sun Dec 15 05:58:12 2019

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options
Starting "USER_A"."SYS_EXPORT_SCHEMA_01":  user_A/********@testdb directory=dirA dumpfile=expdp_A.log schemas=user_A
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Master table "USER_A"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for USER_A.SYS_EXPORT_SCHEMA_01 is:
  /var/work/Adir/expdp_A.log
Job "USER_A"."SYS_EXPORT_SCHEMA_01" successfully completed at Sun Dec 15 05:58:36 2019 elapsed 0 00:00:23

실현하고 싶은 액세스 제어도 가능합니다.
$ id
uid=54323(Badmin) gid=54324(Badmin) groups=54324(Badmin)
$ cd /var/work/Adir/
-bash: cd: /var/work/Adir/: Permission denied
$ ls -l /var/work/Adir/
ls: cannot open directory /var/work/Adir/: Permission denied

이상이 됩니다.

JPOUG 어드벤트 캘린더 2019의 19일째 기사도 기대하세요~

좋은 웹페이지 즐겨찾기