Skip to content
Merged
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
35 changes: 35 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,41 @@ boundary:
go -C app/cetirun-operator test ./internal/runtimebindings ./internal/helm ./internal/controller -run 'TestCustomAgentIdentity' -count=1
```

Credential policy application/readback has focused offline regressions:

```bash
go -C app/internal test ./agenttools -run 'TestCredentialPolicy' -count=1
go -C app/cetirun-agent-broker test ./internal/broker -run 'TestCredentialPolicy' -count=1
go -C app/cetirun-connections-mcp test ./internal/tools -run 'TestCredentialPolicy' -count=1
go -C app/cetirun-operator test ./internal/controller -run 'TestCredentialPolicy' -count=1
```

They cover owned storage, current-policy/identity matching, failed and lost
replies, read-before-retry, status conflicts, removal and the provider execution
boundary. Unqualified native runtimes still reject stored policy as authority.
Current native integration has additional offline checks:

```bash
go -C app/internal test ./agenttools -run 'TestNative' -count=1
go -C app/cetirun-agent-broker test ./internal/broker -run 'TestNative|TestCredentialPolicy' -count=1
go -C app/cetirun-connections-mcp test ./internal/identity ./internal/tools -run 'TestNative|TestCredentialPolicy' -count=1
go -C app/cetirun-operator test ./internal/controller -run 'TestNativeConnections' -count=1
KUBEBUILDER_ASSETS=/path/to/local/envtest \
go -C app/cetirun-operator test -tags=envtest ./internal/controller -run '^TestNativeConnectionsServedCurrentSourceProof$' -count=1
```

The API-server test uses actual common chart rendering, owned bootstrap,
API-issued Pod-bound tokens and TokenReviews, source/UID pins, Pod admission
and current credential evidence reaching
`PolicyApplied`, with both harnesses. Broker/MCP served-interface tests use
synthetic Kubernetes, admission, directory and provider responses.
The API-server case rejects a freshly issued token for a recreated ServiceAccount against the old
source pin and clears applied evidence. The API-server test's Broker readback
fixture is gated by the real admission handler;
it is not a deployed Broker/MCP/Operator system. Scheduler/kubelet observations
remain synthetic. These checks do not qualify live Kata/Cilium routing, TLS
delivery, Entra federation, provider permissions or an Azure tenant.

`npm --prefix app/cetirun-portal/web run dev` starts a local frontend server.
Its API proxy expects a backend on localhost and injects development identity
headers. Keep it local; it is not a production authentication configuration.
Expand Down
86 changes: 81 additions & 5 deletions app/cetirun-agent-broker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ The three internal routes are registered only on the direct mTLS listener:
- `POST /internal/v1/service-credentials/issue`

Input contains `callerProof`, `connectionId`, `service`, `contractVersion`, and
(for issuance) connection/binding revisions. It contains no REST arguments or
operation policy. The Broker independently TokenReviews the Pod-bound proof,
(for issuance) connection/binding revisions and the governed `credentialPolicy`
reference (revision, record UID and resource version). It contains no REST
arguments or operation policy. The Broker independently TokenReviews the Pod-bound proof,
checks the live Pod and ServiceAccount, follows the namespace Agent owner
reference to a named Agent GET, validates its immutable UID, owner and binding,
and resolves the service from the trusted profile. Identity, connection and
Expand All @@ -90,6 +91,78 @@ All three default to `cetirun-connections-mcp`; a custom audience must match acr
all three releases because both MCP and the Broker independently verify the
Agent's projected workload token.

## Credential policy execution and readback

The Operator's existing authenticated mesh API also exposes `PUT`, `GET` and
`DELETE /operator/v1/instances/{uid}/credential-policy`. This is not a token
endpoint. The versioned `credential-policy-v3` projection binds the Agent, Team
and AgentPolicy UIDs, trusted owner tenant/object IDs, canonical Agent client
and principal IDs, and the requested/allowed/required identity controls.
`azure-resource-manager` maps only to the fixed `azure_arm` profile.

PUT independently reads the live Agent, its selected Team and accepted
AgentPolicy, then conditionally writes a credential-free, exactly Agent-owned
Secret in the Broker namespace, using its existing Secret permissions. It
requires no Secret access or token mount in the Agent namespace. It neither
provisions an identity nor creates a Connection or ConnectionBinding.
Its 204 acknowledgment is **not** applied
evidence. GET reads the actual record and rechecks current authorization before
returning its UID, resource version and projection revision. Desired status,
legacy bearer issuance and provider token acquisition cannot supply this
readback. No provider call is made by application or readback.

Readback also requires an available supported executor. Opted-in common native
OpenClaw/Hermes workloads qualify only after current namespace, Pod, Agent and
ServiceAccount reads and an independent check through the Operator's existing
Pod-admission validator. Its protected common-executor expectation verifies
the source UID/version pins, current workload/control shapes and active native
reservation. A stored restriction, generic Entra projection, runtime capability
flag or desired policy cannot provide that authority. Missing, stale, held,
suspended or unqualified native inputs remain unavailable/nonready.

The native path uses the already-pinned current/default ServiceAccount, not a
new dedicated identity lifecycle. The Operator installs its existing exactly
Agent-owned Broker storage Role/RoleBinding in the Agent namespace and includes
them, the public MCP CA and registered MCP Service in common-executor Sources.
Provider credentials remain outside Agent workloads. See
[native Connections configuration](../cetirun-connections-mcp/README.md#governed-native-workloads)
for the opt-in and transport prerequisites; generic `AzureADTokenExchange`
federation is separate.

Configuration readback may precede aggregate Agent Ready, avoiding a readiness
cycle. Actual workload authentication additionally requires a Running/Ready
current Pod and a Ready Agent. The Broker grants neither provider permissions
nor live runtime qualification through configuration readback.

For governed Azure app-only and Azure/Microsoft delegated acquisition, the real
check/issue path requires the stored projection to match current sources.
Unaccepted, removed, changed or unreadable inputs fail before acquiring a
credential. The policy revision and record UID/resource version are pinned along
with Connection and Binding revisions and rechecked after acquisition;
Connections also compares the policy revision with
the authenticated Agent's status before execution. A governed ARM-only policy
does not authorize Microsoft Graph. Existing non-governed provider integrations
keep their Connection/Binding authorization.

Connection discovery lists owned metadata; it does not read ARM credential-policy
evidence or certify credential authorization. Missing, revoked, stale or
unavailable ARM evidence is not a list-wide dependency for GitHub/Google.
Existing owner, binding and runtime filters remain unchanged; identity-backed
service check/issue still requires current credential-policy evidence.

After an uncertain PUT, read before retrying; an identical stored projection is
not rewritten. DELETE uses exact Agent ownership and Secret UID/resource-version
preconditions and confirms absence. The existing authorization cleanup route
removes this record before its other Agent-scoped records; the Operator still
waits for Broker cleanup before directory deletion. Failed cleanup remains
retryable. Source checks reject suspended/deleting Agents even if an old record
is present. None of this revokes already issued provider tokens or retries a
provider operation whose execution result is unknown.

The internal Broker/Connections wire version is `2026-10-28`; deploy matching
Broker, Connections and Operator builds. There is no legacy policy receipt
adapter or migration reader.

## Availability and identity modes

Both chart switches default to `true`:
Expand Down Expand Up @@ -207,14 +280,17 @@ a fixed operation catalog. Google's testing-mode token expiry still applies.
| Record | Storage | Owner |
| --- | --- | --- |
| ConnectionBinding | Agent workload namespace | Agent UID |
| Credential policy enforcement (no credentials) | Broker namespace | Agent UID |
| Independent Azure Connection | Agent workload namespace | Agent UID |
| Credential-free delegated connection reference | Agent workload namespace | Agent UID |
| Personal OAuth Connection | Broker credential namespace | Portal owner |
| OAuth client configuration / Broker TLS | Broker namespace | Platform |

Per-Agent storage is mandatory for this contract. There is no migration command
or compatibility reader for the previous grant model. The Broker resolves the
namespace from live Agent state and checks its owner reference. Encrypted
Per-Agent workload namespace storage remains mandatory for ConnectionBindings
and independent Connections. The credential-free policy record instead uses the
Broker namespace, still with exact Agent ownership. There is no migration
command or compatibility reader for the previous grant model. The Broker resolves
the workload namespace from live Agent state and checks its owner reference. Encrypted
records bind owner, immutable IDs and revisions. Labels and display snapshots
support inventory only and cannot establish authority. Workload authentication
uses namespace ownership and named Agent reads, without a cluster-wide Agent
Expand Down
11 changes: 11 additions & 0 deletions app/cetirun-agent-broker/chart/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ metadata:
labels:
{{- include "cetirun-agent-broker.labels" . | nindent 4 }}
rules:
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
resourceNames: ["cetirun-agent-tools-broker"]
verbs: ["get"]
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["validatingwebhookconfigurations"]
resourceNames: ["cetirun-sandbox-pods"]
verbs: ["get"]
- apiGroups: ["cetirun.microsoft.com"]
resources: ["agents"]
verbs: ["get", "list"]
- apiGroups: ["cetirun.microsoft.com"]
resources: ["teams", "agentpolicies"]
verbs: ["get"]
- apiGroups: ["authentication.k8s.io"]
resources: ["tokenreviews"]
verbs: ["create"]
Expand Down
4 changes: 2 additions & 2 deletions app/cetirun-agent-broker/chart/templates/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ spec:
to:
- operation:
ports: ["8080"]
methods: ["DELETE"]
methods: ["GET", "PUT", "DELETE"]
# Istio StringMatch supports a trailing prefix wildcard. The Go
# ServeMux still exposes only the exact bounded cleanup route.
# ServeMux exposes only bounded cleanup and credential-policy routes.
paths: ["/operator/v1/instances/*"]
- from:
- source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (s *Server) agentIdentityCreate(w http.ResponseWriter, r *http.Request) {
writeAPIError(w, http.StatusForbidden, "forbidden", "Instance owner binding is invalid", correlation)
return
}
if agent.PolicyManaged {
agent, err = s.store.qualifyNativeAgent(r.Context(), agent, nil)
if err != nil {
writeAPIError(w, http.StatusConflict, "identity_not_ready", "Current native workload identity is not ready", correlation)
return
}
}
var input toolIdentityRequest
if !decodeJSON(w, r, &input) {
return
Expand Down
9 changes: 9 additions & 0 deletions app/cetirun-agent-broker/internal/broker/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ func managementOperation(r *http.Request) string {
return "credential.check"
case path == "/internal/v1/service-credentials/issue":
return "credential.issue"
case strings.HasPrefix(path, "/operator/v1/instances/") && strings.HasSuffix(path, "/credential-policy"):
switch r.Method {
case http.MethodGet:
return "credential.policy.readback"
case http.MethodPut:
return "credential.policy.apply"
case http.MethodDelete:
return "credential.policy.remove"
}
case path == "/api/v1/connections/callback":
return "oauth.complete"
case r.Method == "GET":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ func newConnectionFixture(t *testing.T) *connectionFixture {
return fixture
}

func (fixture *connectionFixture) request(t *testing.T, path string) *httptest.ResponseRecorder {
func (fixture *connectionFixture) request(t *testing.T, path string, configure ...func(*serviceRequest)) *httptest.ResponseRecorder {
t.Helper()
input := serviceRequest{CallerProof: "synthetic-workload-proof", Service: fixture.binding.Services[0], ConnectionID: fixture.connection.Connection.ID, BindingRevision: &fixture.binding.Revision, ConnectionRevision: &fixture.connection.Connection.Revision, ContractVersion: agenttools.ContractVersion}
for _, apply := range configure {
apply(&input)
}
body, err := json.Marshal(input)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -694,6 +697,9 @@ func TestOperatorCleanupBeforeNamespaceProvisioningIsIdempotent(t *testing.T) {
f.secrets = map[string]secretDocument{}
original := f.server.store.client.Transport
f.server.store.client.Transport = roundTripFunc(func(r *http.Request) (*http.Response, error) {
if r.Method == http.MethodGet && r.URL.Path == "/api/v1/namespaces/credentials/secrets/"+toolRecordName(credentialPolicyRecord, f.agent.Metadata.UID) {
return securityJSONResponse(t, 404, map[string]any{}), nil
}
if strings.HasPrefix(r.URL.Path, "/api/v1/namespaces/credentials/secrets/agent-authorization-") {
return securityJSONResponse(t, 404, map[string]any{}), nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func (s *Server) bindingAgent(w http.ResponseWriter, r *http.Request) (Owner, Ag
writeAPIError(w, http.StatusForbidden, "forbidden", "The instance owner binding is invalid", correlationID(r))
return Owner{}, Agent{}, false
}
if agent.PolicyManaged && (r.Method == http.MethodPost || r.Method == http.MethodPut) {
agent, err = s.store.qualifyNativeAgent(r.Context(), agent, nil)
if err != nil {
writeAPIError(w, http.StatusConflict, "identity_not_ready", "Current native workload identity is not ready", correlationID(r))
return Owner{}, Agent{}, false
}
}
return owner, agent, true
}

Expand Down
Loading
Loading