Skip to content
Open
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
18 changes: 10 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
# kubectl-ate binaries attached. A maintainer edits and publishes it; see
# docs/dev/releasing.md.
#
# Images are published only from agent-substrate/substrate, to
# ghcr.io/agent-substrate/substrate. In any other repository (a fork) the
# images job is skipped, because GitHub bills package storage to the fork's
# owner, and the draft is created as before.
# Images are published only from agent-substrate/substrate and the
# pluralsh/substrate fork, each to ghcr.io/<repository>. In any other
# repository (a fork) the images job is skipped, because GitHub bills package
# storage to the fork's owner, and the draft is created as before.
# pluralsh/substrate publishes images only: it creates no draft, because it
# has no upstream release tags for the notes to start from.
#
# Run manually to publish images or draft a release for an existing tag.
# A complete image set is left unchanged unless overwrite is set; an incomplete
Expand Down Expand Up @@ -54,7 +56,7 @@ concurrency:
jobs:
# The only job that writes to a registry.
images:
if: github.repository == 'agent-substrate/substrate' && !inputs.dry_run_images
if: (github.repository == 'agent-substrate/substrate' || github.repository == 'pluralsh/substrate') && !inputs.dry_run_images
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
Expand All @@ -63,7 +65,7 @@ jobs:
# Read by ate-setup publish release-images.
env:
VERSION: ${{ inputs.tag || github.ref_name }}
KO_DOCKER_REPO: ghcr.io/agent-substrate/substrate
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}
KO_DEFAULTPLATFORMS: linux/amd64,linux/arm64
# inputs.overwrite is empty on a tag push; this makes the value explicit.
ATE_PUBLISH_OVERWRITE: ${{ inputs.overwrite == true }}
Expand Down Expand Up @@ -153,8 +155,8 @@ jobs:
# Runs after images succeeded, or when images was skipped (any repository
# other than agent-substrate/substrate). If images failed, no draft is
# created, so a release cannot be published without its images. Skipped
# in a dry run.
if: ${{ !cancelled() && !inputs.dry_run_images && (needs.images.result == 'success' || needs.images.result == 'skipped') }}
# in a dry run and in pluralsh/substrate.
if: ${{ !cancelled() && !inputs.dry_run_images && github.repository != 'pluralsh/substrate' && (needs.images.result == 'success' || needs.images.result == 'skipped') }}
runs-on: ubuntu-latest
timeout-minutes: 30
# Creating a release needs contents: write.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
with:
path: site/public
deploy:
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && github.repository == 'agent-substrate/substrate'
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
35 changes: 32 additions & 3 deletions api/ateapi/v1/ateapi.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions api/ateapi/v1/ateapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ message Container {
// the default capability set.
//
// +k8s:optional
// +k8s:customValidation # capabilities must be unset when privileged
SecurityContext security_context = 8;

// resources carries this container's compute limits, enforced inside the
Expand All @@ -1399,9 +1400,28 @@ message Container {
// modeling a subset of the Kubernetes container securityContext.
message SecurityContext {
// capabilities adjusts the Linux capabilities of the container's process.
// Must be unset when privileged is true.
//
// +k8s:optional
Capabilities capabilities = 1;

// privileged runs the container with every Linux capability, a writable
// /sys and cgroup hierarchy, and no masked paths, so that it can run a
// container engine such as dockerd, or Kubernetes in containers (kind, k3s).
// The sandbox, not the container inside it, stays the isolation boundary,
// and the privilege never reaches the node:
//
// * microvm: the actor owns a whole guest kernel. The container also gets
// every guest device, including /dev/net/tun, /dev/fuse and /dev/kmsg.
// * gvisor: capabilities exist only in the Sentry, and runsc runs the
// sandbox with raw and packet sockets enabled.
//
// A worker runs privileged containers only when its WorkerPool sets
// sandboxClasses[].allowPrivilegedActors; every other worker fails the actor
// rather than run it unprivileged.
//
// +k8s:optional
bool privileged = 2;
}

// Capabilities adjusts a container's Linux capabilities relative to the
Expand Down
19 changes: 19 additions & 0 deletions api/infra/k8s/ate/v1/workerpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ type WorkerPoolSandboxClass struct {
//
// +optional
ConfigRef *SandboxConfigReference `json:"configRef,omitempty"`

// allowPrivilegedActors lets this pool's workers run containers whose
// ActorTemplate sets securityContext.privileged, for example to run a
// container engine inside the actor. The sandbox stays the isolation
// boundary, but the workload gets full privilege inside it:
//
// - microvm: each actor owns a whole guest kernel and can drive every
// guest-to-host interface (virtio devices, the guest agent channel)
// directly.
// - gvisor: the Sentry grants every capability inside the sandbox
// (never on the host), and runsc runs with --net-raw and
// --allow-packet-socket-write, so the actor can open raw sockets and
// write arbitrary packets on its own network interface.
//
// Enable it only on pools meant for that, ideally on dedicated nodes.
// Workers of pools without it fail privileged actors.
//
// +optional
AllowPrivilegedActors *bool `json:"allowPrivilegedActors,omitempty"`
}

// SandboxConfigReference names a cluster-scoped SandboxConfig.
Expand Down
13 changes: 13 additions & 0 deletions api/infra/k8s/ate/v1/workerpool_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

const gpuResourceName = corev1.ResourceName("nvidia.com/gpu")
Expand Down Expand Up @@ -119,6 +120,18 @@ func TestWorkerPoolValidation(t *testing.T) {
},
wantErr: true,
errMsg: "spec.sandboxClasses[0].name: Unsupported value",
}, {
name: "microvm pool allows privileged actors",
mutate: func(wp *WorkerPool) {
wp.Spec.SandboxClasses = []WorkerPoolSandboxClass{{Name: SandboxClassMicroVM, AllowPrivilegedActors: ptr.To(true)}}
},
wantErr: false,
}, {
name: "gvisor pool allows privileged actors",
mutate: func(wp *WorkerPool) {
wp.Spec.SandboxClasses = []WorkerPoolSandboxClass{{Name: SandboxClassGvisor, AllowPrivilegedActors: ptr.To(true)}}
},
wantErr: false,
}, {
name: "sandboxClass with configRef",
mutate: func(wp *WorkerPool) {
Expand Down
5 changes: 5 additions & 0 deletions api/infra/k8s/ate/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/ateapi/internal/apivalidation/actor_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,9 @@ func ValidateCustom_Capabilities_Add(_ context.Context, _ operation.Operation, f
func ValidateCustom_Capabilities_Drop(_ context.Context, _ operation.Operation, fldPath *field.Path, value, _ []string) field.ErrorList {
return resources.ValidateDropCapabilities(fldPath, value)
}

// ValidateCustom_Container_SecurityContext rejects capabilities next to
// privileged: a privileged container gets every capability.
func ValidateCustom_Container_SecurityContext(_ context.Context, _ operation.Operation, fldPath *field.Path, value, _ *ateapi.SecurityContext) field.ErrorList {
return resources.ValidatePrivilegedSecurityContext(fldPath, value.GetPrivileged(), value.GetCapabilities().GetAdd(), value.GetCapabilities().GetDrop())
}
11 changes: 11 additions & 0 deletions cmd/ateapi/internal/apivalidation/actor_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,17 @@ func TestValidateActorTemplate(t *testing.T) {
Drop: []string{"ALL"},
}}
},
}, {
name: "privileged container",
mutate: func(tmpl *ateapi.ActorTemplate) {
tmpl.Containers[0].SecurityContext = &ateapi.SecurityContext{Privileged: true}
},
}, {
name: "privileged rejects capabilities",
mutate: func(tmpl *ateapi.ActorTemplate) {
tmpl.Containers[0].SecurityContext = &ateapi.SecurityContext{Privileged: true, Capabilities: &ateapi.Capabilities{Drop: []string{"ALL"}}}
},
want: field.ErrorList{field.Invalid(field.NewPath("containers").Index(0).Child("security_context", "capabilities"), nil, "")},
}, {
name: "capabilities add rejects ALL",
mutate: func(tmpl *ateapi.ActorTemplate) {
Expand Down
32 changes: 32 additions & 0 deletions cmd/ateapi/internal/apivalidation/zz_generated.validation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/ateapi/internal/controlapi/access_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAccessPolicy_GlobalAndAtespaceGovernance(t *testing.T) {
}
persistence.SetPolicyManager(policyManager)

svc := NewRPCService(persistence, nil, nil, nil, nil, nil, "", nil, nil, "", nil, "")
svc := NewRPCService(persistence, nil, nil, nil, nil, nil, "", nil, nil, "", nil, "", false)
interceptor := authz.UnaryServerInterceptor(authorizer)

userCtx := func(id string) context.Context {
Expand Down
7 changes: 7 additions & 0 deletions cmd/ateapi/internal/controlapi/actor_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func (s *ServiceImpl) CreateActorTemplate(ctx context.Context, inTemplate *ateap
if _, err := resolveSnapshotLocation(s.clusterSnapshotLocation, outTemplate); err != nil {
return nil, err
}
if s.disablePrivilegedActors {
for _, c := range outTemplate.GetContainers() {
if c.GetSecurityContext().GetPrivileged() {
return nil, apierror.FailedPrecondition("container %q is privileged, but this cluster disables privileged actors (ate-api-server --disable-privileged-actors)", c.GetName())
}
}
}

return s.store.CreateActorTemplate(ctx, outTemplate)
}
Expand Down
37 changes: 37 additions & 0 deletions cmd/ateapi/internal/controlapi/actor_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,43 @@ func TestCreateActorTemplate_RequiresSnapshotLocation(t *testing.T) {
}
}

// TestCreateActorTemplate_DisablePrivilegedActors pins that
// --disable-privileged-actors rejects only templates with a privileged
// container.
func TestCreateActorTemplate_DisablePrivilegedActors(t *testing.T) {
for i, tt := range []struct {
name string
disable bool
privileged bool
wantCode codes.Code
}{
{name: "allowed", privileged: true, wantCode: codes.OK},
{name: "disabled, privileged", disable: true, privileged: true, wantCode: codes.FailedPrecondition},
{name: "disabled, unprivileged", disable: true, wantCode: codes.OK},
} {
t.Run(tt.name, func(t *testing.T) {
persistence := newTestPersistence(t)
impl := newServiceImpl(persistence, nil)
impl.clusterSnapshotLocation = "gs://cluster-bucket/"
impl.disablePrivilegedActors = tt.disable
s := &RPCService{impl: impl}
ctx := context.Background()
if _, err := persistence.CreateAtespace(ctx, &ateapi.Atespace{Metadata: &ateapi.ResourceMetadata{Name: "ns1"}}); err != nil {
t.Fatalf("CreateAtespace failed: %v", err)
}
req := &ateapi.CreateActorTemplateRequest{ActorTemplate: validActorTemplate(func(tmpl *ateapi.ActorTemplate) {
tmpl.Metadata = &ateapi.ResourceMetadata{Atespace: "ns1", Name: fmt.Sprintf("tmpl-%d", i)}
if tt.privileged {
tmpl.Containers[0].SecurityContext = &ateapi.SecurityContext{Privileged: true}
}
})}
if _, err := s.CreateActorTemplate(ctx, req); apierror.Code(err) != tt.wantCode {
t.Errorf("CreateActorTemplate error = %v, want code %v", err, tt.wantCode)
}
})
}
}

// TestCreateActorTemplateIgnoresServerOwnedFields pins the create contract:
// status on the request is dropped and new templates start with an empty
// status. The store persists whatever the handler hands it, so the handler is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func setupTestWithOptions(t *testing.T, ns string, options testOptions) *testCon
testActorJWTIssuer,
actorJWTAuthorityPool,
testStorageLocation,
false,
)

// 5. Start REAL gRPC Server for ATE API
Expand Down
Loading
Loading