附註:

在單一登入的 OCI 身分識別與存取管理網域上使用 Oracle Analytics Server 部署 App 閘道

簡介

如果您想要使用 Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) 網域在內部部署導入 Oracle Analytics Server 的單一登入 (SSO),建議您為具備 Oracle Analytics Server 應用程式之 IAM 網域的 SSO 設定 App 閘道。此設定可讓使用者使用其「IAM 網域」證明資料並登入 Oracle Analytics Server 應用程式。

主要優點

目標

導入 SSO 以存取 Enterprise Oracle Analytics Server,並瞭解如何部署搭配 IAM 之 SSO 的 App Gateway docker 映像檔。

必要條件

  1. 適用於 IAM 網域的 Oracle Apps Premium SKU。

  2. IAM 網域的管理帳戶。

  3. 執行 App 閘道的機器。

  4. Oracle Analytics Server 應用程式。如果您沒有 Oracle Analytics Server 應用程式,可以使用「市集映像檔」建立應用程式,請參閱在 Oracle Cloud 上部署 Oracle Analytics Server

作業 1:在 IAM 網域中建立企業應用程式

您可以使用兩種方式在 IAM 網域中建立企業應用程式:

方法 1:透過主控台手動建立企業應用程式

  1. 在 IAM 網域中註冊企業應用程式。這代表您的 Oracle Analytics Server 應用程式。提供在 IAM 網域中註冊應用程式的必要詳細資訊,以及編輯 SSO 組態。您可以新增預設資源以允許存取所有資源,否則您可以手動新增每個資源以取得特定資源的存取權。此外,您可以檢查設定 Oracle Identity Cloud Service 和 App 閘道的 SSO ,以瞭解要新增的資源。

    影像 4

    預設資源:/.*

    影像 1

    勾選允許 CORS需要安全 Cookie新增受管理資源的方塊。

    影像 3

  2. 將資源新增至認證原則。新增預設資源以涵蓋所有資源。新增認證原則時,請記得將標頭新增為 iv-user 並將其對應至使用者名稱

    影像 2

方法 2:透過 Python 程式碼建立企業應用程式

  1. 建立機密應用程式並擷取從屬端 ID 和從屬端加密密碼,然後可用來對 OCI IAM 執行 REST API 呼叫以擷取存取記號和後續 API 端點,請參閱 Oracle Identity Cloud Service:第一個 REST API 呼叫

  2. 在您的本機機器上設定配置檔案。config.json 檔案包含用來產生存取權杖的識別網域 URL、從屬端 ID 以及從屬端加密密碼相關資訊。

    {
    "iamurl"         : "https://idcs-###########.identity.oraclecloud.com",
    "client_id"      : "#######################",
    "client_secret"  : "#######################"
    }
    
  3. 產生存取權杖,可用於對 OCI IAM 端點進行進一步的 REST API 呼叫。

    在下面的程式碼片段中,_get_encoded_ 函數會以「從屬端 ID」和「從屬端加密密碼」作為引數,並傳回 base64 編碼的字串。此編碼字串會進一步以引數形式傳送給函數 get_access_token 作為「授權」標頭,以透過執行 POST 要求來取得存取權杖。

    #get base64 encoded
    def get_encoded(self,clid, clsecret):
        encoded = clid + ":" + clsecret
        baseencoded = base64.urlsafe_b64encode(encoded.encode('UTF-8')).decode('ascii')
        return baseencoded
    
    #get access token
    def get_access_token(self,url, header):
        para = "grant_type=client_credentials&scope=urn:opc:idm:__myscopes__"
        response = requests.post(url, headers=header, data=para, verify=False)
        jsonresp = json.loads(response.content)
        access_token = jsonresp.get('access_token')
        return access_token
    
    #print access token
    def printaccesstoken(self):
        obj = IAM()
        encodedtoken = obj.get_encoded(clientID, clientSecret)
        extra = "/oauth2/v1/token"
        headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
                'Authorization': 'Basic %s' % encodedtoken, 'Accept': '*/*'}
        accesstoken = obj.get_access_token(idcsURL + extra, headers)
        return accesstoken
    
  4. 使用下方的 Python 程式碼片段在 IAM 網域中建立企業應用程式。

    def createapplication(self):
        global clID
        global appID
        global resID1
        obj = IAM()
        obj.searchapps()
        accesstoken = obj.printaccesstoken()
        extra = "/admin/v1/Apps"
        headers = {'Accept': '*/*', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accesstoken}
        para = json.dumps({
        "schemas": [
            "urn:ietf:params:scim:schemas:oracle:idcs:App",
            "urn:ietf:params:scim:schemas:oracle:idcs:extension:samlServiceProvider:App",
            "urn:ietf:params:scim:schemas:oracle:idcs:extension:requestable:App",
            "urn:ietf:params:scim:schemas:oracle:idcs:extension:managedapp:App",
            "urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App"
        ],
        "displayName": "OAS Enterprise App",
        "description": "New Enterprise Application for OAS",
        "landingPageURL": "http://150.xx.xx.xx:9502/analytics",
        "basedOnTemplate": {
            "value": "CustomEnterpriseAppTemplateId"
        },
        "isSamlServiceProvider": False,
        "isOAuthResource": False,
        "isOAuthClient": False,
        "showInMyApps": False,
        "isWebTierPolicy": False,
        "active": True,
        "isEnterpriseApp": True,
        "urn:ietf:params:scim:schemas:oracle:idcs:extension:requestable:App": {
        "requestable": False
        },
        "urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App": {
        "webTierPolicyAZControl": "local"
        }
        })
        resp = requests.post(idcsURL + extra, headers=headers, verify=False, data=para)
        jsonresp = json.loads(resp.content)
        clID = jsonresp.get("name")
        #clSecret = jsonresp.get("clientSecret")
        appID = jsonresp.get("id")
        print("OAS Enterprise Application created with Client ID")
        print(clID)
        print("App ID of the created OAS Enterprise Application is :")
        print(appID)
    
        extra1 = "/admin/v1/AppResources"
        extra5 = "/admin/v1/Apps/"+appID
        headers1 = {'Accept': '*/*', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + accesstoken}
    
        data= pd.read_csv("AppResourse.csv",delimiter=',')
        x=0  # For Reading the Data from the CSV file
        i=1  # For Providing the sequence vaule to the Web Policy
    
    ### This part of the code reads the data from CSV file adds the AppResource to the Enterprise application and also adds the Web Policy for all the added resources###
    
        for line in data.iterrows() :
            AppRsUrl=data.AppResourseURL[x] ## Take Application Resource URL as input from CSV file at xth Location
            ##print(AppRsUrl)
            metD=data.accessMode[x] ## Take Access method for Application Resource URL as input from CSV file at xth Location
            ResName=data.ResourceName[x] ## Take Application Resource Name as input from CSV file at xth Location
            para1 = json.dumps({
            "schemas": [
            "urn:ietf:params:scim:schemas:oracle:idcs:AppResource"
            ],
            "name": ResName,
            "resourceURL": AppRsUrl,
            "isRegex": True,
            "description": "OAS App Resourse",
            "app": {
                "value": appID
                }
            })
            resp1 = requests.request("POST",idcsURL + extra1, headers=headers1, verify=False, data=para1)
            ##print(resp1)
            jsonresp1 = json.loads(resp1.content)
            ##print(jsonresp1)
            resID1= jsonresp1.get("id")
            print("Resourse Added to the OAS Enterprise Application with ID")
            print(resID1)
    
            para3 = json.dumps({
            "schemas":[
            "urn:ietf:params:scim:api:messages:2.0:PatchOp"
            ],
            "Operations":[
            {
            "op":"add",
            "path":"urn:ietf:params:scim:schemas:oracle:idcs:extension:enterpriseApp:App:appResources",
            "value":[
                {
                "value":resID1
                }
            ]}]})
    
            resp3 = requests.request("PATCH",idcsURL + extra5, headers=headers1, verify=False, data=para3)
            # print(resp3)
            # jsonresp3 = json.loads(resp3.content)
            # print(jsonresp3)
    
    ### Based on the Access Mode the Web Policy will be generated###
    
            if metD=="oauth":
                jsonBody= "{\"filter\":\""+AppRsUrl+"\",\"headers\":[{\"iv-user\":\"$subject.user.userName\"}],\"comment\":\"abc\",\"resourceRefId\": \""+resID1+"\",\"resourceRefName\":\""+ResName+"\",\"type\":\"regex\",\"sequence\":\""+str(i)+"\",\"method\":\"oauth\"}"+","
            else:
                jsonBody= "{\"filter\":\""+AppRsUrl+"\",\"comment\":\"abc\",\"resourceRefId\": \""+resID1+"\",\"resourceRefName\":\""+ResName+"\",\"type\":\"regex\",\"sequence\":\""+str(i)+"\",\"method\":\"public\"}"+","
            ##print(jsonBody)
            x=x+1
            i=i+1
    
            with open('data.json', 'a') as f:
                json.dump(jsonBody, f)
    
    ## construct the payload for webtier and send it as a Json Body to the REST call###
    
        with open('data.json', 'r') as file: ## Temp json file to hold the payload before getting formated
            data = file.read()
            data1=data.replace('""','')
            ##print(data1)
        with open('formatedData.json', 'a') as file1: ## Actual json file to hoad the payload for the REST call to PATCH WebPolicy
            file1.writelines('{ \n')
            file1.writelines('"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],\n')
            file1.writelines('"Operations": [\n')
            file1.writelines('{"op": "add",\n')
            file1.writelines('"path": "urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App:webTierPolicyJson",\n')
            file1.writelines(R'"value":"{\"cloudgatePolicy\":{\"version\":\"2.6\",\"requireSecureCookies\":true,\"allowCors\":true,\"disableAuthorize\":true,\"webtierPolicy\":[{\"policyName\":\"default\",\"comment\":\"Webtier policy\",\"resourceFilters\":[')
            data2=re.sub(r'.', '', data1, count = 1)
            data3=data2.rstrip(data2[-1])
            data4=data3.rstrip(data3[-1])
            file1.write(data4)
            file1.write(']}]}}"}]}')
            os.remove("data.json")
    
    ### REST API Call to PATCH the Web Policy to the created Enterprise Application###
    
        extra2 = "/admin/v1/Apps/"+appID
        headers2 = {'Accept': '*/*', 'Content-Type': 'application/scim+json', 'Authorization': 'Bearer ' + accesstoken}
        param = {'attributes': "urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App:webTierPolicyJson,urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App:webTierPolicyAZControl,urn:ietf:params:scim:schemas:oracle:idcs:extension:webTierPolicy:App:resourceRef"}
        webPolicy = json.load(open('formatedData.json'))
        payload = json.dumps(webPolicy)
        resp7 = requests.request("PATCH",idcsURL + extra2, headers=headers2, verify=False, data=payload, params=param)
        jsonresp7 = json.loads(resp7.content)
        ##print(resp7)
        ##print(jsonresp7)
        print("The OAS Enterprise Application has been PATCH with the WebPolicy for all the added Resources")
        os.remove("formatedData.json")
    
    
  5. 您將需要一個包含要使用上述程式碼片段建立之所有資源的 csv 檔案。以下是資源 AppResources.csv 的連結。

