Skip to content

Commit 6ad28ad

Browse files
committed
add clarifications and link to google doc for targetRef
1 parent e441b6d commit 6ad28ad

File tree

1 file changed

+114
-20
lines changed

1 file changed

+114
-20
lines changed

geps/gep-3779/index.md

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ However, targeting a `Service` introduces several challenges;
308308

309309
##### Loss Of Service Context
310310

311-
I we go with option 1, apply authorization policy to all traffic addressed to a service;
311+
If we go with option 1, apply authorization policy to all traffic addressed to a service;
312312
This option is very tricky to implement for sidecar-based meshes where the destination sidecar has no knowledge of which Service the request came through.
313313
Here is the very high-level tarffic flow for sidecar-based meshes:
314314

@@ -350,8 +350,7 @@ The UX becomes very confusing. Are we going to enforce only if the traffic arriv
350350
351351
The UX gets weird becuase even though you target a service, you essentially get a **workload** policy, thats enforced regardless.
352352
353-
354-
> Note: with Service as a targetRef, of course we are going to need a Service in order to enforce Authorization -- meaning pods/jobs without a serivce are completely out of scope.
353+
> Note: with Service as a targetRef, of course we are going to need a Service in order to enforce Authorization -- meaning pods/jobs without a Serivce are completely out of scope.
355354
356355
#### **Option 2: Targeting xRoutes**
357356
@@ -475,6 +474,79 @@ TODO: complete gwctl commands
475474
476475
Without dedicated tooling, the `LabelSelector` approach could significantly degrade the user experience and observability.
477476
477+
#### Recommended Option - Hybrid TargetRef and VAP
478+
479+
Adding only the recommendation below, please see [https://docs.google.com/document/d/1CeagBnHDPbzpYAxBmtJqTshxAW8l-aRPwvwgAGbnv2I/edit?tab=t.0](https://docs.google.com/document/d/1CeagBnHDPbzpYAxBmtJqTshxAW8l-aRPwvwgAGbnv2I/edit?tab=t.0) for a comprehensive comparison for design options for TargetRef.
480+
481+
Create one unified authorization policy API with implementation-specific validation using Validating Admission Policies (VAP). Additionally introducing a new `enforcementLevel` enum to simplify validation and enable the user to clarify intent
482+
483+
```
484+
# Network-scoped policy (L4 enforcement points)
485+
kind: AuthorizationPolicy
486+
metadata:
487+
name: network-authz
488+
spec:
489+
enforcementLevel: "network" # Enforced at L4 proxies
490+
targetRef:
491+
kind: Pod
492+
selector: {}
493+
rules:
494+
- authorizationSource:
495+
serviceAccount: ["default/productpage"]
496+
tcpAttributes:
497+
ports: [9080]
498+
499+
# Application-scoped policy (L7-only enforcement points and sidecars)
500+
kind: AuthorizationPolicy
501+
metadata:
502+
name: app-authz
503+
spec:
504+
enforcementLevel: "application" # Enforced at L7 proxies
505+
targetRef: # Service for Ambient implementations, label-selector for sidecar implementations.
506+
rules:
507+
- authorizationSource:
508+
serviceAccount: ["default/productpage"]
509+
tcpAttributes:
510+
ports: [9080]
511+
httpAttributes:
512+
paths: ["/api/*"]
513+
methods: ["GET", "POST"]
514+
515+
516+
```
517+
518+
### Mesh Implementation Behavior
519+
520+
Sidecar Meshes
521+
522+
* **Network Level**: Sidecar enforces policy but only uses L4 attributes
523+
* **Application Level**: Sidecar enforces policy with full L4+L7 capabilities
524+
525+
Ambient Meshes
526+
527+
* **Network Level**: Node-L4-proxy enforces policy using labelSelector targeting
528+
* **Application Level**: Waypoint proxy enforces policy using service targetRef targeting
529+
530+
**VAP Validation**:
531+
532+
* **Sidecar mesh**: Ensures application-level policies don't use targetRef: Service (since sidecars use labelSelector)
533+
* **Ambient**: Ensures application-level policies don't use label-selectors.
534+
* **Both sidecar and ambient:** ensures network level policies **do** use label selectors
535+
536+
Advantages
537+
538+
* **Clear Intent**: Users explicitly state where they want enforcement
539+
* **Flexible Targeting**: Different targetRef types for different enforcement points
540+
* **Migration Path**: Users can start with network-level and upgrade to application-level easily
541+
* **Implementation Alignment**: supporting different meshes architectures
542+
* **Single API**: No duplication of schemas or concepts
543+
* **Validation Clarity**: Clear rules about what's allowed at each level
544+
545+
Disadvantages
546+
547+
* **Complexity**: Users must understand enforcement levels
548+
* **VAP Dependency**: Requires validation rules
549+
478550
### API Design
479551
480552
```go
@@ -511,33 +583,55 @@ type AuthorizationPolicySpec struct {
511583
// +kubebuilder:validation:Required
512584
Action AuthorizationPolicyAction `json:"action"`
513585
514-
// TCPRules defines the list of matching criteria. A request is considered to
515-
// match the policy if it matches any of the rules.
586+
// Rules defines the list of authorization rules.
587+
// A request matches the policy if it matches any of these rules.
516588
// +optional
517-
TCPRules []AuthorizationTCPRule `json:"tcpRules,omitempty"`
589+
Rules []AuthorizationRule `json:"rules,omitempty"`
518590
}
519591
520-
// AuthorizationTCPRule defines a set of criteria for matching a TCP request.
521-
// A request must match all specified criteria.
522-
type AuthorizationTCPRule struct {
523-
// Sources specifies a list of identities that are matched by this rule.
524-
// If this field is empty, this rule matches all sources.
525-
// A request matches if its identity is present in this list.
592+
// AuthorizationRule defines a single authorization rule.
593+
// A request matches the rule if it matches ALL fields specified.
594+
type AuthorizationRule struct {
595+
// AuthorizationSource specifies who is making the request.
596+
// If omitted, matches any source.
526597
// +optional
527-
Sources []AuthorizationSource `json:"sources,omitempty"`
598+
AuthorizationSource *AuthorizationSource `json:"authorizationSource,omitempty"`
528599
529-
// Attributes specifies a list of properties that are matched by this rule.
530-
// If this field is empty, this rule matches all attributes.
531-
// A request matches if its attributes are present in this list.
532-
//
600+
// TCPAttributes specifies TCP-level matching criteria.
601+
// If omitted, matches any TCP traffic.
533602
// +optional
534-
Attributes []AuthorizationTCPAttributes `json:"attributes,omitempty"`
603+
TCPAttributes *AuthorizationTCPAttributes `json:"tcpAttributes,omitempty"`
604+
605+
606+
// FOR FUTURE ENHANCEMENT!
607+
608+
// HTTPAttributes specifies HTTP-level matching criteria.
609+
// If omitted, matches any HTTP traffic.
610+
// +optional
611+
HTTPAttributes *AuthorizationHTTPAttributes `json:"httpAttributes,omitempty"`
535612
}
536613
537614
615+
538616
// AuthorizationSource specifies the source of a request.
539-
// Only one of its fields may be set.
540-
// +kubebuilder:validation:XValidation:rule="(size(self.identities) > 0 ? 1 : 0) + (size(self.serviceAccounts) > 0 ? 1 : 0) + (size(self.namespaces) > 0 ? 1 : 0) == 1",message="Exactly one of identities, serviceAccounts, or namespaces must be specified."
617+
//
618+
// At least one field may be set. If multiple fields are set,
619+
// a request matches this AuthorizationSource if it matches
620+
// **any** of the specified criteria (logical OR across fields).
621+
//
622+
// For example, if both `Identities` and `Namespaces` are provided,
623+
// the rule matches a request if either:
624+
// - the request's identity is in `Identities`
625+
// - OR the request originates from one of the `Namespaces`.
626+
//
627+
// Each list within the fields (e.g. `Identities`) is itself an OR list.
628+
//
629+
// If this struct is omitted in a rule, it matches any source.
630+
//
631+
// NOTE: In the future, if there’s a need to express more complex
632+
// logical conditions (e.g. requiring a request to match multiple
633+
// criteria simultaneously—logical AND), we may evolve this API
634+
// to support richer match expressions or logical operators.
541635
type AuthorizationSource struct {
542636
543637
// Identities specifies a list of identities that are matched by this rule.

0 commit comments

Comments
 (0)