Skip to content

Return Error for invalid identifiers instead of Warning - #9202

Closed
ceco556 wants to merge 13 commits into
concourse:masterfrom
ceco556:master
Closed

ceco556 wants to merge 13 commits into
concourse:masterfrom
ceco556:master

Conversation

@ceco556

@ceco556 ceco556 commented May 15, 2025 •

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

closes #9271
closes #8725
closes #8475

  • When there is invalid identifiers in a fly command it will return Error instead of Warning.
  • Check for invalid identifiers in the set_pipeline step and return Error if there is.

Notes to reviewer

I changed Warnings to be ConfigErrors. Let me know if you are okay with this. If needed i will rename it to IdentifierErrors or something else.

Release Note

Fly commands now will return Error when there is invalid identifiers found.
If there is set_pipeline step with invalid identifier in a pipeline and you try to set it, it will return Error.

@ceco556
ceco556 requested a review from a team May 15, 2025 07:45
@ceco556

ceco556 commented May 15, 2025 •

Copy link
Copy Markdown
Contributor Author

I have only one question here. Do we need a fallback mechanism for the delete-pipeline, delete-team and get-pipeline?
If there are already set pipelines with invalid identifiers and try to delete them with this change it will return Error.

For me it would be good to have such for some time. @taylorsilva , what do you think?

@ceco556

ceco556 commented May 15, 2025

Copy link
Copy Markdown
Contributor Author

@taylorsilva , could you please give me access to the PR checks so i can fix them?

Kump3r and others added 8 commits May 15, 2025 14:29
Signed-off-by: Taylor Silva <[email protected]>
Signed-off-by: IvanChalukov <[email protected]>
Add support for IEC standard notation (KiB, MiB, GiB) alongside the existing
traditional units (KB, MB, GB). Improve the regex pattern to handle abbreviated
units (K, M, G) and ensure case insensitivity across all unit formats. No
functional change to existing behavior - all units continue to use binary
multipliers (2^10, 2^20, 2^30) as before.

Signed-off-by: Mathias Bogaert <[email protected]>
When writing metadata files, the code was using O_WRONLY|O_CREATE flags without
O_TRUNC. This could cause file corruption when writing shorter content than what
existed previously, as the remaining bytes from the old content would persist in
the file.

The fix adds O_TRUNC to ensure clean overwrites and maintain data integrity.

Signed-off-by: Mathias Bogaert <[email protected]>
Fix

Fix

New changes

Fix

Fixes

Fix tests

Signed-off-by: ceco556 <[email protected]>
@ceco556

ceco556 commented May 15, 2025

Copy link
Copy Markdown
Contributor Author

Sorry for the commits, my forked repo was not synced.
If it is a problem i will open new PR.

@taylorsilva

Copy link
Copy Markdown
Member

I've added you to the Concourse org on Github. You will need to log out and then back in to https://ci.concourse-ci.org/, but then you should see the pipeline logs for your PR.

@taylorsilva

Copy link
Copy Markdown
Member

Initial thought for the users that have pipelines with invalid identifiers, since I think the validation only happens client side, would be to add a flag to skip the validation check, --skip-validation.

This would be a final escape hatch for users that have ignored the warnings.

@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests May 15, 2025
@ceco556

ceco556 commented May 16, 2025 •

Copy link
Copy Markdown
Contributor Author

I will implement it. Thanks for the suggestion.

After log out and log in, i still don't see the PR checks. Other pipelines are visible now. Did i miss something?

@taylorsilva

taylorsilva commented May 16, 2025 •

Copy link
Copy Markdown
Member

I can see that you haven't accepted the invitation yet. I'm not sure how you see it on your end, but I think if you go here it may show something: https://github.com/concourse
You should have gotten an email as well.

Invite might show up here as well: https://github.com/notifications

@ceco556

ceco556 commented May 16, 2025

Copy link
Copy Markdown
Contributor Author

Ah, yes, found it!
Thank you!

@taylorsilva

Copy link
Copy Markdown
Member

