一番刊、背景
生產(chǎn)環(huán)境使用的prestodb為Facebook版本的prestodb纠脾,在安裝ranger插件時(shí)發(fā)現(xiàn)源碼中只支持prestosql版本,故考慮將ranger-presto-plugin的代碼改為支持prestodb版本的醋火,同時(shí)去掉對(duì)show schemas虽画、show catalogs、 show tables的鑒權(quán)贩据,因?yàn)樵谂c上層查詢系統(tǒng)對(duì)接時(shí)使用不到栋操,只需要對(duì)select、insert饱亮、drop等操作的鑒權(quán)即可矾芙。
二、ranger presto插件源碼結(jié)構(gòu)
ranger中跟presto插件相關(guān)的模塊為plugin-presto近上、ranger-presto-plugin-shim兩個(gè)剔宪,其中shim為入口,類似hive的shim戈锻,起到適配的作用歼跟,在shim中不實(shí)現(xiàn)具體的業(yè)務(wù)邏輯,均為轉(zhuǎn)調(diào)用plugin-presto模塊中的類方法格遭,兩個(gè)模塊中均有類:org.apache.ranger.authorization.presto.authorizer.RangerSystemAccessControl哈街,該類實(shí)現(xiàn)了各種具體的鑒權(quán)邏輯。
三拒迅、ranger插件被加載的過(guò)程
ranger-presto-plugin-shim的org.apache.ranger.authorization.presto.authorizer.PrestoRangerPlugin實(shí)現(xiàn)了presto的com.facebook.presto.spi.Plugin接口(此處已經(jīng)是換為prestodb下的類骚秦,修改前為prestosql中的類io.prestosql.spi.Plugin),同時(shí)在resouces/META-INF.services目錄下有spi相關(guān)的文件io.prestosql.spi.Plugin璧微,文件內(nèi)容為Plugin的實(shí)現(xiàn)類org.apache.ranger.authorization.presto.authorizer.PrestoRangerPlugin作箍;
presto進(jìn)程在啟動(dòng)時(shí)會(huì)使用java spi自動(dòng)裝載技術(shù)將Plugin接口的所有實(shí)現(xiàn)類都加載到進(jìn)程中,具體代碼在presto源碼的PluginManger#loadPlugin方法中:
四前硫、ranger插件代碼修改內(nèi)容
1胞得、兩個(gè)模塊的pom中中prestosql依賴,換為facebook的presto依賴屹电,修改各類中引用的類為facebook的presto中的類阶剑,RangerSystemAcessControl實(shí)現(xiàn)的接口方法中有一些入?yún)⑿枰{(diào)整。
2危号、shim包: resouces/META-INF.services目錄下文件名修改為Facebook presto的包名:com.facebook.presto.spi.Plugin
3牧愁、打包兩個(gè)模塊,并替換安裝目錄下對(duì)應(yīng)的jar包
mvn clean package -Dmaven.test.skip=true -pl plugin-presto -am -amd
mvn clean package -Dmaven.test.skip=true -pl ranger-presto-plugin-shim -am -amd
4外莲、修改后的代碼見(jiàn)github: zfqhd43/ranger-prestodb
五猪半、其他
遠(yuǎn)程debug方式:
1、在/opt/software/presto/bin/launcher.py中添加:command += ['-agentlib:jdwp=transport=dt_socket,address=5007,server=y,suspend=n'],位置如下:
2磨确、在idea中新建remote jvm debug