개인 정보 보호 법률을 준수하도록 액세스 로그 및 활동 보고서 마스크

이 섹션의 스크립트를 사용하여 개인정보보호 법률을 준수하도록 활동 보고서 또는 액세스 로그의 정보를 마스킹하는 프로세스를 자동화할 수 있으며 선택적으로 수신자에게 전자메일로 보낼 수 있습니다.

일부 국가의 엄격한 개인 정보 보호 법률 때문에 사용자의 개인 정보 보호를 위해 활동 보고서 및 액세스 로그에 제공되는 정보가 서비스 관리자에게 표시되지 않도록 숨겨야 할 수도 있습니다.

anonymizeData.bat를 사용하여 개인정보보호 법률을 준수하도록 활동 보고서 또는 액세스 로그의 정보를 마스크하고 선택적으로 전자메일로 보낼 수 있습니다. 정보를 마스크하려면 매일 각 환경에 대한 일별 유지관리 프로세스가 완료된 후 바로 실행되도록 Windows 스케줄러를 사용하여 이 스크립트나 스크립트의 변형을 스케줄링합니다.

다음과 같은 정보 소스를 사용합니다.

다음 절차에 제공된 Windows 스크립트를 복사하여 anonymizeData.bat를 수동으로 생성하고 Windows 스케줄러를 사용하여 스케줄링합니다. Windows를 사용하여 스케줄링하지 않는 경우 플랫폼에 적합한 유사 스크립트를 생성하고 실행할 수도 있습니다.

anonymizeData.bat는 다음 절차에 설명된 대로 생성하고 업데이트하는 anonymizeData.ps1 스크립트를 실행하는 래퍼 스크립트입니다.

