cd /usr/hdp/current/knox-server
touch conf/topologies/haha.xml
<?xml version="1.0" encoding="utf-8"?>
<topology>
<gateway>
<provider>
<role>authentication</role>
<name>ShiroProvider</name>
<enabled>false</enabled>
<param>
<name>main.ldapRealm</name>
<value>org.apache.hadoop.gateway.shirorealm.KnoxLdapRealm</value>
</param>
<param>
<name>main.ldapContextFactory</name>
<value>org.apache.hadoop.gateway.shirorealm.KnoxLdapContextFactory</value>
</param>
<param>
<name>main.ldapRealm.contextFactory</name>
<value>$ldapContextFactory</value>
</param>
<param>
<name>main.ldapRealm.contextFactory.url</name>
<value>ldap://fsmanager</value>
</param>
<param>
<name>main.ldapRealm.contextFactory.authenticationMechanism</name>
<value>simple</value>
</param>
<param>
<name>main.ldapRealm.userDnTemplate</name>
<value>uid={0},ou=people,dc=hadoop,dc=apache,dc=org</value>
</param>
<param>
<name>urls./**</name>
<value>authcBasic</value>
</param>
</provider>
<provider>
<role>identity-assertion</role>
<name>Default</name>
<enabled>true</enabled>
</provider>
<provider>
<role>hostmap</role>
<name>static</name>
<enabled>true</enabled>
<param>
<name>localhost</name>
<value>sandbox,sandbox.hortonworks.com,fsmanager</value>
</param>
</provider>
<provider>
<role>federation</role>
<name>SSOCookieProvider</name>
<enabled>true</enabled>
<param>
<name>sso.authentication.provider.url</name>
<value>https://fsmanager:8443/gateway/knoxsso/api/v1/websso</value>
</param>
</provider>
</gateway>
<service>
<role>HAHAUIIII</role>
<url>http://fsmanager:5000</url>
</service>
</topology>
mkdir -p /data/services/hahauiiii/2.4.0
touch {service, rewrite}.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<service role="HAHAUIIII" name="hahauiiii" version="2.4.0">
<routes>
<!-- https://fsmanager:8443/gateway/haha/hahauiiii -->
<route path="/hahauiiii/?**">
<rewrite apply="HAHAUIIII/hahauiiii/inbound" to="request.url"/>
</route>
<!-- https://fsmanager:8443/gateway/haha/hahauiiii/v1/?op=LISTSTATUS -->
<route path="/hahauiiii/v1/?**">
<rewrite apply="HAHAUIIII/hahauiiii/inbound/version" to="request.url"/>
</route>
</routes>
<service>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rules>
<rule dir="IN" name="HAHAUIIII/hahauiiii/inbound" pattern="*://*:*/**/hahauiiii">
<rewrite template="{$serviceUrl[HAHAUIIII]}"/>
</rule>
<rule dir="IN" name="HAHAUIIII/hahauiiii/inbound/version" pattern="*://*:*/**/hahauiiii/{version}/?{**}">
<rewrite template="{$serviceUrl[HAHAUIIII]}/{version}/?{**}"/>
</rule>
</rules>
bin/knoxcli.sh redeploy --cluster haha
bin/gataway.sh stop
bin/gateway.sh start
data
└── services
└── hahauiiii
└── 2.4.0
├── rewrite.xml
└── service.xml
<service role="HAHAUIIII" name="hahauiiii" version="2.4.0">
<routes>
<route path="/hahauiiii/?**"></route>
</routes>
</service>
<service role="HAHAUIIII">
<topology><service><role>
属性
<service name="hahauiiii">
<GATEWAY_HOME>/data/services
中相应的目录名称,这里是指hahauiiii
这个目录名称
<service version="2.4.0">
<GATEWAY_HOME>/data/services
, 这里是指2.4.0
这个目录名称
<route path="/hahauiiii/?**"></route>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rules>
<rule dir="IN" name="HAHAUIIII/hahauiiii/inbound" pattern="*://*:*/**/hahauiiii">
<rewrite template="{$serviceUrl[HAHAUIIII]}"/>
</rule>
<rule dir="IN">
<rule name="HAHAUIIII/hahauiiii/inbound">
<rule pattern="*://*:*/**/hahauiiii">
<rewrite template="{$serviceUrl[HAHAUIIII]}"/>
{$serviceUrl[HAHAUIIII]}
会去寻找topologies中的指定ROLE中定义的URL, 这里指的是haha.xml
中ROLE为HAHAUIIII
中定义的URL<url>http://fsmanager:5000</url>
500: rewrite.xml
内容可能有问题,特别是partern
可能有误
404:service.xml
内容有问题,特别是path
可能有误
Understanding Rewrite Rules for Apache Knox
Adding a service to Apache Knox
Knox SSO Integration for UIs
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1>Hello World!</h1>"
@app.route("/v1/")
def version():
return "<h1>Hello Stranger -> {0}</h1>".format(request.args.get("op"))
if __name__ == "__main__":
app.run(host="0.0.0.0")