diff --git a/_local/.armadactl.yaml b/_local/.armadactl.yaml index f9dd46366fe..5f564b62d13 100644 --- a/_local/.armadactl.yaml +++ b/_local/.armadactl.yaml @@ -30,7 +30,7 @@ contexts: # Context with OIDC Client Credentials authentication # For service accounts (requires confidential client with secret) - auth-client-creds: + auth-client-creds-executor: armadaUrl: localhost:50051 openIdClientCredentialsAuth: providerUrl: "http://localhost:8180/realms/armada" @@ -38,6 +38,42 @@ contexts: clientSecret: "executor-secret" scopes: ["openid", "profile", "email"] + auth-client-creds-user: + armadaUrl: localhost:50051 + openIdClientCredentialsAuth: + providerUrl: "http://localhost:8180/realms/armada" + clientId: "armada-user" + clientSecret: "user-secret" + scopes: ["openid", "profile", "email"] + + auth-client-creds-admin: + armadaUrl: localhost:50051 + openIdClientCredentialsAuth: + providerUrl: "http://localhost:8180/realms/armada" + clientId: "armada-admin" + clientSecret: "admin-secret" + scopes: ["openid", "profile", "email"] + + # Contexts for the rbac integration test suite, against the containerized full.yaml stack + # (server-auth on :50061, keycloak reachable from the host via the /etc/hosts alias that + # `mage dev:full` adds -- see magefiles/dev.go's ensureEtcHostsEntry). Same Keycloak realm/ + # clients as auth-client-creds-admin/-user above; only the network path differs. + rbac-admin: + armadaUrl: localhost:50061 + openIdClientCredentialsAuth: + providerUrl: "http://keycloak:8180/realms/armada" + clientId: "armada-admin" + clientSecret: "admin-secret" + scopes: ["openid", "profile", "email"] + + rbac-user: + armadaUrl: localhost:50061 + openIdClientCredentialsAuth: + providerUrl: "http://keycloak:8180/realms/armada" + clientId: "armada-user" + clientSecret: "user-secret" + scopes: ["openid", "profile", "email"] + # Context with OIDC Password Flow authentication auth-password: armadaUrl: localhost:50051 diff --git a/_local/compose/full.yaml b/_local/compose/full.yaml index 6a0e5b4d9a9..ed631006d35 100644 --- a/_local/compose/full.yaml +++ b/_local/compose/full.yaml @@ -138,6 +138,47 @@ services: ARMADA_POSTGRES_CONNECTION_HOST: postgres command: ./lookout --migrateDatabase --config /config/config.yaml + # ========================================================= + # OIDC provider, for the rbac test suite only + # ========================================================= + keycloak: + container_name: keycloak + image: ${KEYCLOAK_IMAGE:-quay.io/keycloak/keycloak:25.0} + environment: + KEYCLOAK_ADMIN: admin + KEYCLOAK_ADMIN_PASSWORD: admin + KC_HTTP_PORT: 8180 + KC_HEALTH_ENABLED: "true" + # Pins the OIDC issuer to one literal hostname regardless of whether the caller is another + # container (reaching it via the "keycloak" service name) or the host (reaching it via the + # "keycloak" /etc/hosts alias that `mage dev:full` adds, pointing at 127.0.0.1). go-oidc + # requires the discovery document's issuer to exactly match the URL used to fetch it, and + # token verification then requires the token's iss claim to match that same issuer, so both + # paths must agree on one hostname string. + KC_HOSTNAME: keycloak + ports: + - "8180:8180" + command: start-dev --import-realm + volumes: + - ../keycloak/import:/opt/keycloak/data/import:ro + networks: [kind] + restart: unless-stopped + # server-auth dials Keycloak's discovery endpoint at its own startup and, unlike the + # dependency services above, doesn't retry/restart on failure -- so server-auth's + # depends_on below needs service_healthy, not just service_started, to not lose the race + # against Keycloak's realm import. No curl/wget in this image, so the check uses bash's + # /dev/tcp against the KC_HEALTH_ENABLED management endpoint (port 9000) instead. + healthcheck: + test: + [ + "CMD-SHELL", + "bash -c 'exec 3<>/dev/tcp/127.0.0.1/9000 && printf \"GET /health/ready HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n\" >&3 && cat <&3' | grep -q '\"status\": \"UP\"'", + ] + interval: 5s + timeout: 5s + retries: 30 + start_period: 20s + # ========================================================= # Armada components # ========================================================= @@ -198,6 +239,33 @@ services: ARMADA_SCHEDULERAPICONNECTION_ARMADAURL: scheduler:50052 command: ./server --config /config/config.yaml + # Second API server instance, backed by the same scheduler/pulsar/redis/postgres as `server`, + # but with OIDC auth enabled (config-auth.yaml). Used only by the rbac test suite, so every + # other suite's unauthenticated connection to `server` is unaffected. + server-auth: + <<: *component + container_name: server-auth + image: ${ARMADA_IMAGE:-gresearch/armada-bundle}:${ARMADA_IMAGE_TAG:-latest} + ports: + - "50061:50051" + - "8091:8081" + depends_on: + lookout-migration: {condition: service_completed_successfully} + pulsar: {condition: service_healthy} + redis: {condition: service_healthy} + keycloak: {condition: service_healthy} + volumes: + - ../server/config-auth.yaml:/config/config.yaml:ro + environment: + ARMADA_EVENTSAPIREDIS_ADDRS: redis:6379 + ARMADA_REDIS_ADDRS: redis:6379 + ARMADA_POSTGRES_CONNECTION_HOST: postgres + ARMADA_QUERYAPI_POSTGRES_CONNECTION_HOST: postgres + ARMADA_PULSAR_URL: pulsar://pulsar:6650 + ARMADA_SCHEDULERAPICONNECTION_ARMADAURL: scheduler:50052 + ARMADA_AUTH_OPENIDAUTH_PROVIDERURL: http://keycloak:8180/realms/armada + command: ./server --config /config/config.yaml + executor: <<: *component container_name: executor diff --git a/_local/keycloak/import/armada-realm.json b/_local/keycloak/import/armada-realm.json index 0a4d731e80b..382316d81a5 100644 --- a/_local/keycloak/import/armada-realm.json +++ b/_local/keycloak/import/armada-realm.json @@ -102,6 +102,72 @@ "offline_access", "microprofile-jwt" ] + }, + { + "clientId": "armada-user", + "name": "Armada User Service", + "description": "Service account for Armada Users", + "enabled": true, + "publicClient": false, + "standardFlowEnabled": false, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": true, + "authorizationServicesEnabled": false, + "protocol": "openid-connect", + "bearerOnly": false, + "consentRequired": false, + "clientAuthenticatorType": "client-secret", + "secret": "user-secret", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "attributes": { + "use.refresh.tokens": "false", + "client_credentials.use_refresh_token": "false" + }, + "fullScopeAllowed": true, + "nodeReRegistrationTimeout": -1, + "defaultClientScopes": ["web-origins", "profile", "roles", "email"], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, + { + "clientId": "armada-admin", + "name": "Armada Admin Service", + "description": "Service account for Armada Admins", + "enabled": true, + "publicClient": false, + "standardFlowEnabled": false, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": false, + "serviceAccountsEnabled": true, + "authorizationServicesEnabled": false, + "protocol": "openid-connect", + "bearerOnly": false, + "consentRequired": false, + "clientAuthenticatorType": "client-secret", + "secret": "admin-secret", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "attributes": { + "use.refresh.tokens": "false", + "client_credentials.use_refresh_token": "false" + }, + "fullScopeAllowed": true, + "nodeReRegistrationTimeout": -1, + "defaultClientScopes": ["web-origins", "profile", "roles", "email"], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] } ], "clientScopes": [ @@ -239,6 +305,40 @@ "realmRoles": ["default-roles-armada"], "groups": ["/admins"] }, + { + "username": "executor", + "enabled": true, + "email": "executor@example.com", + "firstName": "Executor", + "lastName": "User", + "emailVerified": true, + "credentials": [ + { + "type": "password", + "value": "executor", + "temporary": false + } + ], + "realmRoles": ["default-roles-armada"], + "groups": ["/executors"] + }, + { + "username": "user", + "enabled": true, + "email": "user@example.com", + "firstName": "User", + "lastName": "User", + "emailVerified": true, + "credentials": [ + { + "type": "password", + "value": "user", + "temporary": false + } + ], + "realmRoles": ["default-roles-armada"], + "groups": ["/users"] + }, { "username": "service-account-armada-executor", "enabled": true, @@ -247,6 +347,26 @@ "lastName": "Executor", "emailVerified": true, "serviceAccountClientId": "armada-executor", + "groups": ["/executors"] + }, + { + "username": "service-account-armada-user", + "enabled": true, + "email": "user@armada.local", + "firstName": "Service Account", + "lastName": "User", + "emailVerified": true, + "serviceAccountClientId": "armada-user", + "groups": ["/users"] + }, + { + "username": "service-account-armada-admin", + "enabled": true, + "email": "admin-service@armada.local", + "firstName": "Service Account", + "lastName": "Admin", + "emailVerified": true, + "serviceAccountClientId": "armada-admin", "groups": ["/admins"] } ], diff --git a/_local/queues/e2e-test-queue.yaml b/_local/queues/e2e-test-queue.yaml new file mode 100644 index 00000000000..dcefbff0a42 --- /dev/null +++ b/_local/queues/e2e-test-queue.yaml @@ -0,0 +1,4 @@ +apiVersion: armadaproject.io/v1beta1 +kind: Queue +name: e2e-test-queue +priorityFactor: 1.0 diff --git a/_local/rbac-queues/rbac-fixture-plain.yaml b/_local/rbac-queues/rbac-fixture-plain.yaml new file mode 100644 index 00000000000..9066f24f274 --- /dev/null +++ b/_local/rbac-queues/rbac-fixture-plain.yaml @@ -0,0 +1,4 @@ +apiVersion: armadaproject.io/v1beta1 +kind: Queue +name: rbac-fixture-plain +priorityFactor: 1.0 diff --git a/_local/rbac-queues/rbac-fixture-restricted.yaml b/_local/rbac-queues/rbac-fixture-restricted.yaml new file mode 100644 index 00000000000..dffc1e00938 --- /dev/null +++ b/_local/rbac-queues/rbac-fixture-restricted.yaml @@ -0,0 +1,10 @@ +apiVersion: armadaproject.io/v1beta1 +kind: Queue +name: rbac-fixture-restricted +priorityFactor: 1.0 +permissions: + - subjects: + - name: users + kind: Group + verbs: + - submit diff --git a/_local/server/config-auth.yaml b/_local/server/config-auth.yaml index a22f162a5ce..418e1964ac9 100644 --- a/_local/server/config-auth.yaml +++ b/_local/server/config-auth.yaml @@ -34,9 +34,13 @@ auth: delete_retry_policy: ["admins"] delete_queue: ["admins"] cancel_any_jobs: ["admins"] + preempt_any_jobs: ["admins"] reprioritize_any_jobs: ["admins"] watch_all_events: ["admins"] execute_jobs: ["admins", "executors"] + cordon_queue: ["admins"] + cordon_nodes: ["admins"] + update_executor_settings: ["admins"] eventsApiRedis: addrs: - localhost:6379 diff --git a/internal/testsuite/app.go b/internal/testsuite/app.go index 3e8c6c59677..39a7d52e283 100644 --- a/internal/testsuite/app.go +++ b/internal/testsuite/app.go @@ -317,9 +317,23 @@ func (a *App) RunTests(ctx context.Context, testSpecs []*api.TestSpec) (*TestSui wg.Add(len(testSpecs)) for i, testSpec := range testSpecs { i := i + apiConnectionDetails := a.Params.ApiConnectionDetails + if testSpec.AuthContext != "" { + resolved, err := client.ResolveNamedContext(testSpec.AuthContext) + if err != nil { + report := NewTestCaseReport(testSpec) + report.Finish = report.Start + report.FailureReason = fmt.Sprintf("failed to resolve authContext %q: %s", testSpec.AuthContext, err) + report.Out = &bytes.Buffer{} + rv.TestCaseReports[i] = report + wg.Done() + continue + } + apiConnectionDetails = resolved + } testRunner := TestRunner{ Out: a.Out, - apiConnectionDetails: a.Params.ApiConnectionDetails, + apiConnectionDetails: apiConnectionDetails, testSpec: testSpec, eventLogger: eventLogger, } diff --git a/internal/testsuite/eventwatcher/eventwatcher.go b/internal/testsuite/eventwatcher/eventwatcher.go index cbbc73ac568..35a66ba8366 100644 --- a/internal/testsuite/eventwatcher/eventwatcher.go +++ b/internal/testsuite/eventwatcher/eventwatcher.go @@ -88,7 +88,9 @@ func (srv *EventWatcher) Run(ctx context.Context) error { if err == nil || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { return err } - if status.Code(err) == codes.Canceled { + if status.Code(err) == codes.Canceled || status.Code(err) == codes.PermissionDenied { + // Permission denials are permanent for the lifetime of a test (the caller's + // identity doesn't change mid-run), so retrying would only waste the backoff budget. return err } diff --git a/internal/testsuite/testrunner.go b/internal/testsuite/testrunner.go index f0fd7982f96..804a6e86e1a 100644 --- a/internal/testsuite/testrunner.go +++ b/internal/testsuite/testrunner.go @@ -11,6 +11,8 @@ import ( "github.com/pkg/errors" "golang.org/x/exp/maps" "golang.org/x/sync/errgroup" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" @@ -26,6 +28,26 @@ import ( "github.com/armadaproject/armada/pkg/client" ) +// checkExpectedError reconciles a call's outcome against testSpec.ExpectErrorCode. +// A nil err is always passed through unchanged: at most one call site is "the action under +// test" for any given negative RBAC test, and every other site along the way (queue setup, +// submit, teardown, ...) is a precondition that's expected to genuinely succeed. Run() uses +// expectedErrorObserved to separately verify that the expected denial happened somewhere by +// the end of the test, rather than baking that check into every call site. +// If ExpectErrorCode is unset, err is returned unchanged (today's behavior: any error fails +// the test). If set and err is non-nil: a matching status code is the expected, benign outcome +// (returns nil); a non-matching code is a real failure (wrapped and returned). +func checkExpectedError(testSpec *api.TestSpec, err error) error { + if err == nil || testSpec.GetExpectErrorCode() == 0 { + return err + } + wantCode := codes.Code(testSpec.GetExpectErrorCode()) + if status.Code(err) != wantCode { + return errors.Wrapf(err, "expected call to fail with code %s", wantCode) + } + return nil +} + type TestRunner struct { Out io.Writer apiConnectionDetails *client.ApiConnectionDetails @@ -70,6 +92,20 @@ func (srv *TestRunner) Run(ctx context.Context) (err error) { } }() + // expectedErrorObserved is set by whichever call site actually produces the + // ExpectErrorCode denial this test is checking for (at most one of setup/update/submit/ + // teardown/action ever will, per test). Registered before the report defer above so it + // runs first (defers are LIFO) and can still correct err before the report captures it. + var expectedErrorObserved bool + defer func() { + if err == nil && srv.testSpec.GetExpectErrorCode() != 0 && !expectedErrorObserved { + err = errors.Errorf( + "expected a call to fail with code %s, but the test completed successfully", + codes.Code(srv.testSpec.GetExpectErrorCode()), + ) + } + }() + // Optional timeout var cancel context.CancelFunc timeout := protoutil.ToStdDuration(srv.testSpec.Timeout) @@ -81,22 +117,43 @@ func (srv *TestRunner) Run(ctx context.Context) (err error) { defer cancel() // Create and (optionally) update the queue(s) under test. - queueNames, err := queue.RunSetup(ctx, srv.testSpec, srv.apiConnectionDetails, out) - if err != nil { + queueNames, setupErr := queue.RunSetup(ctx, srv.testSpec, srv.apiConnectionDetails, out) + if err = checkExpectedError(srv.testSpec, setupErr); err != nil { return err } - if err = queue.RunUpdate(ctx, queueNames, srv.testSpec, srv.apiConnectionDetails, out); err != nil { + if setupErr != nil { + // The expected failure already occurred (e.g. create_queue denied); nothing was + // created, so there's nothing left to do or tear down. + expectedErrorObserved = true + return nil + } + updateErr := queue.RunUpdate(ctx, queueNames, srv.testSpec, srv.apiConnectionDetails, out) + if err = checkExpectedError(srv.testSpec, updateErr); err != nil { return err } + if updateErr != nil { + // The expected failure already occurred (e.g. update_queue denied against a queue this + // test doesn't own); skip teardown since this test didn't create the queue it targeted. + expectedErrorObserved = true + return nil + } // (deferred): always delete the queue(s) once the test finishes. defer func() { - if teardownErr := queue.RunTeardown(queueNames, srv.testSpec, srv.apiConnectionDetails, out); teardownErr != nil { - fmt.Fprintf(out, "warning: queue teardown failed: %s\n", teardownErr) + teardownErr := queue.RunTeardown(queueNames, srv.testSpec, srv.apiConnectionDetails, out) + if teardownErr == nil { + return + } + if checkedErr := checkExpectedError(srv.testSpec, teardownErr); checkedErr != nil { + fmt.Fprintf(out, "warning: queue teardown failed: %s\n", checkedErr) if err == nil { - err = teardownErr + err = checkedErr } + return } + // teardownErr matched ExpectErrorCode (e.g. delete_queue denied) -- the expected + // denial for this test. + expectedErrorObserved = true }() // Pure queue tests submit no jobs, so skip the job-submission block below and @@ -110,9 +167,16 @@ func (srv *TestRunner) Run(ctx context.Context) (err error) { // Submit jobs. All jobs must be submitted before proceeding since we need the job ids. sbmtr := submitter.NewSubmitterFromTestSpec(srv.apiConnectionDetails, srv.testSpec, out) - if err = sbmtr.Run(ctx); err != nil { + submitErr := sbmtr.Run(ctx) + if err = checkExpectedError(srv.testSpec, submitErr); err != nil { return err } + if submitErr != nil { + // The expected failure already occurred (e.g. submit denied); no jobs exist to watch, + // act on, or assert against. + expectedErrorObserved = true + return nil + } jobIds := sbmtr.JobIds() jobIdMap := make(map[string]bool) for _, jobId := range jobIds { @@ -205,16 +269,38 @@ func (srv *TestRunner) Run(ctx context.Context) (err error) { // Watch for ingress events and try to download from any ingresses found. g.Go(func() error { return eventwatcher.GetFromIngresses(ctx, ingressCh) }) + if srv.testSpec.GetExpectErrorCode() != 0 { + // Negative RBAC tests targeting the action/watch goroutines (cancel, preempt, + // reprioritize, GetJobSetEvents) deliberately leave ExpectedEvents empty, since + // what's under test is whether the RPC was denied, not what events followed it -- a + // short ExpectedEvents list (e.g. just "submitted") would let AssertEvents return + // success before the denied action even runs, racing the very thing we're testing. + // An empty ExpectedEvents list instead blocks AssertEvents until ctx is cancelled, + // which happens automatically once the denied RPC returns and the errgroup cancels + // its shared ctx -- or once this test's own timeout elapses if the RPC was (wrongly) + // allowed through. So AssertEvents's own result is meaningless here; reconcile the + // aggregated error from every goroutine in the group against ExpectErrorCode instead. + eventwatcher.AssertEvents(ctx, assertCh, maps.Clone(jobIdMap), srv.testSpec.ExpectedEvents) //nolint:errcheck + cancel() + groupErr := g.Wait() + if checkedErr := checkExpectedError(srv.testSpec, groupErr); checkedErr != nil { + return checkedErr + } + if groupErr != nil { + expectedErrorObserved = true + } + return nil + } + // Assert that we get the right events for each job. // Returns once we've received all events or when ctx is cancelled. - if err = eventwatcher.AssertEvents(ctx, assertCh, maps.Clone(jobIdMap), srv.testSpec.ExpectedEvents); err != nil { + if assertErr := eventwatcher.AssertEvents(ctx, assertCh, maps.Clone(jobIdMap), srv.testSpec.ExpectedEvents); assertErr != nil { cancel() groupErr := g.Wait() if groupErr != nil { - return errors.Errorf("%s: %s", err, groupErr) - } else { - return err + return errors.Errorf("%s: %s", assertErr, groupErr) } + return assertErr } // Assert queue state now that the jobs have finished. (used for GetActiveQueues) diff --git a/magefiles/ci.go b/magefiles/ci.go index c4d980ec785..fff93f2944c 100644 --- a/magefiles/ci.go +++ b/magefiles/ci.go @@ -14,13 +14,34 @@ import ( ) func createQueue() error { - out, err := runArmadaCtl("create", "queue", "e2e-test-queue") - // check if err text contains "already exists" and ignore if it does - if err != nil && !strings.Contains(out, "already exists") { - fmt.Println(out) + return createQueuesFromDir("", "_local/queues") +} + +// createRbacFixtureQueues bootstraps the queues the rbac test suite's "without permission" cases +// target, using the rbac-admin context (server-auth, on the containerized full.yaml stack) since +// armada-user itself lacks create_queue. rbac-fixture-restricted grants the Keycloak "users" +// group submit-only, so armada-user's negative tests (cancel/reprioritize/watch without +// permission) can submit a job and prove those specific actions -- not queue ownership -- are +// what's denied. +func createRbacFixtureQueues() error { + return createQueuesFromDir("rbac-admin", "_local/rbac-queues") +} + +// createQueuesFromDir runs armadactl to create every queue fixture (*.yaml) in dir against the +// given armadactl context, tolerating "already exists" so repeated CI runs against a stack that +// wasn't torn down don't fail. +func createQueuesFromDir(context string, dir string) error { + files, err := filepath.Glob(filepath.Join(dir, "*.yaml")) + if err != nil { return err } - + for _, file := range files { + out, err := runArmadaCtlContext(context, "create", "-f", file) + if err != nil && !strings.Contains(out, "already exists") { + fmt.Println(out) + return err + } + } return nil } @@ -38,7 +59,7 @@ func TestSuite() error { timeTakenTestSuite := time.Now() suites := []string{ - "basic", "categorization", "preemption", "reprioritization", "queue", + "basic", "categorization", "preemption", "reprioritization", "queue", "rbac", "testsuite/testcases/node/node_cancel_by_name_1x5.yaml", "testsuite/testcases/node/node_preempt_by_name_1x5.yaml", } @@ -81,6 +102,7 @@ func CheckForArmadaRunning() error { // TODO Make a good check to confirm the system is ready, such as seeing armadactl get executors return a value mg.Deps(CheckSchedulerReady) mg.Deps(createQueue) + mg.Deps(createRbacFixtureQueues) // Set high to take compile time into account timeout := time.After(2 * time.Minute) @@ -142,9 +164,19 @@ func CheckDockerContainerRunning(containerName string, expectedLogRegex string) } func runArmadaCtl(args ...string) (string, error) { + return runArmadaCtlContext("", args...) +} + +// runArmadaCtlContext is runArmadaCtl with an explicit armadactl context override (e.g. +// "rbac-admin"), needed to bootstrap the rbac suite's fixture queues against server-auth rather +// than the default unauthenticated "server" connection every other suite uses. +func runArmadaCtlContext(context string, args ...string) (string, error) { armadaCtlArgs := []string{ "--config", "_local/.armadactl.yaml", } + if context != "" { + armadaCtlArgs = append(armadaCtlArgs, "--context", context) + } armadaCtlArgs = append(armadaCtlArgs, args...) outBytes, err := exec.Command(findOrBuildArmadaCtl(), armadaCtlArgs...).CombinedOutput() out := string(outBytes) diff --git a/magefiles/dev.go b/magefiles/dev.go index d7291a4ca97..f4609b430a8 100644 --- a/magefiles/dev.go +++ b/magefiles/dev.go @@ -161,9 +161,43 @@ func (Dev) Down() error { // ordered ahead of the components, so no separate init step is needed. func (Dev) Full() error { mg.Deps(mg.F(goreleaserMinimalRelease, "bundle", "lookout-bundle"), Kind) + if err := ensureEtcHostsEntry("keycloak", "127.0.0.1"); err != nil { + return err + } + // keycloak has its own compose healthcheck, so --wait already blocks until it (and every + // other service, including server-auth which depends on it) is ready. return sh.RunV("docker", "compose", "-f", fullComposeFile, "up", "-d", "--wait") } +// ensureEtcHostsEntry makes the literal hostname host resolve to ip from the host machine, by +// appending an /etc/hosts entry if one isn't already present. full.yaml's keycloak service pins +// KC_HOSTNAME=keycloak so its OIDC issuer is one fixed string regardless of caller; other +// containers reach it as "keycloak" via Docker's own DNS, so the host (where armadactl and the +// test runner run) needs the same literal hostname to resolve, to satisfy go-oidc's requirement +// that the issuer used for discovery and a token's iss claim match exactly. +func ensureEtcHostsEntry(host, ip string) error { + data, err := os.ReadFile("/etc/hosts") + if err != nil { + return fmt.Errorf("reading /etc/hosts: %w", err) + } + for _, line := range strings.Split(string(data), "\n") { + fields := strings.Fields(line) + if len(fields) >= 2 && fields[0] == ip { + for _, name := range fields[1:] { + if name == host { + return nil + } + } + } + } + fmt.Printf("Adding %q entry to /etc/hosts (sudo required)...\n", ip+" "+host) + cmd := exec.Command("sudo", "tee", "-a", "/etc/hosts") + cmd.Stdin = strings.NewReader("\n" + ip + " " + host + "\n") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + // FullDown stops the containerized full stack and tears down the Kind cluster. func (Dev) FullDown() error { if err := sh.RunV("docker", "compose", "-f", fullComposeFile, "down", "-v"); err != nil { diff --git a/pkg/api/testspec.pb.go b/pkg/api/testspec.pb.go index 9036ffff006..209e9e2731f 100644 --- a/pkg/api/testspec.pb.go +++ b/pkg/api/testspec.pb.go @@ -139,6 +139,13 @@ type TestSpec struct { TriggerEvent string `protobuf:"bytes,20,opt,name=trigger_event,json=triggerEvent,proto3" json:"triggerEvent,omitempty"` // Optional queue lifecycle phases. QueueConfig *QueueConfig `protobuf:"bytes,21,opt,name=queue_config,json=queueConfig,proto3" json:"queueConfig,omitempty"` + // Named armadactl context (see client.ApiConnectionDetails) to authenticate this test's + // API calls with. If empty, falls back to the connection details the suite was invoked with. + AuthContext string `protobuf:"bytes,22,opt,name=auth_context,json=authContext,proto3" json:"authContext,omitempty"` + // If non-zero, the test expects job submission/cancellation/reprioritization or queue + // create/update/delete to fail with this gRPC status code (see google.golang.org/grpc/codes) + // rather than succeed. Mutually exclusive with expecting expected_events to be observed. + ExpectErrorCode int32 `protobuf:"varint,23,opt,name=expect_error_code,json=expectErrorCode,proto3" json:"expectErrorCode,omitempty"` } func (m *TestSpec) Reset() { *m = TestSpec{} } @@ -321,6 +328,20 @@ func (m *TestSpec) GetQueueConfig() *QueueConfig { return nil } +func (m *TestSpec) GetAuthContext() string { + if m != nil { + return m.AuthContext + } + return "" +} + +func (m *TestSpec) GetExpectErrorCode() int32 { + if m != nil { + return m.ExpectErrorCode + } + return 0 +} + type NodeCancelConfig struct { Request *NodeCancelRequest `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` // value of the armadaproject.io/node-pool label used to resolve the target node at runtime @@ -657,84 +678,87 @@ func init() { func init() { proto.RegisterFile("pkg/api/testspec.proto", fileDescriptor_38d601305b414287) } var fileDescriptor_38d601305b414287 = []byte{ - // 1222 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x56, 0x4f, 0x6f, 0x1b, 0x45, - 0x14, 0xcf, 0x26, 0x6d, 0xe2, 0x3c, 0xc7, 0xf6, 0x66, 0x9c, 0x3f, 0xdb, 0x16, 0x6c, 0xcb, 0x07, - 0x08, 0x52, 0x65, 0xa3, 0x82, 0x10, 0x50, 0x10, 0xd8, 0xa9, 0x0b, 0xae, 0x9a, 0xc4, 0xd8, 0x91, - 0x28, 0x45, 0x68, 0xb5, 0xb6, 0x5f, 0xb7, 0x1b, 0xbc, 0x3b, 0xdb, 0xdd, 0x71, 0x4a, 0xfb, 0x15, - 0xb8, 0x20, 0x8e, 0x88, 0x4f, 0xc0, 0x27,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 0x6d, 0xd7, 0x13, - 0x4f, 0xa7, 0xc3, 0xc6, 0x88, 0xfb, 0x4d, 0x27, 0xf2, 0x9d, 0xb1, 0x13, 0x46, 0xfc, 0x0c, 0x47, - 0x42, 0x7d, 0x35, 0xd5, 0xff, 0xec, 0x6f, 0xab, 0x3b, 0x2d, 0x02, 0x7a, 0x92, 0x6e, 0x74, 0x79, - 0xa3, 0x15, 0x7a, 0xc3, 0x75, 0x32, 0xf8, 0xbd, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x11, 0x15, - 0xa1, 0xb8, 0x60, 0x0b, 0x00, 0x00, + // 1274 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x96, 0xcf, 0x6e, 0x1b, 0xd5, + 0x17, 0xc7, 0x33, 0x49, 0x93, 0x38, 0xc7, 0xb1, 0x3d, 0xb9, 0xce, 0x9f, 0x69, 0xfb, 0xfb, 0xd9, + 0x96, 0x17, 0x60, 0xa4, 0xca, 0x46, 0x05, 0x21, 0xa0, 0x20, 0xb0, 0x5d, 0x17, 0x5c, 0x35, 0x89, + 0xb1, 0x23, 0x51, 0x8a, 0xd0, 0x68, 0x6c, 0x9f, 0x4e, 0x27, 0x78, 0xe6, 0x4e, 0x67, 0xae, 0xd3, + 0x3f, 0xaf, 0xc0, 0x06, 0xb1, 0x44, 0x3c, 0x01, 0x4f, 0xc2, 0xb2, 0x42, 0x2c, 0x58, 0x59, 0xa8, + 0xdd, 0xf9, 0x29, 0xd0, 0x9c, 0x7b, 0x27, 0xbe, 0x76, 0x16, 0xec, 0x58, 0xb0, 0xf4, 0xe7, 0x7b, + 0xce, 0x99, 0x33, 0xf7, 0x7b, 0x7c, 0xee, 0xc0, 0x61, 0xf8, 0xbd, 0xdb, 0x70, 0x42, 0xaf, 0x21, + 0x30, 0x16, 0x71, 0x88, 0xa3, 0x7a, 0x18, 0x71, 0xc1, 0xd9, 0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b, 0xae, 0x27, 0x9e, 0x4c, 0x87, 0xf5, 0x11, 0xf7, 0x1b, 0x4e, 0xe4, 0x3b, 0x63, 0x27, + 0x8c, 0xf8, 0x39, 0x8e, 0x84, 0xfa, 0xd5, 0x50, 0x1f, 0xd6, 0xbf, 0xae, 0xef, 0x37, 0x09, 0xf4, + 0xa4, 0x5c, 0xef, 0xf2, 0x7a, 0x33, 0xf4, 0x86, 0x5b, 0x64, 0xf0, 0x7b, 0x7f, 0x07, 0x00, 0x00, + 0xff, 0xff, 0x32, 0x83, 0xc3, 0xa5, 0xe9, 0x0b, 0x00, 0x00, } func (m *TestSpec) Marshal() (dAtA []byte, err error) { @@ -757,6 +781,22 @@ func (m *TestSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ExpectErrorCode != 0 { + i = encodeVarintTestspec(dAtA, i, uint64(m.ExpectErrorCode)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb8 + } + if len(m.AuthContext) > 0 { + i -= len(m.AuthContext) + copy(dAtA[i:], m.AuthContext) + i = encodeVarintTestspec(dAtA, i, uint64(len(m.AuthContext))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb2 + } if m.QueueConfig != nil { { size, err := m.QueueConfig.MarshalToSizedBuffer(dAtA[:i]) @@ -1317,6 +1357,13 @@ func (m *TestSpec) Size() (n int) { l = m.QueueConfig.Size() n += 2 + l + sovTestspec(uint64(l)) } + l = len(m.AuthContext) + if l > 0 { + n += 2 + l + sovTestspec(uint64(l)) + } + if m.ExpectErrorCode != 0 { + n += 2 + sovTestspec(uint64(m.ExpectErrorCode)) + } return n } @@ -2057,6 +2104,57 @@ func (m *TestSpec) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 22: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuthContext", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTestspec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTestspec + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTestspec + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuthContext = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 23: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExpectErrorCode", wireType) + } + m.ExpectErrorCode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTestspec + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExpectErrorCode |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTestspec(dAtA[iNdEx:]) diff --git a/pkg/api/testspec.proto b/pkg/api/testspec.proto index 241888c7836..ec8be7d9229 100644 --- a/pkg/api/testspec.proto +++ b/pkg/api/testspec.proto @@ -73,6 +73,13 @@ message TestSpec { string trigger_event = 20; // Optional queue lifecycle phases. QueueConfig queue_config = 21; + // Named armadactl context (see client.ApiConnectionDetails) to authenticate this test's + // API calls with. If empty, falls back to the connection details the suite was invoked with. + string auth_context = 22; + // If non-zero, the test expects job submission/cancellation/reprioritization or queue + // create/update/delete to fail with this gRPC status code (see google.golang.org/grpc/codes) + // rather than succeed. Mutually exclusive with expecting expected_events to be observed. + int32 expect_error_code = 23; } message NodeCancelConfig { diff --git a/pkg/client/command_line.go b/pkg/client/command_line.go index c142480bc14..dde013fd963 100644 --- a/pkg/client/command_line.go +++ b/pkg/client/command_line.go @@ -183,6 +183,22 @@ func ExtractConfigurationContexts() []string { return contexts } +// ResolveNamedContext resolves a named context (as defined under "contexts" in the config loaded +// into viper) directly into ApiConnectionDetails, without going through the "currentContext" / +// "armadaUrl" command-line flags. Hence, this function must be called after loading config into +// viper, e.g., by calling LoadCommandlineArgsFromConfigFile. +func ResolveNamedContext(contextName string) (*ApiConnectionDetails, error) { + subTree := viper.Sub(fmt.Sprintf("contexts.%s", contextName)) + if subTree == nil { + return nil, fmt.Errorf("context %s not found under contexts within the Armada config", contextName) + } + apiConnectionDetails := &ApiConnectionDetails{} + if err := subTree.Unmarshal(apiConnectionDetails); err != nil { + return nil, err + } + return apiConnectionDetails, nil +} + // ExtractCommandlineArmadaApiConnectionDetails extracts Armada server connection details from the // config loaded into viper. Hence, this function must be called after loading config into viper, // e.g., by calling LoadCommandlineArgsFromConfigFile. @@ -191,11 +207,10 @@ func ExtractCommandlineArmadaApiConnectionDetails() (*ApiConnectionDetails, erro var err error if context := viper.GetString("currentContext"); context != "" { - subTree := viper.Sub(fmt.Sprintf("contexts.%s", context)) - if subTree == nil { - return nil, fmt.Errorf("context %s not found under contexts within the Armada config", context) + apiConnectionDetails, err = ResolveNamedContext(context) + if err != nil { + return nil, err } - err = subTree.Unmarshal(apiConnectionDetails) if viper.GetString("armadaUrl") != defaultArmadaConnectionUrl { apiConnectionDetails.ArmadaUrl = viper.GetString("armadaUrl") } diff --git a/testsuite/testcases/rbac/rbac_cancel_with_global_permission.yaml b/testsuite/testcases/rbac/rbac_cancel_with_global_permission.yaml new file mode 100644 index 00000000000..1a7eb6aafc1 --- /dev/null +++ b/testsuite/testcases/rbac/rbac_cancel_with_global_permission.yaml @@ -0,0 +1,40 @@ +# RBAC: a principal with the global cancel_any_jobs permission (armada-admin) can cancel jobs +# in a queue it doesn't own. +queue: rbac-cancel-with-perm +authContext: rbac-admin +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: cancel-by-id + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "sleep" + - "100s" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +action: ACTION_CANCEL +selection: SELECTION_BY_ID +timeout: "100s" +expectedEvents: + - submitted: + - cancelled: +queueConfig: + setup: + # An explicit non-admin owner stops CreateQueue's auto-add-owner default (which would + # otherwise make armada-admin the queue owner and let ownership -- not cancel_any_jobs -- + # explain a successful cancel). + queueSpec: + userOwners: ["nobody"] diff --git a/testsuite/testcases/rbac/rbac_cancel_without_permission.yaml b/testsuite/testcases/rbac/rbac_cancel_without_permission.yaml new file mode 100644 index 00000000000..f9b8ae350ba --- /dev/null +++ b/testsuite/testcases/rbac/rbac_cancel_without_permission.yaml @@ -0,0 +1,35 @@ +# RBAC: a principal without cancel_any_jobs and without a queue-level cancel grant (armada-user) +# cannot cancel a job, even one it submitted itself. Targets the shared rbac-fixture-restricted +# queue (bootstrapped by CI under the admin identity, granting the /users group submit-only), +# so submission succeeds via the queue-level grant but the subsequent cancel is denied. +# ExpectedEvents is deliberately empty -- see testrunner.go's Run() for why a short list would +# race the denied action. +queue: rbac-fixture-restricted +authContext: rbac-user +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: cancel-by-id + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "sleep" + - "100s" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +action: ACTION_CANCEL +selection: SELECTION_BY_ID +timeout: "30s" +expectErrorCode: 7 # PERMISSION_DENIED diff --git a/testsuite/testcases/rbac/rbac_get_jobset_events_with_permission.yaml b/testsuite/testcases/rbac/rbac_get_jobset_events_with_permission.yaml new file mode 100644 index 00000000000..a693680c17a --- /dev/null +++ b/testsuite/testcases/rbac/rbac_get_jobset_events_with_permission.yaml @@ -0,0 +1,37 @@ +# RBAC: a principal with the global watch_all_events permission (armada-admin) can watch a job +# set's events via GetJobSetEvents in a queue it doesn't own. +queue: rbac-watch-with-perm +authContext: rbac-admin +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: sleep + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "ls" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +timeout: "100s" +expectedEvents: + - submitted: + - succeeded: +queueConfig: + setup: + # An explicit non-admin owner stops CreateQueue's auto-add-owner default (which would + # otherwise make armada-admin the queue owner and let ownership -- not watch_all_events -- + # explain successfully watching events). + queueSpec: + userOwners: ["nobody"] diff --git a/testsuite/testcases/rbac/rbac_get_jobset_events_without_permission.yaml b/testsuite/testcases/rbac/rbac_get_jobset_events_without_permission.yaml new file mode 100644 index 00000000000..725a8853f87 --- /dev/null +++ b/testsuite/testcases/rbac/rbac_get_jobset_events_without_permission.yaml @@ -0,0 +1,34 @@ +# RBAC: a principal without watch_all_events and without a queue-level watch grant (armada-user) +# cannot watch job-set events via GetJobSetEvents, even for a job it submitted itself. Targets +# the shared rbac-fixture-restricted queue (bootstrapped by CI under the admin identity, granting +# the /users group submit-only), so submission succeeds via the queue-level grant but the +# GetJobSetEvents stream that Run() opens to watch for events is denied. +# ExpectedEvents is deliberately empty -- see testrunner.go's Run() for why a short list would +# race the denied watch (eventwatcher.EventWatcher.Run returns PermissionDenied immediately, +# without retrying, cancelling the errgroup's shared ctx). +queue: rbac-fixture-restricted +authContext: rbac-user +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: sleep + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "ls" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +timeout: "30s" +expectErrorCode: 7 # PERMISSION_DENIED diff --git a/testsuite/testcases/rbac/rbac_reprioritize_with_global_permission.yaml b/testsuite/testcases/rbac/rbac_reprioritize_with_global_permission.yaml new file mode 100644 index 00000000000..7e1fb72e6f5 --- /dev/null +++ b/testsuite/testcases/rbac/rbac_reprioritize_with_global_permission.yaml @@ -0,0 +1,41 @@ +# RBAC: a principal with the global reprioritize_any_jobs permission (armada-admin) can +# reprioritize jobs in a queue it doesn't own. +queue: rbac-reprioritize-with-perm +authContext: rbac-admin +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: reprioritize-by-id + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "sleep" + - "100s" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +action: ACTION_REPRIORITIZE +selection: SELECTION_BY_ID +newPriority: 100 +timeout: "100s" +expectedEvents: + - submitted: + - reprioritized: +queueConfig: + setup: + # An explicit non-admin owner stops CreateQueue's auto-add-owner default (which would + # otherwise make armada-admin the queue owner and let ownership -- not + # reprioritize_any_jobs -- explain a successful reprioritize). + queueSpec: + userOwners: ["nobody"] diff --git a/testsuite/testcases/rbac/rbac_reprioritize_without_permission.yaml b/testsuite/testcases/rbac/rbac_reprioritize_without_permission.yaml new file mode 100644 index 00000000000..1df91223524 --- /dev/null +++ b/testsuite/testcases/rbac/rbac_reprioritize_without_permission.yaml @@ -0,0 +1,37 @@ +# RBAC: a principal without reprioritize_any_jobs and without a queue-level reprioritize grant +# (armada-user) cannot reprioritize a job, even one it submitted itself. Targets the shared +# rbac-fixture-restricted queue (bootstrapped by CI under the admin identity, granting the +# /users group submit-only), so submission succeeds via the queue-level grant but the +# subsequent reprioritize is denied. +# ExpectedEvents is deliberately empty -- see testrunner.go's Run() for why a short list would +# race the denied action. +queue: rbac-fixture-restricted +authContext: rbac-user +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: reprioritize-by-id + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "sleep" + - "100s" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +action: ACTION_REPRIORITIZE +selection: SELECTION_BY_ID +newPriority: 100 +timeout: "30s" +expectErrorCode: 7 # PERMISSION_DENIED diff --git a/testsuite/testcases/rbac/rbac_submit_with_global_permission.yaml b/testsuite/testcases/rbac/rbac_submit_with_global_permission.yaml new file mode 100644 index 00000000000..6655973c179 --- /dev/null +++ b/testsuite/testcases/rbac/rbac_submit_with_global_permission.yaml @@ -0,0 +1,37 @@ +# RBAC: a principal with the global submit_any_jobs permission (armada-admin) can submit to a +# queue it doesn't own. +queue: rbac-submit-with-perm +authContext: rbac-admin +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: sleep + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "ls" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +timeout: "100s" +expectedEvents: + - submitted: + - succeeded: +queueConfig: + setup: + # An explicit non-admin owner stops CreateQueue's auto-add-owner default (which would + # otherwise make armada-admin the queue owner and let ownership -- not submit_any_jobs -- + # explain a successful submit). + queueSpec: + userOwners: ["nobody"] diff --git a/testsuite/testcases/rbac/rbac_submit_without_permission.yaml b/testsuite/testcases/rbac/rbac_submit_without_permission.yaml new file mode 100644 index 00000000000..cb656818c0e --- /dev/null +++ b/testsuite/testcases/rbac/rbac_submit_without_permission.yaml @@ -0,0 +1,29 @@ +# RBAC: a principal without submit_any_jobs (armada-user) and without a queue-level submit +# grant cannot submit jobs. Targets the shared rbac-fixture-plain queue (bootstrapped by CI +# under the admin identity; this test must not create or delete it -- no queueConfig). +queue: rbac-fixture-plain +authContext: rbac-user +numBatches: 1 +batchSize: 1 +jobs: + - priority: 0 + namespace: personal-anonymous + podSpec: + terminationGracePeriodSeconds: 0 + restartPolicy: Never + containers: + - name: sleep + imagePullPolicy: IfNotPresent + image: alpine:3.20.0 + args: + - "ls" + resources: + limits: + memory: 25Mi + cpu: 100m + requests: + memory: 25Mi + cpu: 100m +--- +timeout: "30s" +expectErrorCode: 7 # PERMISSION_DENIED