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
7 changes: 6 additions & 1 deletion docs/agent-runtime-hardening.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ Notes on the choices:
## API scope

The WorkerPool field and resource ceilings were checked against
[WorkerPoolSpec at a9c1bd3](https://github.com/agent-substrate/substrate/blob/a9c1bd389403af59520e419d3884d447cf40edd2/pkg/api/v1alpha1/workerpool_types.go).
[WorkerPoolSpec at v1.0.1](https://github.com/agent-substrate/substrate/blob/20778a6dbb01f13024642851bb592bf67c9fec05/api/infra/k8s/ate/v1/workerpool_types.go)
(`ate.dev/v1`). The rules match WorkerPool at both `ate.dev/v1alpha1` and
`ate.dev/v1`: Substrate served it only at `v1alpha1` up to v0.6.0 and only at
`v1` from v1.0.0. `spec.workerImage` and `spec.template.resources` are the same
in `v1` and in `v1alpha1` from v0.1.0 to v0.6.0 (v0.0.0 used `spec.ateomImage`
and had no `spec.template.resources`).
ActorTemplate is an [ATE protobuf resource](https://github.com/agent-substrate/substrate/blob/a9c1bd389403af59520e419d3884d447cf40edd2/pkg/proto/ateapipb/ateapi.proto),
not a Kubernetes CRD. Its environment variables carry literal name/value pairs,
not Kubernetes `secretKeyRef` fields. ActorTemplate image, secret-reference,
Expand Down
5 changes: 3 additions & 2 deletions rules/agent-runtime-image-digests/rule.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"ate.dev"
],
"apiVersions": [
"v1alpha1"
"v1alpha1",
"v1"
Comment on lines +35 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I checked Substrate's WorkerPool CRD: v1alpha1 is the only served version up to v0.6.0, and from v0.7.0-alpha1 through v1.0.1 only v1 is served. spec.workerImage is unchanged in the v1 types (api/infra/k8s/ate/v1/workerpool_types.go), so the rego works as-is. Keeping v1alpha1 alongside matches what we already do for Sandbox / SandboxTemplate (v1alpha1 + v1beta1) in this same file.

],
"resources": [
"WorkerPool"
Expand All @@ -41,6 +42,6 @@
],
"ruleDependencies": [],
"description": "Requires exact lowercase SHA-256 image pins on Sandbox, SandboxTemplate and WorkerPool resources.",
"remediation": "Use image@sha256:<64 lowercase or uppercase hexadecimal characters>.",
"remediation": "Use image@sha256:<64 lowercase hexadecimal characters>.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch the rego only accepts [a-f0-9]{64} and the C-0312 control remediation already says lowercase, so "lowercase or uppercase" was wrong. This is a separate fix from the apiVersion change though, so could you mention it in the PR description (one bullet under Overview is enough)? Right now the description only covers the v1 matching, and someone reading the squashed commit later won't know why the remediation text changed.

"ruleQuery": "armo_builtins"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"postureControlInputs": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-digest
spec:
replicas: 1
workerImage: gcr.io/team/worker@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"postureControlInputs": {}
}
25 changes: 25 additions & 0 deletions rules/agent-runtime-image-digests/test/worker-tag-v1/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"alertMessage": "WorkerPool image must be pinned to an exact SHA-256 digest",
"alertObject": {
"k8sApiObjects": [
{
"apiVersion": "ate.dev/v1",
"kind": "WorkerPool",
"metadata": {
"name": "worker-tag"
}
}
]
},
"alertScore": 8,
"failedPaths": [
"spec.workerImage"
],
"fixPaths": [],
"packagename": "armo_builtins",
"reviewPaths": [
"spec.workerImage"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-tag
spec:
replicas: 1
workerImage: gcr.io/team/worker:1.0
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"postureControlInputs": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"alertMessage": "WorkerPool image must be pinned to an exact SHA-256 digest",
"alertObject": {
"k8sApiObjects": [
{
"apiVersion": "ate.dev/v1",
"kind": "WorkerPool",
"metadata": {
"name": "worker-uppercase"
}
}
]
},
"alertScore": 8,
"failedPaths": [
"spec.workerImage"
],
"fixPaths": [],
"packagename": "armo_builtins",
"reviewPaths": [
"spec.workerImage"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-uppercase
spec:
replicas: 1
workerImage: gcr.io/team/worker@sha256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
template:
resources:
limits:
cpu: '1'
memory: 256Mi
3 changes: 2 additions & 1 deletion rules/agent-runtime-image-registries/rule.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"ate.dev"
],
"apiVersions": [
"v1alpha1"
"v1alpha1",
"v1"
],
"resources": [
"WorkerPool"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the -v1 copies of the passing cases (worker-allowed-v1, worker-docker-*-v1, worker-empty-v1, worker-missing-v1, cpu-nano-v1, disabled-v1, within-v1, worker-digest-v1) expect [], so they also passed on master when the rule never received the object. The failing-case copies are what actually test the fix. I'm fine keeping them for symmetry, just noting it so nobody reads them as coverage of the match.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-allowed
spec:
replicas: 1
workerImage: gcr.io/team/actor
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-docker-digest
spec:
replicas: 1
workerImage: nginx@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-docker-path-tag
spec:
replicas: 1
workerImage: org/nginx:1.0
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-docker-path
spec:
replicas: 1
workerImage: library/nginx
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-docker-short
spec:
replicas: 1
workerImage: nginx
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-docker-tag
spec:
replicas: 1
workerImage: nginx:1.0
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-empty
spec:
replicas: 1
workerImage: evil.example/worker
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"alertMessage": "WorkerPool image uses a registry outside imageRepositoryAllowList",
"alertObject": {
"k8sApiObjects": [
{
"apiVersion": "ate.dev/v1",
"kind": "WorkerPool",
"metadata": {
"name": "worker-evil"
}
}
]
},
"alertScore": 8,
"failedPaths": [
"spec.workerImage"
],
"fixPaths": [],
"packagename": "armo_builtins",
"reviewPaths": [
"spec.workerImage"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
name: worker-evil
spec:
replicas: 1
workerImage: gcr.io.evil/actor
template:
resources:
limits:
cpu: '1'
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"postureControlInputs": {
"imageRepositoryAllowList": [
"gcr.io",
"docker.io"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"alertMessage": "WorkerPool image uses a registry outside imageRepositoryAllowList",
"alertObject": {
"k8sApiObjects": [
{
"apiVersion": "ate.dev/v1",
"kind": "WorkerPool",
"metadata": {
"name": "worker-host"
}
}
]
},
"alertScore": 8,
"failedPaths": [
"spec.workerImage"
],
"fixPaths": [],
"packagename": "armo_builtins",
"reviewPaths": [
"spec.workerImage"
]
}
]
Loading
Loading