|
| 1 | +# Groups and Namespaces Based Authorization Implementation Summary |
| 2 | + |
| 3 | +## Overview |
| 4 | +This document summarizes the implementation of groups and namespaces extraction support in Feast for user authentication in Pull Request https://github.com/feast-dev/feast/pull/5619. |
| 5 | + |
| 6 | +## Changes Made |
| 7 | + |
| 8 | +### 1. Enhanced User Model (`sdk/python/feast/permissions/user.py`) |
| 9 | +- **Extended User class** to include `groups` and `namespaces` attributes |
| 10 | +- **Added methods**: |
| 11 | + - `has_matching_group()`: Check if user has required groups |
| 12 | + - `has_matching_namespace()`: Check if user has required namespaces |
| 13 | +- **Maintained backward compatibility** with existing role-based functionality |
| 14 | + |
| 15 | +### 2. New Policy Types (`sdk/python/feast/permissions/policy.py`) |
| 16 | +- **GroupBasedPolicy**: Grants access based on user group membership |
| 17 | +- **NamespaceBasedPolicy**: Grants access based on user namespace association |
| 18 | +- **CombinedGroupNamespacePolicy**: Requires both group OR namespace match |
| 19 | +- **Updated Policy.from_proto()** to handle new policy types |
| 20 | +- **Maintained backward compatibility** with existing RoleBasedPolicy |
| 21 | + |
| 22 | +### 3. Protobuf Definitions (`protos/feast/core/Policy.proto`) |
| 23 | +- **Added GroupBasedPolicy message** with groups field |
| 24 | +- **Added NamespaceBasedPolicy message** with namespaces field |
| 25 | +- **Extended Policy message** to include new policy types in oneof |
| 26 | +- **[Love] Regenerated Python protobuf files** using `make compile-protos-python` |
| 27 | + |
| 28 | +### 4. Token Access Review Integration (`sdk/python/feast/permissions/auth/kubernetes_token_parser.py`) |
| 29 | +- **Added AuthenticationV1Api client** for Token Access Review |
| 30 | +- **Implemented `_extract_groups_and_namespaces_from_token()`**: |
| 31 | + - Uses Kubernetes Token Access Review API |
| 32 | + - Extracts groups and namespaces from token response |
| 33 | + - Handles both service accounts and regular users |
| 34 | +- **Updated `user_details_from_access_token()`** to include groups and namespaces |
| 35 | + |
| 36 | +### 5. Client SDK Updates (`sdk/python/feast/permissions/client/kubernetes_auth_client_manager.py`) |
| 37 | +- **Extended KubernetesAuthConfig** to support user tokens |
| 38 | +- **Updated `get_token()` method** to check for user_token in config |
| 39 | +- **Maintained backward compatibility** with service account tokens |
| 40 | + |
| 41 | +### 6. Configuration Model (`sdk/python/feast/permissions/auth_model.py`) |
| 42 | +- **Added user_token field** to KubernetesAuthConfig for external users |
| 43 | +- **Maintained backward compatibility** with existing configurations |
| 44 | + |
| 45 | +### 7. Comprehensive Tests (`sdk/python/tests/permissions/test_groups_namespaces_auth.py`) |
| 46 | +- **15 test cases** covering all new functionality |
| 47 | +- **Tests for**: |
| 48 | + - User creation with groups/namespaces |
| 49 | + - Group matching functionality |
| 50 | + - Namespace matching functionality |
| 51 | + - All new policy types |
| 52 | + - Backward compatibility |
| 53 | + |
| 54 | +### 8. Documentation (`docs/getting-started/components/groups_namespaces_auth.md`) |
| 55 | +- **Usage examples** and configuration guides |
| 56 | +- **Security considerations** and best practices |
| 57 | +- **Troubleshooting guide** and migration instructions |
| 58 | + |
| 59 | + |
| 60 | +## Key Features Implemented |
| 61 | + |
| 62 | +### ✅ Token Access Review Integration |
| 63 | +- Uses Kubernetes Token Access Review API to extract user details |
| 64 | +- Handles both service accounts and external users |
| 65 | + |
| 66 | +### ✅ Groups and Namespaces Extraction |
| 67 | +- Extracts groups and namespaces from token response |
| 68 | +- Supports both service account and regular user tokens |
| 69 | + |
| 70 | +### ✅ New Policy Types |
| 71 | +- **GroupBasedPolicy**: Access based on group membership |
| 72 | +- **NamespaceBasedPolicy**: Access based on namespace association |
| 73 | +- **CombinedGroupNamespacePolicy**: Requires either group OR namespace |
| 74 | + |
| 75 | +### ✅ Client SDK Support |
| 76 | +- Extended to support user tokens for external users |
| 77 | +- Maintains backward compatibility with service account tokens |
| 78 | +- New parameter in KubernetesAuthConfig for user tokens |
| 79 | + |
| 80 | + |
| 81 | +## Usage Examples |
| 82 | + |
| 83 | +### Basic Group-Based Permission |
| 84 | +```python |
| 85 | +from feast.permissions.policy import GroupBasedPolicy |
| 86 | +from feast.permissions.permission import Permission |
| 87 | + |
| 88 | +policy = GroupBasedPolicy(groups=["data-team", "ml-engineers"]) |
| 89 | +permission = Permission( |
| 90 | + name="data_team_access", |
| 91 | + types=ALL_RESOURCE_TYPES, |
| 92 | + policy=policy, |
| 93 | + actions=[AuthzedAction.DESCRIBE] + READ |
| 94 | +) |
| 95 | +``` |
| 96 | + |
| 97 | +### Basic Namespace-Based Permission |
| 98 | +```python |
| 99 | +from feast.permissions.policy import NamespaceBasedPolicy |
| 100 | +from feast.permissions.permission import Permission |
| 101 | + |
| 102 | +policy = NamespaceBasedPolicy(namespaces=["de-dsp", "ml-dsp"]) |
| 103 | +permission = Permission( |
| 104 | + name="data_team_access", |
| 105 | + types=ALL_RESOURCE_TYPES, |
| 106 | + policy=policy, |
| 107 | + actions=[AuthzedAction.DESCRIBE] + READ |
| 108 | +) |
| 109 | +``` |
| 110 | + |
| 111 | +### Combined Group + Namespace Permission |
| 112 | +```python |
| 113 | +from feast.permissions.policy import CombinedGroupNamespacePolicy |
| 114 | + |
| 115 | +policy = CombinedGroupNamespacePolicy( |
| 116 | + groups=["data-team"], |
| 117 | + namespaces=["production"] |
| 118 | +) |
| 119 | +``` |
| 120 | + |
| 121 | +### Client Configuration with User Token |
| 122 | +```python |
| 123 | +from feast.permissions.auth_model import KubernetesAuthConfig |
| 124 | + |
| 125 | +auth_config = KubernetesAuthConfig( |
| 126 | + type="kubernetes", |
| 127 | + user_token="your-kubernetes-user-token" # For external users |
| 128 | +) |
| 129 | +``` |
0 commit comments