Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1alpha/networkinterfaceclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const (
NetworkInterfaceClaimReady = "Ready"
)

// NetworkInterfaceClaimDetachFinalizer holds a physical claim until the
// realizer has taken the claim's network off its switch port. Only the
// operator adds it, and only the realizer, or the operator for a claim no
// port ever carried, removes it.
const NetworkInterfaceClaimDetachFinalizer = "networking.datumapis.com/physical-detach"

const (
// NetworkInterfaceClaimReasonNetworkNotAvailableInLocation means the network
// exists and has not reached this location yet, which is a different answer
Expand Down
1 change: 1 addition & 0 deletions config/cell/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ resources:
components:
- ../rbac_deployment
- ../components/cell-controllers
- ../components/physical-attachment-admission
56 changes: 56 additions & 0 deletions config/components/physical-attachment-admission/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Physical attachment admission

Limits who may write a physical `NetworkInterfaceClaim` or
`NetworkInterface` in a cell, meaning one whose attachment mode is
`Physical`. The schemas already refuse an attachment point, purpose or
isolation on any other mode, and keep the mode from changing.

- Only a listed provider may create or change a physical claim.
- A listed realizer or break-glass operator may update a physical claim,
such as to remove its finalizers, but not create one. The claim's schema
already keeps its spec from changing.
- Only the realizer, or a break-glass operator, may remove the
`networking.datumapis.com/physical-detach` finalizer.
- Only the operator may add that finalizer, or write a physical interface.
- A claim with `purpose: Boot` is created only in a namespace whose project,
decoded from its `meta.datumapis.com/upstream-cluster-name` label, is a
listed provider project. Later updates are not checked again, so changing
the list never strands a boot claim that already exists.

The lists are the first five variables of the policy, each a CEL list of
strings, in this order:

| Index | Variable | Holds |
|---|---|---|
| 0 | `operators` | Usernames the operator authenticates as. Exempt from every rule. |
| 1 | `providers` | Usernames allowed to write physical claims. |
| 2 | `realizers` | Usernames of the physical realizer. |
| 3 | `breakGlassGroups` | Groups allowed to remove a stuck detach finalizer. |
| 4 | `providerProjects` | Project names whose namespaces may hold boot claims. |

The defaults name the cell's own service account as the operator and leave
every other list empty, so every physical claim is refused until a
deployment fills them in. A deployment replaces a list with a JSON patch:

```yaml
- op: replace
path: /spec/variables/1/expression
value: "['system:serviceaccount:example-provider:provider']"
```

The policy only matches physical claims and interfaces, and writes that add
or remove the detach finalizer, so a wrong list can only affect physical
attachment. Every other claim and interface is admitted as before. Within
physical attachment, a wrong `realizers` or `breakGlassGroups` list leaves
deleted claims waiting on their detach finalizer, with their addresses held.

Patches name the lists by index, so the order of the first five variables is
part of this component's contract. The operator's default entry is the cell's
own service account, and a test renders `config/cell` to keep the two in
step. A deployment that renames that service account must replace variable 0
too.

An operator in a break-glass group removes a detach finalizer only after
confirming on the switch that the port no longer carries the claim's
network. Anyone allowed to impersonate a listed username or group holds
the same power.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

resources:
- physical-attachment-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: physical-attachment-writers
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- networking.datumapis.com
apiVersions:
- "*"
operations:
- CREATE
- UPDATE
resources:
- networkinterfaceclaims
- networkinterfaces
matchConditions:
- name: physical-or-detach
expression: >-
(has(object.spec) && has(object.spec.attachmentMode) && object.spec.attachmentMode == 'Physical') ||
(has(object.metadata.finalizers) &&
'networking.datumapis.com/physical-detach' in object.metadata.finalizers) ||
(request.operation == 'UPDATE' && has(oldObject.metadata.finalizers) &&
'networking.datumapis.com/physical-detach' in oldObject.metadata.finalizers)
# The first five variables are the lists a deployment sets, in this order.
# Deployments patch them by index, so the order is a contract: add new
# variables after them, never between. Each is a CEL list of strings, and
# leaving a list empty refuses whatever it would allow.
variables:
- name: operators
expression: >-
['system:serviceaccount:network-services-operator-system:controller-manager']
- name: providers
expression: "[]"
- name: realizers
expression: "[]"
- name: breakGlassGroups
expression: "[]"
- name: providerProjects
expression: "[]"
- name: isClaim
expression: request.resource.resource == 'networkinterfaceclaims'
- name: isOperator
expression: request.userInfo.username in variables.operators
- name: isProvider
expression: request.userInfo.username in variables.providers
- name: isRealizer
expression: request.userInfo.username in variables.realizers
- name: isBreakGlass
expression: >-
has(request.userInfo.groups) &&
request.userInfo.groups.exists(g, g in variables.breakGlassGroups)
- name: physical
expression: >-
has(object.spec) && has(object.spec.attachmentMode) && object.spec.attachmentMode == 'Physical'
- name: detachFinalizer
expression: "'networking.datumapis.com/physical-detach'"
- name: hasDetach
expression: >-
has(object.metadata.finalizers) && variables.detachFinalizer in object.metadata.finalizers
- name: hadDetach
expression: >-
request.operation == 'UPDATE' && has(oldObject.metadata.finalizers) &&
variables.detachFinalizer in oldObject.metadata.finalizers
- name: projectLabel
expression: >-
has(namespaceObject.metadata.labels) &&
'meta.datumapis.com/upstream-cluster-name' in namespaceObject.metadata.labels
? namespaceObject.metadata.labels['meta.datumapis.com/upstream-cluster-name'].replace('_', '/')
: ''
- name: projectTrimmed
expression: >-
variables.projectLabel.startsWith('cluster-')
? variables.projectLabel.substring(8)
: variables.projectLabel
- name: project
expression: >-
variables.projectTrimmed.startsWith('/')
? variables.projectTrimmed.substring(1)
: variables.projectTrimmed
validations:
- expression: >-
variables.isOperator || !variables.physical ||
(variables.isClaim && variables.isProvider) ||
(variables.isClaim && request.operation == 'UPDATE' && (variables.isRealizer || variables.isBreakGlass))
messageExpression: >-
variables.isClaim
? 'physical network interface claims may only be written by a configured provider, and ' +
request.userInfo.username + ' is not one'
: 'physical network interfaces may only be written by the network services operator'
reason: Forbidden
- expression: >-
variables.isOperator || !variables.hadDetach || variables.hasDetach ||
variables.isRealizer || variables.isBreakGlass
messageExpression: >-
'only the physical realizer may remove the ' + variables.detachFinalizer +
' finalizer, and ' + request.userInfo.username + ' is not it'
reason: Forbidden
- expression: >-
variables.isOperator || !variables.hasDetach || variables.hadDetach
messageExpression: >-
'only the network services operator may add the ' + variables.detachFinalizer + ' finalizer'
reason: Forbidden
- expression: >-
variables.isOperator || request.operation != 'CREATE' ||
!(has(object.spec.purpose) && object.spec.purpose == 'Boot') ||
(variables.project != '' && variables.project in variables.providerProjects)
messageExpression: >-
'a boot claim is only accepted in a provider project namespace, and namespace ' +
object.metadata.namespace + ' does not belong to one'
reason: Forbidden
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: physical-attachment-writers
spec:
policyName: physical-attachment-writers
validationActions:
- Deny
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ require (
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.36.0 // indirect
sigs.k8s.io/json v0.0.0-20260909141634-11ed52e25bc5 // indirect
sigs.k8s.io/kubectl-validate v0.0.5-0.20250915070809-d2f2d68fba09 // indirect
sigs.k8s.io/kustomize/api v0.21.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.21.1 // indirect
sigs.k8s.io/kustomize/api v0.21.1
sigs.k8s.io/kustomize/kyaml v0.21.1
sigs.k8s.io/mcs-api v0.5.0 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.4.2 // indirect
Expand Down
Loading
Loading