日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Apache Derby数据库JVM安全策略

發布時間:2023/12/3 数据库 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache Derby数据库JVM安全策略 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

抽象

我已經發布了許多有關Derby的博客:

  • Derby數據庫備份
  • 同一主機上的多個Derby網絡服務器
  • Apache Derby數據庫用戶和權限
  • 與Maven和內存中Derby數據庫的集成測試

這本不打算是一個系列。 但是多年來,我越來越多地使用Derby。 我開始使用Derby作為微服務體系結構的首選數據庫。 這些是個人使用的應用程序,因此Derby綽綽有余。 即使這些是個人使用的應用程序,我也需要具有有限用戶權限的 多臺服務器 ,當然還有數據庫備份和還原 。 最終要求是安全性。 我使用derby usr帳戶在Ubuntu Linux VM上運行Derby數據庫。 盡管derby usr帳戶對VM的權限有限,但是任何額外的安全層都是好的。 因此,本博客的目的是演示如何使用Java安全策略運行Derby,以限制JVM的權限并增強運行時安全性。

免責聲明

這篇文章僅供參考。 在使用所提供的任何信息之前,請認真思考。 從中學到東西,但最終自己做出決定,風險自負。

要求

我使用以下主要技術完成了本文的所有工作。 您可能可以使用不同的技術或版本來做相同的事情,但不能保證。

  • Apache Derby 10.14.2.0
  • Java zulu11.39.15-ca-jdk11.0.7-linux_x64

我將不涉及下載和安裝這些技術的過程。 我將其留給您練習。

注意從版本10.15開始,Derby項目已更新為使用Java 9模塊系統。 結果,JAR文件已經發生了很大變化。 下面的security.policy不太可能與10.15+版本一起使用。 截至本博客的發布日期,我還沒有嘗試過。

Linux bash腳本

為了管理Derby使其與Java安全策略一起運行,您需要3個腳本。 第一個腳本將設置設置環境變量以配置Derby。 第二個腳本將啟動Derby網絡服務器,并傳遞正確的命令行參數。 第三臺將停止Derby網絡服務器。

清單1.1向您展示了這些腳本中的第一個。 它導出具有特定配置值的許多系統環境變量,這些配置值專門用于在您的環境中運行Derby。

清單1.1 – setenv.sh

#!/bin/bash export DERBY_HOME=/home/derby/opt/derby export PATH= "$DERBY_HOME/bin:$PATH" echo "DERBY_HOME=$DERBY_HOME" export JAVA_HOME=/home/derby/opt/java echo "JAVA_HOME=$JAVA_HOME" export NS_HOME=/var/local/derby/ 1527 mkdir -p $NS_HOME echo "NS_HOME=$NS_HOME" export NS_PORT= 1527 echo "NS_PORT=$NS_PORT" export NS_HOST= 0.0 . 0.0 echo "NS_HOST=$NS_HOST" export DERBY_OPTS= "" export DERBY_OPTS= "$DERBY_OPTS -Dderby.drda.host=$NS_HOST" export DERBY_OPTS= "$DERBY_OPTS -Dderby.drda.portNumber=$NS_PORT" export DERBY_OPTS= "$DERBY_OPTS -Dderby.system.home=$NS_HOME" # Security Policy export DERBY_OPTS= "$DERBY_OPTS -Dderby.stream.error.logSeverityLevel=0" export DERBY_OPTS= "$DERBY_OPTS -Dderby.security.port=$NS_PORT" export DERBY_OPTS= "$DERBY_OPTS -Dderby.install.url=file:$DERBY_HOME/lib/" export DERBY_OPTS= "$DERBY_OPTS -Djava.security.manager" export DERBY_OPTS= "$DERBY_OPTS -Djava.security.policy=$NS_HOME/security.policy"

DERBY_HOME不言自明。 這是解壓縮(安裝)Derby的地方。 將Derby的bin目錄添加到PATH 。

