You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reorganize SubjectMapping design to separate architecture from implementation
Eliminate duplication between "Architecture and Components" and "Implementation
Details" sections by clearly separating concerns:
- Architecture section: lightweight overview of WHAT components exist and WHERE
they are located (controller, authentication module, repository structure)
- Implementation Details: comprehensive HOW covering ManagedServiceAccount
creation, lifecycle management, cluster discovery, binding/unbinding,
authentication flow, and token caching
Removed duplicate Cluster Discovery section that appeared in both sections.
This improves readability and follows standard OCM enhancement proposal patterns.
Signed-off-by: zhujian <jiazhu@redhat.com>
@@ -253,30 +253,64 @@ See [API Specification](#api-specification) section below for complete type defi
253
253
254
254
### Architecture and Components
255
255
256
-
#### Component Overview
257
-
258
256
The SubjectMapping feature will be implemented in the **cluster-proxy** repository as it is fundamentally a transparent authentication feature built on top of cluster-proxy's existing proxy infrastructure.
SubjectMapping controller creates ManagedServiceAccount resources with a special annotation to prevent token synchronization to the hub:
311
+
#### ManagedServiceAccount Creation
312
+
313
+
The SubjectMapping controller creates ManagedServiceAccount resources with a special annotation to prevent token synchronization to the hub:
280
314
281
315
```go
282
316
const (
@@ -319,82 +353,114 @@ The managed-serviceaccount addon agent honors this annotation:
319
353
-**Missing annotation or `"secret"`**: Sync token to hub as Secret (default, backward compatible)
320
354
-**`"none"`**: Create ServiceAccount on managed cluster only, don't sync token to hub
321
355
322
-
**Lifecycle Management**:
323
-
324
-
Since SubjectMapping is cluster-scoped and ManagedServiceAccount is namespaced (in cluster namespaces), owner references cannot be used. The controller uses:
325
-
326
-
- **Finalizers** on SubjectMapping to ensure cleanup of all associated ManagedServiceAccounts before deletion
327
-
- **Labels** on ManagedServiceAccounts (see example above) to track which SubjectMapping created them
328
-
- On SubjectMapping deletion, the controller deletes all ManagedServiceAccounts with matching labels across all cluster namespaces
329
-
330
356
This approach:
331
357
332
358
- Requires **no ManagedServiceAccount API changes**
333
359
- Is **fully backward compatible** (existing ManagedServiceAccounts continue working)
334
360
- Eliminates token storage on hub for SubjectMapping use case
335
361
- Allows managed-serviceaccount addon to support both use cases simultaneously
336
-
- Follows OCM patterns (consistent with ManifestWork, Placement, etc.)
337
362
338
-
**Cluster Binding/Unbinding**:
363
+
#### Lifecycle Management
339
364
340
-
The controller continuously reconciles cluster membership via watches on ManagedClusterSetBinding, ManagedCluster labels, and PlacementDecision:
365
+
Since SubjectMapping is cluster-scoped and ManagedServiceAccount is namespaced (in cluster namespaces), owner references cannot be used. The controller uses:
341
366
342
-
- **Cluster Added**: Creates ManagedServiceAccount in new cluster's namespace, updates status
343
-
- **Cluster Removed**: Deletes corresponding ManagedServiceAccount, updates status
344
-
- **Cleanup**: Orphaned resources removed during reconciliation
367
+
-**Finalizers** on SubjectMapping to ensure cleanup of all associated ManagedServiceAccounts before deletion
368
+
-**Labels** on ManagedServiceAccounts (see code example above) to track which SubjectMapping created them
369
+
-On SubjectMapping deletion, the controller deletes all ManagedServiceAccounts with matching labels across all cluster namespaces
345
370
346
-
**2. Authentication Module (Spoke-side)**
371
+
This approach follows OCM patterns (consistent with ManifestWork, Placement, etc.).
347
372
348
-
**Location**: `pkg/proxyagent/authentication/`
373
+
#### Cluster Discovery
349
374
350
-
**Deployment**: Runs in the proxy-agent on each managed cluster
375
+
The controller determines which clusters should receive the mapped service account based on subject type:
351
376
352
-
The proxy-agent component will be enhanced with an authentication module to:
377
+
**For ServiceAccount Subjects:**
353
378
354
-
- Watch SubjectMapping CRs on the hub (via informer) for create/update/delete events
355
-
- On update: Invalidate cached tokens if spec fields affecting token generation changed
356
-
- On delete: Invalidate all cached tokens for the subject
357
-
- Intercept requests from mapped hub subjects
358
-
- Extract subject information from request authentication:
359
-
- **ServiceAccount**: Extract from `system:serviceaccount:<namespace>:<name>` user
360
-
- **User**: Extract from user identity (e.g., `admin@example.com`)
361
-
- Resolve hub subject to managed cluster service account names via SubjectMapping lookup
362
-
- Request tokens from the local TokenRequest API
363
-
- Cache tokens for performance (keyed by hub subject + managed SA name)
364
-
- Automatic invalidation on time expiration and SubjectMapping changes
365
-
- Inject tokens transparently into Authorization headers
366
-
- Forward authenticated requests to the managed cluster API server
367
-
368
-
**Repository Structure**:
379
+
Uses ManagedClusterSetBinding in the ServiceAccount's namespace:
380
+
381
+
1. List all ManagedClusterSetBindings in the ServiceAccount's namespace
382
+
2. Extract ManagedClusterSet names from bindings
383
+
3. List all ManagedClusters with matching `cluster.open-cluster-management.io/clusterset` labels
384
+
4. Create/update ManagedServiceAccount for each discovered cluster
2. Reads PlacementDecisions created by the Placement controller
445
+
3. Extracts the list of selected clusters from PlacementDecisions
446
+
4. Creates/updates ManagedServiceAccount for each selected cluster
447
+
448
+
This approach leverages OCM's existing Placement API capabilities (sophisticated cluster selection, dynamic updates, consistency with Policy and ManifestWork).
449
+
450
+
#### Cluster Binding/Unbinding
451
+
452
+
The controller continuously reconciles cluster membership via watches on ManagedClusterSetBinding, ManagedCluster labels, and PlacementDecision:
453
+
454
+
- **Cluster Added**: Creates ManagedServiceAccount in new cluster's namespace, updates status
455
+
- **Cluster Removed**: Deletes corresponding ManagedServiceAccount, updates status
456
+
- **Cleanup**: Orphaned resources removed during reconciliation
389
457
390
458
#### Authentication Flow
391
459
392
460
1. **Setup Phase:**
393
461
- Admin creates SubjectMapping on the hub
394
462
- For User subjects: Admin also creates a Placement resource (or references existing one)
395
-
- Controller discovers bound clusters:
396
-
- ServiceAccount: via ManagedClusterSetBinding in the ServiceAccount's namespace
397
-
- User: via Placement's PlacementDecisions
463
+
- Controller discovers bound clusters via cluster discovery mechanism
398
464
- ManagedServiceAccount resources are automatically created for each cluster
399
465
400
466
2. **Request Phase:**
@@ -467,90 +533,13 @@ To optimize performance and reduce API server load:
467
533
- **Detection mechanism**: proxy-agent runs informer watching SubjectMapping resources on the hub cluster
0 commit comments