vincbeck commented on code in PR #33213:
URL: https://github.com/apache/airflow/pull/33213#discussion_r1307665731


##########
airflow/auth/managers/models/resource_details.py:
##########
@@ -0,0 +1,31 @@
+#
+# 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
+
+from dataclasses import dataclass
+
+
+@dataclass
+class ResourceDetails:
+    """
+    Represents the details of a resource.
+
+    All fields must be optional. These details can be used in authorization 
decision.
+    """
+
+    id: str | None = None

Review Comment:
   I have a second thought...
   
   > How many resource types we are going to have ... Can we enumerate them now?
   
   My understanding is the number of resource type will not change, hence from 
[permissions.py](https://github.com/apache/airflow/blob/main/airflow/security/permissions.py#L19),
 there are 40 resources types and as such, we should have 40 methods? This 
looks really massive.
   
   Also, regarding FAB auth manager, even though we consider this auth manager 
as an exception, all `is_authorized_` methods are going to basically call one 
private `_is_authorized` method because this is the same implementation.
   
   That makes me wonder whether other auth manager wont be in the same 
situation. We can easily imagine one auth manager with this pseudo code as 
implementation of `is_authorized`:
   
   ```
   def is_authorized(
           self,
           action: ResourceMethod,
           resource_type: ResourceType,
           resource_details: ResourceDetails | None = None,
           user: BaseUser | None = None,
       ) -> bool:
       # Fetch the backend client of the service used tu make authorization 
decision
       client = ....
   
       return client.is_authorized(
           action=action.value,
           resource_type=resource_type.value
           extra=resource_details.to_dict(),
       )
   ```
   
   This is obviously some simplified code and some logic is probably missing 
but the idea is to basically pass the information to the underlying service 
which will make the authorization decision.



-- 
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]

Reply via email to