사용하는 비밀번호에 특수 문자가 포함된 경우 특수 문자 처리를 참조하십시오.

  1. 다음 스크립트를 포함하는 anonymizeData.bat라는 뱃치(BAT) 파일을 생성한 후 C:\automate_scripts 등의 편리한 위치에 저장합니다.
    @echo off
    set paramRequiredMessage=Syntax: anonymizeData.bat USERNAME PASSWORD/PASSWORD_FILE URL [EMAIL_TO_ADDRESS]
    
    if "%~1" == "" (
      echo User Name is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~2" == "" (
      echo Password or Password_File is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    if "%~3" == "" (
      echo URL is missing.
      echo %paramRequiredMessage%
      exit /b 1
      )
    
    PowerShell.exe -File anonymizeData.ps1 %*
  2. 다음 스크립트를 포함하는 anonymizeData.ps1이라는 PowerShell 스크립트(PS1) 파일을 생성한 후 C:\automate_scripts 등의 편리한 위치에 저장합니다.
    # Anonymize data script
    
    $username=$args[0]
    $password=$args[1]
    $url=$args[2]
    $emailtoaddress=$args[3]
    
    # Generic variables
    $date=$(get-date -f dd_MM_yy_HH_mm_ss)
    $datedefaultformat=$(get-date)
    $logdir="./logs/"
    $logfile="$logdir/anonymize-data-" + $date + ".log"
    $filelist="filelist.txt"
    
    function LogMessage
    {
      $message=$args[0]
    
      echo "$message" >> $logfile
    }
    
    function EchoAndLogMessage
    {
      $message=$args[0]
    
      echo "$message"
      echo "$message" >> $logfile
    }
    function Init
    {
       $logdirexists=Test-Path $logdir
       if (!($logdirexists)) {
           mkdir $logdir 2>&1 | out-null
        }
    
       $logfileexists=Test-Path $logfile
       if ($logfileexists) {
           rm $logfile 2>&1 | out-null
        }
    
       $filelistexists=Test-Path $filelist
       if ($filelistexists) {
           rm $filelist 2>&1 | out-null
        }
    }
    
    function ProcessCommand
    {
       $op=$args
       echo "EPM Automate operation: epmautomate.bat $op" >> $logfile
       if ($op -eq 'listfiles') {
          epmautomate.bat $op | where {$_ -like ' apr/*/access_log.zip'} | Tee-Object -FilePath $filelist | Out-File $logfile -Append 2>&1
        } else {
          epmautomate.bat $op >> $logfile 2>&1
            if ($LASTEXITCODE -ne 0) {
               echo "EPM Automate operation failed: epmautomate.bat $op. See $logfile for details."
               #exit
               }
        }
    }
    
    function RunEpmAutomateCommands
    {
        EchoAndLogMessage "Running EPM Automate commands to anonymize data in the access logs and activity reports."
        ProcessCommand login $username $password $url
        ProcessCommand listfiles
        ProcessFiles
        ProcessCommand logout
    }
    
    function ProcessActivityReport
    {
        $activityreport=$args[0]
        $user=$args[1]
    
        $activityreportexists=Test-Path "$activityreport"
        if ($activityreportexists) {
            LogMessage "Removing User ID: $user from activity report $activityreport"
            (Get-Content "$activityreport").replace("$user", 'XXXXX') | Set-Content "$activityreport"
            $txt = [io.file]::ReadAllText("$activityreport") -replace "`r`n","`n"
            [io.file]::WriteAllText("$activityreport", $txt)
            #Get-ChildItem -File -Recurse | % { $x = get-content -raw -path $activityreport; $x -replace "`r`n","`n" | set-content -path $activityreport }
        }
    }
    
    function AnonymizeData
    {
        $aprdir=$args[0]
        $datestampdir=$args[1]
        $path="$aprdir/$datestampdir"
        $accesslogzipped="access_log.zip"
        $accesslog="access_log.csv"
        $accesslogupdated=$accesslog + ".tmp"
        $activityreportfile="$datestampdir" + ".html"
        $userArray = @()
    
        expand-Archive -Path "$path/$accesslogzipped" -DestinationPath $path
        rm $path/$accesslogzipped 2>&1 | out-null
        $accesslogexists=Test-Path "$path/$accesslog"
        if ($accesslogexists) {
            EchoAndLogMessage "Processing access log: $path/$accesslog"
            Get-Content $path/$accesslog | ForEach-Object {
                $elements=[regex]::Split( $_ , ',(?=(?:[^"]|"[^"]*")*$)' )
                $date=$elements[0]
                $time=$elements[1]
                $uri=$elements[2]
                $duration=$elements[3]
                $bytes=$elements[4]
                $ip=$elements[5]
                $user=$elements[6]
                $screen=$elements[7]
                $action=$elements[8]
                $object=$elements[9]
                if ($date -like 'Date') {
                    echo "$_" >> $path/$accesslogupdated
                } else {
                    if ($user -notlike '-') {
                        LogMessage "Removing instance of User ID: $user from $path/$accesslog."
                        echo "$date,$time,$uri,$duration,$bytes,$ip,XXXXX,$screen,$action,$object" >> $path/$accesslogupdated
                        $userArray += $user
                    } else {
                        echo "$date,$time,$uri,$duration,$bytes,$ip,$user,$screen,$action,$object" >> $path/$accesslogupdated
                    }
                }
            }
            #Get-ChildItem -File -Recurse | % { $x = get-content -raw -path $path/$accesslogupdated; $x -replace "`r`n","`n" | set-content -path $path/$accesslogupdated }
            $txt = [io.file]::ReadAllText("$path/$accesslogupdated") -replace "`r`n","`n"
            [io.file]::WriteAllText("$path/$accesslogupdated", $txt)
            mv -Force $path/$accesslogupdated $path/$accesslog
            Compress-Archive -Path $path/$accesslog $path/$accesslogzipped
            rm $path/$accesslog 2>&1 | out-null
        }
    
        EchoAndLogMessage "Processing activity report: $path/$activityreportfile"
        $userArray = $userArray | Select-Object -Unique
        foreach ($element in $userArray) {
            ProcessActivityReport "$path/$activityreportfile" "$element"            
        }
    }
    
    function ProcessFiles
    {
        # Loop through iteration csv file and parse
        Get-Content $filelist | ForEach-Object {
            $fullpath=$_.trim()
            $elements=$fullpath.split('/')
            $aprdir=$elements[0]
            $datestampdir=$elements[1]
            $accesslogfile="access_log.zip"
            $activityreportfile="$datestampdir" + ".html"
            $datestampdirexists=Test-Path "$aprdir/$datestampdir"
            $accesslog="$aprdir/$datestampdir/$accesslogfile"
            $activityreport="$aprdir/$datestampdir/$activityreportfile"
    
            echo "fullpath: $fullpath" >> $logfile
            echo "aprdir: $aprdir, datestampdir: $datestampdir" >> $logfile
            if (!($datestampdirexists)) {
                mkdir "$aprdir/$datestampdir" -ea 0 2>&1 | out-null
                ProcessCommand downloadfile "$accesslog"
                ProcessCommand downloadfile "$activityreport"
                mv "$accesslogfile" "$aprdir/$datestampdir"
                mv "$activityreportfile" "$aprdir/$datestampdir"
                AnonymizeData "$aprdir" "$datestampdir"
                ProcessCommand deletefile "$accesslog"
                ProcessCommand deletefile "$activityreport"
                ProcessCommand uploadfile "$accesslog" "$aprdir/$datestampdir"
                ProcessCommand uploadfile "$activityreport" "$aprdir/$datestampdir"
            } else {
                EchoAndLogMessage "Files in directory $aprdir/$datestampdir were processed earlier. Skipping these files."
            }
        }
    }
    
    function callSendMail
    {
        $elements=$logfile.split('/')
        $logfilename=$elements[3]
    
        if (${emailtoaddress} -match "@") {
            epmautomate.bat login ${username} ${password} ${url}
            epmautomate.bat uploadFile "$logfile"
            epmautomate.bat sendMail $emailtoaddress "Mask Access Logs and Activity Reports results" Body="The results of running the Mask Access Logs and Activity Reports script are attached." Attachments=$logfilename
            epmautomate.bat deleteFile "$logfilename"
            epmautomate.bat logout
        }
    }
    
    Init
    EchoAndLogMessage "Starting the anonymize data script"
    RunEpmAutomateCommands
    EchoAndLogMessage "Anonymize data script completed"
    EchoAndLogMessage "Refer to logfile: $logfile for details."
    callSendMail
    
  3. Windows 스케줄러를 사용하여 anonymizeData.bat를 스케줄링합니다. 자세한 단계는 스크립트 실행 자동화를 참조하십시오.
    anonymizeData.bat를 실행하려면 다음 매개변수 값을 제공해야 합니다.
    • 서비스 관리자의 사용자 이름
    • 서비스 관리자의 비밀번호 또는 암호화된 비밀번호 파일을 사용할 수 있는 위치
    • 액세스 로그 및 활동 보고서를 마스크할 서비스 환경의 URL
    • 선택사항: 보고서를 보낼 전자메일 주소. 이 값이 지정된 경우에만 보고서를 전자메일로 보냅니다.