tod build check-spec returns HTTP 406 for private build-spec imports #3309
Xander opened 6 hours ago

Environment

Reproduced on stock OneDev 17.2.3 with tod 4.5.0 and on the official 1dev/server:17.2.7 image with tod 4.6.0. The validator method is unchanged across 17.2.3 through 17.2.7 and upstream main as checked on December 5, 2026.

Steps to reproduce

  1. Create a private OneDev project named fixture-templates. Commit this .onedev-buildspec.yml to main:

    version: 46
    stepTemplates:
    - name: shared-template
      steps:
      - type: CheckoutStep
        name: checkout
        condition: SUCCESSFUL
        optional: false
        cloneCredential:
          type: DefaultCredential
    
  2. Create fixture-app. Add a job secret named templates_token on fixture-app containing a OneDev access token with code-read access to fixture-templates. Use OneDev’s default all-branches authorization rule for the secret.

  3. In a local clone of fixture-app, add this .onedev-buildspec.yml:

    version: 46
    imports:
    - projectPath: fixture-templates
      revision: main
      accessTokenSecret: templates_token
    
  4. Configure tod with a caller that has code-write permission on fixture-app and no direct access to fixture-templates. Run tod build check-spec from the clone.

Expected

The validator resolves the import using the authorized job secret and accepts the build spec.

Actual

POST /~api/tod/check-build-spec?project=fixture-app returns HTTP 406 at imports[0], and tod exits with status 1. The error indicates that JobAuthorizationContext.get() returned null while resolving the import token. A build spec without imports returns HTTP 200 on the same instance.

Root cause and suggested fix

TodResource.checkBuildSpec() pushes the project context and calls the build-spec validator without setting a JobAuthorizationContext. Import.getBuildSpec() expects that context when resolving the access-token secret. Normal job submission sets it before validating the spec.

A local test patch supplied a context for uncommitted YAML and changed the result from HTTP 406 to HTTP 200. It required code-write permission to resolve job secrets and kept branch-specific secrets unavailable without a trusted Git revision. The same test also confirmed that read-only callers could still validate specs without secret-backed imports.

1/1
Type
Bug
Priority
Normal
Assignee
Affected Versions
17.2.3, 17.2.7
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3309
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover