将身份验证添加到oozie工作流通知

ttcibm8c  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(509)

Apache·奥齐 oozie.wf.workflow.notification.url 属性将作业状态更新通知自定义终结点。

<property>
    <name>oozie.wf.workflow.notification.url</name>
    <value>http://SERVER:8080/endpoint/oozieUpdate?jobId=$jobId%26status=$status</value>
</property>

我有一个用例,端点必须对传入的请求进行身份验证,但我找不到一个解决方案,该解决方案允许我配置oozie,以便它将身份验证头发送到此通知url(例如basic auth)。有办法吗?

qncylg1j

qncylg1j1#

我怀疑你能用 oozie.wf.workflow.notification.url 在目前的状态下。我检查了oozie的源代码发现:
org.apache.oozie.client.oozieclient(在常量中读取的属性):

public static final String WORKFLOW_NOTIFICATION_URL = "oozie.wf.workflow.notification.url";

org.apache.oozie.command.wf.workflownotificationxcommand(常量用于形成proxyconf变量):

public WorkflowNotificationXCommand(WorkflowJobBean workflow) {
    super("job.notification", "job.notification", 0);
    ParamChecker.notNull(workflow, "workflow");
    jobId = workflow.getId();
    url = workflow.getWorkflowInstance().getConf().get(OozieClient.WORKFLOW_NOTIFICATION_URL);
    if (url != null) {
        url = url.replaceAll(JOB_ID_PATTERN, workflow.getId());
        url = url.replaceAll(STATUS_PATTERN, workflow.getStatus().toString());
        proxyConf = workflow.getWorkflowInstance().getConf()
                .get(OozieClient.WORKFLOW_NOTIFICATION_PROXY, ConfigurationService.get(NOTIFICATION_PROXY_KEY));
        LOG.debug("Proxy :" + proxyConf);
    }
}

org.apache.oozie.command.notificationxcommand(在workflownotificationxcommand的超类中使用proxyconf变量的http调用本身):

protected void sendNotification() {
    if (url != null) {
        Proxy proxy = getProxy(proxyConf);
        try {
            URL url = new URL(this.url);
            HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(proxy);
            urlConn.setConnectTimeout(getTimeOut());
            urlConn.setReadTimeout(getTimeOut());
            if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                handleRetry();
            }
        }
        catch (IOException ex) {
            handleRetry();
        }
    }
    else {
        LOG.info("No Notification URL is defined. Therefore nothing to notify for job " + jobId);

    }

}

如您所见,这里没有使用 httpURLConnection.setRequestProperty(,) .
不过,您可以使用自定义java操作进行变通,也可以使用任何您喜欢的头从中进行http调用。

snz8szmq

snz8szmq2#

作为解决方法,我为通知url创建了一个替换变量。

<property>
    <name>oozie.wf.workflow.notification.url</name>
    <value>_NOTIFICATION_URL_</value>
</property>

然后每次运行作业时,我都会在url中包含一个不同的密钥。

confXml.replaceAll("_NOTIFICATION_URL_", server + "/" + getRandomSecret());

本例中的信任锚定是https。当我收到来自作业的通知时,我可以通过比较密钥来确保它不是来自攻击者。

相关问题