Ignore the [containerd-integration](https://ci.concourse-ci.org/builds/464632242) failure. It's flaking, I'll get it passing.

The unit test failures are legit though: https://ci.concourse-ci.org/builds/464630948#L6821cb41:627:654

@ceco556

ceco556 commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

The unit job timed out right at the end. I've retriggered it. Is it normal to time out ?

I think i managed to fix the unit test, now i have to take a look at the testflight tests.

@taylorsilva taylorsilva added this to the v8.0.0 milestone May 21, 2025
@taylorsilva

Copy link
Copy Markdown
Member

Sadly the time out is normal. There's only one worker for all PR's right now which creates a bottleneck and these timeouts are one side effect. Hopefully we can get more PR workers soon.

@ceco556

ceco556 commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

While fixing the testflight tests i found one issue. If you try to set a pipeline with set_pipeline step in it such as:

jobs:
- name: sp-1
  public: true
  plan:
    - get: some-resource
    - set_pipeline: ((pipeline_name))
      file: some-resource/pipeline.yml
      var_files:
      - some-resource/name.yml
      vars:
        greetings: hello

It will return error because the name ((pipeline_name)) has invalid identifier - "(".
My suggestion here is to change the regex to not check for "(". What do you think?

@ceco556

ceco556 commented May 22, 2025

Copy link
Copy Markdown
Contributor Author

I've added new checks to handle placeholders in identifiers. A new regex pattern is introduced to detect them. If an idetifier contains placeholder, the validation will process the remaining parts of the identifier after removing the placeholder.

One more thing we should discuss. After implementing the --skip-validation flag i didn't write tests for it. @taylorsilva , will this be a temporary flag and should i write tests for it?

@taylorsilva

taylorsilva commented May 27, 2025 •

Copy link
Copy Markdown
Member

I'm going to take a look at this today and answer some of the questions you've brought up.

Could you also please sign-off your commits 🙏
Clicking on the "DCO" check will take you here: https://github.com/concourse/concourse/pull/9202/checks?check_run_id=42687195953
which has instructions on how to sign-off all of your commits.

@taylorsilva taylorsilva left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall we're on the right track here.

The majority of my feedback basically boils down to: delete more code! 😀

I think anywhere where we were returning an atc.ConfigWarning can be consolidated into the error that was returned along with the ConfigWarning. That should result in code being deleted and simplify method signatures to return only error instead of warnings and errors.

Also great job adding the SkipValidation escape hatch for various fly commands 👏

Comment thread atc/responses.go
Comment on lines 7 to 10
type SaveConfigResponse struct {
Errors []string `json:"errors,omitempty"`
Warnings []ConfigWarning `json:"warnings,omitempty"`
Errors []string `json:"errors,omitempty"`
ConfigErrors []ConfigErrors `json:"configerrors,omitempty"`
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need both fields still? I think we can refactor this to:

type SaveConfigResponse struct {
	Errors []string `json:"errors,omitempty"`
}

Similar to what you did for SetTeamResponse:

type SetTeamResponse struct {

Feels redundant to have two fields that contain errors.

Comment thread atc/configwarning.go
var startsWithLetterOrNumber = regexp.MustCompile(`^[^\p{Ll}\p{Lt}\p{Lm}\p{Lo}\d]`)
var justNumbers = regexp.MustCompile(`^\d+$`)
var invalidCharacter = regexp.MustCompile(`([^\p{Ll}\p{Lt}\p{Lm}\p{Lo}\d\-_.])`)
var placeholderRegex = regexp.MustCompile(`\(\([a-zA-Z0-9_\-\.]+\)\)`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we should do this. I think this risks allowing users to accidentally create pipelines with the vars syntax in the name. I'll play around with this a bit to see how we can make this work for the set_pipeline step.

Comment on lines -176 to +177
var warnings []atc.ConfigWarning
func validateResources(c atc.Config) ([]atc.ConfigErrors, error) {
var errorMessages []string
var configErrors []atc.ConfigErrors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can consolidate this into just errorMessages now and remove configErrors. Let me know if I'm missing something here and there's a reason we need to keep both.

func validateResources(c atc.Config) error {
  //...
}

Comment on lines +213 to +215
func validateResourceTypes(c atc.Config, seenTypes map[string]location) ([]atc.ConfigErrors, error) {
var errorMessages []string
var configErrors []atc.ConfigErrors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

dup: see previous comment

Comment on lines -254 to +249
var warnings []atc.ConfigWarning
func validatePrototypes(c atc.Config, seenTypes map[string]location) ([]atc.ConfigErrors, error) {
var errorMessages []string
var configErrors []atc.ConfigErrors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

dup: see previous comment

CheckCredentials bool
DryRun bool
CommandWarnings []concourse.ConfigWarning
CommandErrors []atc.ConfigErrors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this field is will be needed anymore if you consolidate to just return error instead of using []atc.ConfigErrors everywhere still.

Comment on lines +38 to +39
func (command *SetPipelineCommand) Validate() ([]atc.ConfigErrors, error) {
var configErrors []atc.ConfigErrors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

dup: consolidate to return error only

func (command *SetPipelineCommand) Validate() error {

sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

Eventually(sess.Err.Contents).Should(ContainSubstring(`error: team 'doesnotexist' does not exist`))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep the ContainSubstring() checks in these tests?

Expect(err).ToNot(HaveOccurred())

Eventually(sess).Should(gexec.Exit(0))
Expect(sess.Out).To(gbytes.Say(fmt.Sprintf("pipeline successfully renamed to '%s'", newName)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can we keep the output check here?

_, _, _, warnings, err := team.CreateOrUpdate(desiredTeam)
Expect(err).NotTo(HaveOccurred())
Expect(warnings).To(HaveLen(1))
Expect(warnings[0].Message).To(ContainSubstring("team: 'new venture' is not a valid identifier"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can we still check for the string?

@ceco556

ceco556 commented May 30, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @taylorsilva,

Thanks for the code review. While addressing your comments i encountered issues with the integration tests for fly.(set_pipeline_test.go)
I get a lot of errors for invalid groups, resources, etc. Should we raise errors for these cases?
If yes, could you please assist with the tests? Let me know if you'd like to commit my latest changes.

@ceco556

ceco556 commented May 30, 2025

Copy link
Copy Markdown
Contributor Author

Another thing i forgot to mention.
Next week i will be on vacation and i am not sure how much time i will have to work on this PR.

@taylorsilva

Copy link
Copy Markdown
Member

Thanks @ceco556! I'm a bit backlogged right now so it'll take a while for me to circle back here, hopefully next week when you're back. Once I have time I'll dig into the tests.

This comment here also pointed out a similar issue that you ran into with the set_pipeline step, but for task steps as well: #9184 (reply in thread)

Not sure how we'll tackle this right now. We can dig into it more next week hopefully.

@ceco556

ceco556 commented Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

Hi @taylorsilva, did you have time to dig in this PR?

I have concerns regarding the failing tests and how we will handle the placeholders in the set_pipeline step. Even we skip the check for invalid identifiers in the set_pipeline step, there are a lot failing tests which have to be rewritten.

@taylorsilva

Copy link
Copy Markdown
Member

I haven't had a chance yet, but this PR has been in my head for the last few weeks. I have the same concerns as you and I'm not feeling good about the possible paths in front of us.

I've been feeling a bit tempted to have fields like the name of tasks not be considered identifiers at all and just skip checking them. The RFC does mention step names, but the supporting arguments only apply to job and resource names. Maybe we have a more lax check on step names, like making sure they don't have newline characters?

@taylorsilva

Copy link
Copy Markdown
Member

Heads up, I'm going to focus on the next release (7.14), so I won't get back to this PR until after that is done. This is top of the list though for me to review after the next release is out.

@taylorsilva

Copy link
Copy Markdown
Member

Hey, FINALLY circling back to this. So it seems our biggest issue is with handling vars (( )) in identifiers. You previously shared this example:

jobs:
- name: sp-1
  public: true
  plan:
    - get: some-resource
    - set_pipeline: ((pipeline_name))
      file: some-resource/pipeline.yml
      var_files:
      - some-resource/name.yml
      vars:
        greetings: hello

What confuses me about this is: when is ((pipeline_name)) expected to be interpolated?
I think ((pipeline_name)) would be interpolated when this pipeline is set. If I make your example a bit more portable:

resources:
- name: mock
  type: mock
  source:
    create_files:
      pipeline.yml: |
        resources:
          - name: mock
            type: mock
        jobs:
          - name: job
            plan:
              - get: mock

jobs:
- name: sp
  plan:
    - get: mock
    - set_pipeline: ((pipeline_name))
      file: mock/pipeline.yml

and fly set-pipeline and run it, I get an error undefined vars: pipeline_name
image
This error is interesting for other reasons, but the main point for now is that it fails.

If I set this pipeline again with --var pipeline_name=sp-test-ch set, everything works:
image

What workflow were you conveying when you shared this pipeline?


I decided to see where vars currently work through out a pipeline. I think I found some bugs related to how and when Concourse interpolates vars, but I think we can get away with ignoring those for now for the sake of this PR.

First, there are three "types" of vars that Concourse can interpolate:

  • (( )) - the classic. Can be interpolated when a pipeline is being set and used anywhere in a pipeline. Can also be interpolated during runtime, where the value is then expected to come from the configured secrets manager. Runtime interpolation is limited though (e.g. step names cannot be interpolated, but a task.config can be)
  • ((.:)) - the "local" var source, created by load_var and across steps
  • ((src:)) - var sources, come from var_sources defined in a pipeline

I created the following pipeline to play around with these different types of vars in various situations.

Click to view pipeline
var_sources:
  - name: varsrc
    type: dummy
    config:
      vars:
        task-name: my-vars
        child-pipe: child_pipe

resources:
  - name: mock
    type: mock

jobs:
  - name: job
    plan:
      - get: image
        resource: mock
        params:
          mirror_self_via_params: true

      - get: mock
        params:
          create_files_via_params:
            vars.yml: |
              task_name: some_task_name
              invalid_task_name: invalid task name
              child-pipe: child_pipe
            pipe.yml: |
              resources:
                - name: mock
                  type: mock
              jobs:
                - name: job
                  plan:
                    - get: mock

      - load_var: my-vars
        reveal: true
        file: mock/vars.yml

      - across:
          - var: acr
            values:
              - 123
              - abc
        in_parallel:
          # is currently allowed and should remain so
          # should we error if the identifier is not valid???
          - task: ((.:acr))
            image: image
            config:
              platform: linux
              run:
                path: bash
                args:
                  - -ec
                  # referncing var_sources does not work ((varsrc:child-pipe)) inside across steps
                  # results in error: missing source 'varsrc' in var: varsrc:child-pipe
                  # referencing ((.:my-vars)) does work! it is interpolated
                  - |
                    echo ((.:my-vars.child-pipe))-((.:acr))
          # does not warn, will create a pipeline with the literal var `(( ))` as the name
          # ((.:my-vars)) is not interpolatd
          # ((.:acr)) is interpolated
          # ((varsrc:)) results in an error during runtime: missing source 'varsrc'. I think this means lookups from secrets manager may also fail...
          - set_pipeline: ((.:my-vars.child-pipe))-((.:acr))
            file: mock/pipe.yml

      # currently warns, and should not be allowed moving forward
      - task: ((.:task-name))
        image: image
        config:
          platform: linux
          run:
            path: bash
            args:
              - -ec
              - |
                echo ((.:my-vars.child-pipe))-((varsrc:child-pipe))

      # it seems we detect the var, but it's never actually interpolated. We end
      # up with a bad pipeline name. The step should error.
      - set_pipeline: ((.:my-vars.child-pipe))
        file: mock/pipe.yml

There are a number of different cases we have to deal with here. Overall, I found the variable interpolation within across steps isn't working as expected. There are some bugs here. Thankfully, the core part works as expected and I think the fact that no one has logged any of the bugs I just found means I've stumbled across a very unusual use-case that we can ignore for now. Read my comments in the pipeline above for details on what works and doesn't work throughout the pipeline.

What does this all mean for this PR? There are various places where "validation" happens and we can check identifiers. I think when setting a pipeline, we can ignore any vars found inside across steps. Any vars found in identifiers outside across steps should result in an error.

During runtime, I think I would like to see the across properly validate identifiers for task and set_pipeline steps. How both of those are handled may be different. My expertise in that area of the code base is a bit foggy. I consider this part a bit out of scope for this PR, feels a bit like scope-creep potentially.

Those are my thoughts right now. I'm interested in your response to the first section of my post here. Let me know your thoughts! Sorry for the longggg post 😬

@taylorsilva taylorsilva moved this from In Progress to Todo in Pull Requests Oct 8, 2025
@ceco556

ceco556 commented Oct 30, 2025

Copy link
Copy Markdown
Contributor Author

Hi @taylorsilva,

I am sorry for the late response. Last couple of months were very interesting for me and i didn't have much time to work on this. I am not sure i will be able to continue the work on this PR next weeks, maybe months.

From what you've said, i totally agree with that to validate only what is outside of the across step. My only concern here is the tests. There are a tons of failing tests after the requested changes from you which must be fixed to handle these errors. I am not the best GO test developer and i am not sure i can handle them 😄 I will be very grateful for any help on this PR.

I am totally fine if someone wants to continue the work and fix the tests. Let me know what do you think.

@taylorsilva

Copy link
Copy Markdown
Member

Totally cool if you want to drop this PR. It is a tricky issue and was an informative exercise for the project. Feel free to close the PR.

@taylorsilva taylorsilva removed this from the v8.0.0 milestone Dec 2, 2025
@github-project-automation github-project-automation Bot moved this from Todo to Done in Pull Requests Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

5 participants