JAVA_HOME是不言自明的。 這是解壓縮(安裝)Java的地方。 將Java的bin目錄添加到PATH 。

NS_HOME“N etwork 小號 erver家”。 這是Derby網絡服務器將用于存儲其配置和數據庫的目錄。 每當在此Derby網絡服務器上創建新數據庫時,都會在NS_HOME下為新數據庫創建一個新的子目錄。 這允許在同一主機上運行的多個Derby網絡服務器將其數據分開。

NS_PORT“N etwork 小號 erver端口”。 這是Derby網絡服務器用來偵聽連接的端口。 這允許多個Derby網絡服務器在同一主機上運行。

NS_HOST“N etwork 小號 erver主機”。 它設置偵聽連接時Derby網絡服務器使用的網絡接口。 默認情況下,Derby網絡服務器僅在127.0.0.1的環回地址上偵聽連接。 此默認值表示客戶端必須與網絡服務器在同一主機上運行-不太有用。 通過將主機設置為0.0.0.0 ,Derby網絡服務器將偵聽主機上任何網絡接口上的連接。 如果您的VM具有多個網絡接口,則應將NS_HOST設置為這些接口之一的IP。 設置此值可使客戶端成為遠程客戶端。

DERBY_OPTS是用于將所有配置選項獲取到Derby的系統屬性。 通過將適當的Derby系統屬性及其關聯值連接在一起來創建其值。 使用或不使用安全策略來啟動Derby都需要前三個屬性。

  • derby.drda.host
  • derby.drda.portNumber
  • derby.system.home
  • 配置Derby使其與安全策略一起運行時,需要最后5個屬性。

  • derby.stream.error.logSeverityLevel
  • derby.security.port
  • derby.install.url
  • java.security.manager
  • java.security.policy
  • 其中最重要的特性之一是java.security.policy=$NS_HOME/security.policy" 。這個屬性指向的值security.policy文件,該文件將配置Java SecurityManager ,你會讀到有關創建security.policy文件接下來,您將看一下啟動服務器的腳本。

    清單1.2顯示了這些腳本的第二個。 它會啟動Derby網絡服務器,并傳遞正確的命令行參數,因此Derby會以安全策略運行。

    清單1.2 – start.sh

    #!/bin/bash # Directory of the script SD=$( cd "$( dirname " ${BASH_SOURCE[ 0 ]} " )" && pwd ) # Source in common variables source $SD/setenv.sh # Symlink the network server configurations ln -sf $SD/../conf/security.policy $NS_HOME/security.policy ln -sf $SD/../conf/derby.properties $NS_HOME/derby.properties startNetworkServer

    SDS CRIPT d irectory。 該評估確定start.sh腳本的標準文件系統位置,并將其分配給SD 。 當引用其他腳本時,這很有用。

    來源不言自明。 它在系統環境變量中來源以配置Derby網絡服務器。 有關詳細信息,請參見清單1.1。

    Symlink配置適用于security.policy文件和derby.properties文件。 符號鏈接的目的是將這兩個文件放入$NS_HOME目錄。 Derby在$NS_HOME目錄中尋找derby.properties文件,因此它必須存在。 為了保持一致性(不是必需的),您還希望將security.policy文件放在此處。 在清單1.1中, java.security.policy=$NS_HOME/security.policy"屬性配置了此位置。對于我的環境,我將$NS_HOME目錄與保存管理腳本和其他Derby配置文件的目錄分開。我這樣做是因為災難恢復,我認為$NS_HOME目錄是$NS_HOME ,這意味著如果由于某種原因它丟失了(刪除,磁盤驅動器錯誤,損壞,構建新的VM等),我必須能夠恢復數據庫數據,管理腳本( setenv.sh , start.sh , stop.sh )和配置文件( security.policy , derby.properties從我的云備份)。 真正的配置文件的保留之外$NS_HOME目錄, start.sh將它們在正確的位置符號鏈接。

    startNetworkServer是Derby提供的腳本( $DERBY_HOME/bin ),用于啟動網絡服務器。 該DERBY_OPTS變量-在設置setenv.sh -用于配置網絡服務器。 默認情況下,Derby使用有限的安全策略運行。 但是,由于配置了安全策略,因此Derby將使用您的配置而不是默認配置。

    現在,您具有Derby服務器環境配置和啟動腳本。 您還沒有能夠停止Derby網絡服務器的功能。 停止服務器很容易。 您將查看下一個用于停止服務器的腳本。

    注意仍然還需要security.policy文件。 我保證,您將在短時間內閱讀到有關它的信息!

    清單1.3顯示了這些腳本的第三個。 它將停止Derby網絡服務器。 不太令人興奮,但是對服務器進行有管理的關閉以防止數據損壞很重要。

    清單1.3 – stop.sh

    #!/bin/bash # Directory of the script SD=$( cd "$( dirname " ${BASH_SOURCE[ 0 ]} " )" && pwd ) # Source in common variables source $SD/setenv.sh stopNetworkServer

    所有這些都是不言自明的。 此腳本不需要進一步的注釋。

    security.policy文件

    Derby隨附一個演示安全策略文件。 它位于DERBY_HOME/demo/templates/security.policy 。 使用此文件作為起點,我能夠生成滿足以下要求的最終版本:

    • 網絡(遠程)訪問
    • 本地主機訪問
    • 啟動
    • 關掉
    • 后備

    清單2.1 – security.policy

    // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // grant codeBase "${derby.install.url}derby.jar" { // These permissions are needed for everyday, embedded Derby usage. // permission java.lang.RuntimePermission "createClassLoader" ; permission java.util.PropertyPermission "derby.*" , "read" ; permission java.util.PropertyPermission "user.dir" , "read" ; permission org.apache.derby.security.SystemPermission "engine" , "usederbyinternals" ; // The next two properties are used to determine if the VM is 32 or 64 bit. // permission java.util.PropertyPermission "sun.arch.data.model" , "read" ; permission java.util.PropertyPermission "os.arch" , "read" ; permission java.io.FilePermission "${derby.system.home}" , "read" ; permission java.io.FilePermission "${derby.system.home}${/}-" , "read,write,delete" ; // Needed by sysinfo. A file permission is needed to check the existence of // jars on the classpath. You can limit this permission to just the locations // which hold your jar files. This block is reproduced for all codebases // which include the sysinfo classes--the policy file syntax does not let you // grant permissions to several codebases all at once. // permission java.util.PropertyPermission "user.*" , "read" ; permission java.util.PropertyPermission "java.home" , "read" ; permission java.util.PropertyPermission "java.class.path" , "read" ; permission java.util.PropertyPermission "java.runtime.version" , "read" ; permission java.util.PropertyPermission "java.fullversion" , "read" ; permission java.lang.RuntimePermission "getProtectionDomain" ; permission java.io.FilePermission "java.runtime.version" , "read" ; permission java.io.FilePermission "java.fullversion" , "read" ; permission java.io.FilePermission "${derby.install.path}${/}-" , "read" ; permission java.io.FilePermission "/tmp${/}-" , "read,write,delete" ; // Permissions needed for JMX based management and monitoring. // // Allows this code to create an MBeanServer: // permission javax.management.MBeanServerPermission "createMBeanServer" ; // Allows access to Derby's built-in MBeans, within the domain // org.apache.derby. Derby must be allowed to register and unregister these // MBeans. To fine tune this permission, see the javadoc of // javax.management.MBeanPermission or the JMX Instrumentation and Agent // Specification. // permission javax.management.MBeanPermission "org.apache.derby.*#[org.apache.derby:*]" , "registerMBean,unregisterMBean" ; // Trusts Derby code to be a source of MBeans and to register these in the // MBean server. // permission javax.management.MBeanTrustPermission "register" ; // Gives permission for jmx to be used against Derby but only if JMX // authentication is not being used. In that case the application would need // to create a whole set of fine-grained permissions to allow specific users // access to MBeans and actions they perform. // permission org.apache.derby.security.SystemPermission "jmx" , "control" ; permission org.apache.derby.security.SystemPermission "engine" , "monitor" ; permission org.apache.derby.security.SystemPermission "server" , "monitor" ; // getProtectionDomain is an optional permission needed for printing // classpath information to derby.log // permission java.lang.RuntimePermission "getProtectionDomain" ; // The following permission must be granted for Connection.abort(Executor) to // work. Note that this permission must also be granted to outer // (application) code domains. // permission java.sql.SQLPermission "callAbort" ; permission java.sql.SQLPermission "deregisterDriver" ; // Needed by FileUtil#limitAccessToOwner // permission java.lang.RuntimePermission "accessUserInformation" ; permission java.lang.RuntimePermission "getFileStoreAttributes" ; }; grant codeBase "${derby.install.url}derbynet.jar" { // These permissions lets the Network Server manage connections from clients. // Accept connections from any host. Derby is listening to the host interface // specified via the -h option to "NetworkServerControl start" on the command // line, via the address parameter to the // org.apache.derby.drda.NetworkServerControl constructor in the API or via // the property derby.drda.host; the default is localhost. You may want to // restrict allowed hosts, eg to hosts in a specific subdomain, // eg "*.example.com". // permission java.net.SocketPermission "*" , "accept" ; // Allow the server to listen to the socket on the port specified with the // -p option to "NetworkServerControl start" on the command line, or with // the portNumber parameter to the NetworkServerControl constructor in the // API, or with the property derby.drda.portNumber. The default is 1527. permission java.net.SocketPermission "localhost:${derby.security.port}" , "listen" ; permission java.net.SocketPermission "${derby.drda.host}:${derby.security.port}" , "listen" ; // Needed for server tracing. // permission java.io.FilePermission "${derby.drda.traceDirectory}${/}-" , "read,write,delete" ; // Needed by FileUtil#limitAccessToOwner // permission java.lang.RuntimePermission "accessUserInformation" ; permission java.lang.RuntimePermission "getFileStoreAttributes" ; // Needed for NetworkServerMBean access (see JMX section above) // permission org.apache.derby.security.SystemPermission "server" , "control,monitor" ; permission org.apache.derby.security.SystemPermission "engine" , "usederbyinternals" ; // Needed by sysinfo. A file permission is needed to check the existence of // jars on the classpath. You can limit this permission to just the locations // which hold your jar files. This block is reproduced for all codebases // which include the sysinfo classes--the policy file syntax does not let you // grant permissions to several codebases all at once. // permission java.util.PropertyPermission "user.*" , "read" ; permission java.util.PropertyPermission "java.home" , "read" ; permission java.util.PropertyPermission "java.class.path" , "read" ; permission java.util.PropertyPermission "java.runtime.version" , "read" ; permission java.util.PropertyPermission "java.fullversion" , "read" ; permission java.lang.RuntimePermission "getProtectionDomain" ; permission java.io.FilePermission "java.runtime.version" , "read" ; permission java.io.FilePermission "java.fullversion" , "read" ; permission java.io.FilePermission "${derby.install.path}${/}-" , "read" ; permission java.util.PropertyPermission "derby.*" , "read,write" ; permission java.net.SocketPermission "localhost:${derby.security.port}" , "connect,resolve" ; permission java.net.SocketPermission "${derby.drda.host}:${derby.security.port}" , "connect,resolve" ; }; grant codeBase "${derby.install.url}derbytools.jar" { // Needed by sysinfo. A file permission is needed to check the existence of // jars on the classpath. You can limit this permission to just the locations // which hold your jar files. This block is for all codebases which include // the sysinfo classes--the policy file syntax does not let you grant // permissions to several codebases all at once. // permission java.util.PropertyPermission "user.*" , "read" ; permission java.util.PropertyPermission "java.home" , "read" ; permission java.util.PropertyPermission "java.class.path" , "read" ; permission java.util.PropertyPermission "java.runtime.version" , "read" ; permission java.util.PropertyPermission "java.fullversion" , "read" ; permission java.lang.RuntimePermission "getProtectionDomain" ; permission java.io.FilePermission "<<ALL FILES>>" , "read" ; permission java.io.FilePermission "java.runtime.version" , "read" ; permission java.io.FilePermission "java.fullversion" , "read" ; permission java.util.PropertyPermission "*" , "read,write" ; }; grant codeBase "${derby.install.url}derbyclient.jar" { // Needed by sysinfo. A file permission is needed to check the existence of // jars on the classpath. You can limit this permission to just the locations // which hold your jar files. This block is reproduced for all codebases // which include the sysinfo classes--the policy file syntax does not let you // grant permissions to several codebases all at once. // permission java.util.PropertyPermission "user.*" , "read" ; permission java.util.PropertyPermission "java.home" , "read" ; permission java.util.PropertyPermission "java.class.path" , "read" ; permission java.util.PropertyPermission "java.runtime.version" , "read" ; permission java.util.PropertyPermission "java.fullversion" , "read" ; permission java.lang.RuntimePermission "getProtectionDomain" ; permission java.io.FilePermission "${derby.install.path}${/}-" , "read" ; // The following permission must be granted for Connection.abort(Executor) to // work. Note that this permission must also be granted to outer // (application) code domains. // permission java.sql.SQLPermission "callAbort" ; permission java.net.SocketPermission "localhost:${derby.security.port}" , "connect,resolve" ; permission java.net.SocketPermission "${derby.drda.host}:${derby.security.port}" , "connect,resolve" ; };

    策略文件很多。使用Java 20年后,我只遇到過幾次。 我不假裝知道策略文件中的所有內容。 我所知道的是,此文件可滿足我的所有要求。 每次Derby更新都需要進行測試,并且可能需要進行一些調整。 derby-users@db.apache.org郵件列表是您最好的信息來源。

    從derby-users@db.apache.org郵件列表向Rick Hillegas大聲喊叫,以幫助我獲得此版本的策略文件。 他提供了大部分內容,我添加了以下內容以滿足我的要求。

    第50行permission java.io.FilePermission "/tmp${/}-", "read,write,delete"; 。 我的數據庫備份過程使用CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE ('/tmp/resiste-backup/1527') 。 因此, derby.jar文件需要對文件系統上/tmp目錄的讀取,寫入,刪除權限,以便可以將備份寫入該目錄。

    第92行permission java.sql.SQLPermission "deregisterDriver"; 。 使用ij工具管理我的Derby數據庫時,在derby.log文件中發現了關于deregisterDriver的異常。 因此,我也將此權限添加到了derby.jar文件中。

    第160行permission java.net.SocketPermission "${derby.drda.host}:${derby.security.port}", "connect,resolve"; 。 屬性derby.drda.host和derby.security.port在設定setenv.sh腳本(列表1.1)。 我必須添加此權限,因為遠程(非本地主機)客戶端可以訪問我的Derby網絡服務器。 在setenv.sh ,我用-Dderby.drda.host=0.0.0.0覆蓋默認的本地主機唯一接口監聽。 我還發現在測試stop.sh腳本(清單1.3)時,我需要在策略文件中使用stop.sh 。

    摘要

    而已。 希望您喜歡學習如何使用安全策略來運行Derby網絡服務器。

    翻譯自: https://www.javacodegeeks.com/2020/04/apache-derby-database-jvm-security-policy.html

    總結

    以上是生活随笔為你收集整理的Apache Derby数据库JVM安全策略的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。