Inconsistent syntax check when definining multiple includes allows committing/executing invalid YAML

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

"Sibling-keywords" of include:-sub-keywords are not verified consistently. While the Pipeline Editor shows a schema warning, the general syntax check claims that everything is fine, and a pipeline that silently ignores the invalid keys is executed.

My examples below are very on the nose – a more insidious way for this to manifest is that you can do a typo and use project:include:files: rather than project:include:file: (notice the extra s) and not notice because your incorrect version just gets silently ignored/not included rather than reporting your syntax error.

Steps to reproduce

  1. Create new project
  2. Add test2.yml and test3.yml with a basic job in them:
    # replace X with 2 or 3 respectively
    jobX:
        script: echo X
  3. Add the following .gitlab-ci.yml:
    stages:
      - validate
      - test
      - build
      - deploy
    
    include:
      - component: $CI_SERVER_FQDN/components/opentofu/validate@2.6.1
        foobarnonexistant: 123
      - remote: 'https://gitlab.com/gl-demo-ultimate-mgrabowski/test/-/raw/main/test2.yml' # replace with your own project path
        integrity123: 'sha256-L3/GAoKaw0Arw6hDCKeKQlV1QPEgHYxGBHsH4zG1IY8='
      - project: 'gl-demo-ultimate-mgrabowski/test'
        file: 'test2.yml'
      - project: 'gl-demo-ultimate-mgrabowski/test'
        files: 'test3.yml'
        foobarnonexistant: 123
      - local: 'test3.yml'
        foobarnonexistant: 123
        inputs213:
          website: "My website"
      - local: test3.yml
        foobarnonexistant: 123
        rules123:
          - if: $INCLUDE_BUILDS == "true"
      - template: Bash.gitlab-ci.yml
        foobarnonexistant: 123
  4. Observe a pipeline being executed
  5. Go to Pipeline Editor
  6. Observe Pipeline syntax is correct. message
  7. Note multiple schema issues being shown by the linter
  8. Change any of the "top-level" include keywords (i.e. change component, project, local or template by adding an extra character to the word)
  9. Observe invalid syntax now being reported for these infractions
  10. Remove all includes but the project: one with files: 'test3.yml'
  11. Observe This GitLab CI configuration is invalid: include:include config contains unknown keys: files, foobarnonexistant. now being reported

Example Project

https://gitlab.com/gl-demo-ultimate-mgrabowski/zd-633570

What is the current bug behavior?

Parts of the syntax in include: statements are not properly validated and allow executing pipelines with invalid syntax by silently ignoring incorrect includes.

What is the expected correct behavior?

Incorrect include statements are reported as invalid YAML syntax and prevent pipeline execution.

Relevant logs and/or screenshots

image

image

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