注意:請確定您的系統已安裝 Python 3.x,且已安裝 urllib3requestspandas Python 套裝軟體,同時使用上述程式碼片段。此外,上述程式碼片段僅供參考之用,您也可以建立自己的邏輯來達到相同的目的。

作業 2:在 IAM 網域中建立 App 閘道

  1. 安全頁籤下的 IAM 網域上建立應用程式閘道。提供必要的詳細資訊以完成組態。註冊 App 閘道所需的詳細資訊為 App 閘道的名稱主機,也就是您要部署 App 閘道映像檔之機器的公用 IP 。選取啟用 SSL 核取方塊,然後在其他特性區段中新增要用於 App 閘道的憑證,格式如下。新增 App 閘道上憑證的正確路徑。

    ssl_certificate /usr/local/nginx/conf/server.crt;
    ssl_certificate_key /usr/local/nginx/conf/server.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    

    影像 7

    注意:您可以在上述步驟使用公用 SSL 憑證,但如果您沒有任何公用憑證,則也可以使用自行簽署的憑證。您可以使用下列 openSSL 指令產生自行簽署的憑證。

    openssl req -x509 -newkey rsa:4096 -keyout /home/opc/certs/key.pem -out /home/opc/certs/cert.pem -sha256 -days 3650 -nodes -subj "/C=US/ST=Florida/L=Miami/O=Oracle/OU=Cloud/CN=oracle"
    
  2. 在 App 閘道上新增已註冊為應用程式的企業應用程式。選擇您在應用程式底下建立的企業應用程式,選取選取主機底下的主機。將資源前置碼提供為 / ,在原始伺服器底下提供 Oracle Analytics Server 的 URL儲存變更。

    影像 8

作業 3:部署 App 閘道 Docker 映像檔

  1. 下載 App 閘道碼頭映像檔。在 IAM 網域的左側功能表中,按一下設定值,然後按一下下載。下載 App Gateway Docker Image for Identity Cloud ServiceApp Gateway Wallet 工具。將 App 閘道 Docker 映像檔和公事包工具保留在個別目錄中。例如:/home/opc/appgateway 代表 App 閘道,/home/opc/cwallet 代表公事包工具。

  2. 建立一個公事包檔案,此公事包包含在 IAM 網域中建立的 App 閘道從屬端 ID 和從屬端加密密碼。請使用下列步驟建立公事包檔案。

    env LD_LIBRARY_PATH=./lib ./cgwallettool --create -i **ClientID of AppGateway in IAM Domain**.
    
    

    注意:若執行上述動作,將會要求應用程式閘道的從屬端加密密碼。這些步驟將會建立 App 閘道的 cwallet.sso 檔案。

    影像 9

  3. 使用下列命令在機器上安裝 App 閘道的 Docker。

    sudo yum-config-manager --disable ol7_UEKR3 ol7_UEKR4
    sudo yum-config-manager --enable ol7_UEKR5
    sudo yum-config-manager --enable ol7_addons
    sudo yum install docker-engine docker-cli -y
    sudo systemctl enable --now docker
    sudo systemctl status docker
    sudo docker info
    sudo usermod -a -G docker $USER
    

    注意:我們使用 Oracle Linux 7 設定 App 閘道的碼頭映像檔。

  4. 您可以使用來自任何信任公用憑證授權機構的憑證,或使用 openSSL 建立自行簽署的憑證。自我簽署憑證範例如下:

    openssl req -x509 -newkey rsa:4096 -keyout /home/opc/certs/key.pem -out /home/opc/certs/cert.pem -sha256 -days 3650 -nodes -subj "/C=US/ST=Florida/L=Miami/O=Oracle/OU=Cloud/CN=oracle"
    
  5. 由於 docker 映像檔的格式為 tar.gz,因此我們需要擷取映像檔,以下列步驟建立 docker 容器。使用下列命令將 tar.gz 檔案載入本機 Docker 登錄:

    $ docker load -i **filename.tar.gz**
    

作業 4:建立 App 閘道 ENV 檔案

  1. 若要執行 App 閘道 Docker 容器,必須在 appgateway-env 檔案中設定下列環境變數。CG_APP_TENANT=<tenant name> IDCS_INSTANCE_URL=<idcs instance url>.存取 Identity Cloud Service 執行處理所需的 URL。NGINX_DNS_RESOLVER=<resolver ip>.

    注意:進行 IAM 網域 URL 和伺服器 IP 的 nslookup,將會是您需要的值。

  2. 使用下列命令執行 Docker。

    sudo docker run -it -p 4443:4443 --name appgateway --env-file /home/opc/AppgwDocker/appgateway-env --env HOST_MACHINE=`hostname -f` --volume /home/opc/cwallet.sso:/usr/local/nginx/conf/cwallet.sso --volume /home/opc/server.key:/usr/local/nginx/conf/server.key --volume /home/opc/server.crt:/usr/local/nginx/conf/server.crt --net=host idcs/idcs-appgateway:23.2.92-2301160723
    
  3. 使用下列命令重新啟動 docker:

    docker stop conatiner_ID
    docker start conatiner_ID
    

作業 5:在 Oracle Analytics Server WebLogic 伺服器上建立識別宣告器

  1. 以管理員身分登入 WebLogic 伺服器管理主控台。

  2. 瀏覽至 myrealm 以及提供者。以提供者身分建立 OAMIdentityAsserter

    影像 10

  3. 建立「提供者」之後,請編輯相同項目,將控制旗標變更為必要,然後選擇作用中類型作為一般使用者

    影像 11

  4. SSOHeader 名稱底下的提供者特定特性中設定 iv-user ,然後按一下儲存

    影像 12

  5. 重新排序提供者清單,並將新建立的提供者保留在最上層。

  6. 使用命令檔重新啟動 WebLogic 伺服器,如下所示。

    sudo su oracle
    cd /u01/data/domains/bi/bitools/bin
    ./stop.sh
    ./start.sh
    
  7. 一旦伺服器再次啟動,您就可以測試 SSO。

作業 6:測試 SSO

存取 App 閘道 URL https://AppGateway.example.com:4443/analytics 來測試 SSO,它會將使用者重新導向至 OCI IAM 識別網域以進行認證,成功認證之後,使用者將可根據其角色存取 Oracle Analytics Server。

注意:AppGateway.example.com 可在此處參考,請根據您的環境使用正確的 URL,並確定您具有正確的 DNS 路由。

確認

其他學習資源

探索 docs.oracle.com/learn 的其他實驗室,或者存取更多 Oracle Learning YouTube 頻道上的免費學習內容。此外,請瀏覽 education.oracle.com/learning-explorer 以成為 Oracle Learning 檔案總管。

如需產品文件,請造訪 Oracle Help Center