jscheffl commented on code in PR #42049: URL: https://github.com/apache/airflow/pull/42049#discussion_r1774010699
########## airflow/providers/edge/api_endpoints/rpc_api_endpoint.py: ########## @@ -0,0 +1,151 @@ +# 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. + +from __future__ import annotations + +import functools +import json +import logging +from typing import TYPE_CHECKING, Any, Callable + +from flask import Response, request +from itsdangerous import BadSignature +from jwt import ( + ExpiredSignatureError, + ImmatureSignatureError, + InvalidAudienceError, + InvalidIssuedAtError, + InvalidSignatureError, +) + +from airflow.api_connexion.exceptions import PermissionDenied +from airflow.api_internal.endpoints.rpc_api_endpoint import ( + initialize_method_map, + log_and_build_error_response, +) +from airflow.configuration import conf +from airflow.exceptions import AirflowException +from airflow.serialization.serialized_objects import BaseSerialization +from airflow.utils.jwt_signer import JWTSigner +from airflow.utils.session import create_session + +if TYPE_CHECKING: + from airflow.api_connexion.types import APIResponse + +log = logging.getLogger(__name__) + + [email protected]_cache +def _initialize_method_map() -> dict[str, Callable]: + from airflow.providers.edge.models.edge_job import EdgeJob + from airflow.providers.edge.models.edge_logs import EdgeLogs + from airflow.providers.edge.models.edge_worker import EdgeWorker + + internal_api_functions = initialize_method_map().values() + functions: list[Callable] = [ + # TODO Trim down functions really needed by Edge Worker Review Comment: I just removed it because... the intend changed over time. The RPC API is derived from the AIP-44 Internal API which step by step during completion of AIP went into a route of Spaghetti - which is one of the main reasons we will have AIP-72 in future. To clean up the DB chatty calls. The Internal API is/was made to expose to all components which are not internal core the needed endpoints to lock-down the DB. For DAG Parser, Triggerer and Worker. (Webserver and Scheduler still to keep direct DB access). As the Edge Worker RPC API is just for worker, I was not sure whether some API methods are solely needed for DAG Parser or Triggerer. If so then removing some methods might be good to reduce attack vectors. But as all this end-up with a very wide open RPC endpoint, removing a few methods does not make a difference. And from codebase it is almost impossible w/o try&error to figure-out which methods might not be used. But also a lot of security related internals need to be accessible for an external worker anyway (e.g. all connections) so... would leave it as it is for the moment (and just removed TODO). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
