Skip to content

Emit warnings for invalid identifiers - #5864

Merged
aoldershaw merged 20 commits into
concourse:masterfrom
mouellet:5810-valid-identifiers
Jul 22, 2020
Merged

aoldershaw merged 20 commits into
concourse:masterfrom
mouellet:5810-valid-identifiers

Conversation

@mouellet

@mouellet mouellet commented Jul 9, 2020 •

Copy link
Copy Markdown
Contributor

What does this PR accomplish?

Bug Fix | Feature | Documentation

closes #5810.

Changes proposed by this PR:

fly commands print warnings when teams, pipelines, jobs, steps, groups, resources, resource_types or var_sources identifier are not valid (see rfc#40 for spec).

Notes to reviewer:

Release Note

  • A warning will be emitted for every identifier that doesn't match the validation rules described in the identifier schema
  • After 1 year, we will error when identifiers don't match the validation rules - so, we recommend adhering to the new validation as soon as possible!

Contributor Checklist

Reviewer Checklist

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed
  • New config flags added? Ensure that they are added to the
    BOSH and
    Helm packaging; otherwise, ignored for
    the integration
    tests

    (for example, if they are Garden configs that are not displayed in the
    --help text).

@mouellet
mouellet force-pushed the 5810-valid-identifiers branch 2 times, most recently from 28cd400 to e5f3d5b Compare July 11, 2020 17:02
@aoldershaw

Copy link
Copy Markdown
Contributor

Hey @mouellet, thanks for another awesome contribution! I haven't had much of a chance to look at this, and probably won't for another day or two - we're busy trying to get 6.4.0 out the door. But will try to review it soon!

Comment thread atc/api/pipelines_test.go Resolved
Comment thread atc/api/teams_test.go Resolved
Comment thread atc/api/teams_test.go Resolved
Comment thread atc/api/teams_test.go Resolved
Comment thread atc/configwarning.go Outdated
return warning
}

var validIdentifiers = regexp.MustCompile(`^\p{L}[\p{L}\d\-.]*$`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The RFC mentions that

All letters will be converted to lowercase. This is to enforce case-insensitivity and to present a consistent UI/UX while still supporting languages that don't have any casing (e.g. Japanese).

We should probably just emit a warning for now.

@vito in the future, do you see this as the CLI automatically converting the case and logging a warning; or just fail outright?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@chenbh I see it as the server-side auto-converting case, though a client-side warning makes sense too. With this enforced on the server-side it can know to only convert newly created pipelines to lowercase while leaving the original pipelines alone. Whaddaya think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't \p{L} short for [\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}]? If we remove \p{Lu} from that we would have valid identifier be lowercase only and support languages without case. Then there's no need for auto-converting case, right?

It's not pretty, but I think ^[\p{Ll}\p{Lt}\p{Lm}\p{Lo}][\p{Ll}\p{Lt}\p{Lm}\p{Lo}\d\-.]*$ would do that...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mouellet Neat! Yeah, that works as expected. I'll amend the RFC with this as well.

Comment thread atc/configvalidate/validate.go Resolved
Comment thread atc/configwarning_test.go Resolved
Comment thread atc/api/configserver/save.go Resolved
Comment thread atc/api/pipelineserver/rename.go Resolved
Comment thread atc/api/pipelineserver/rename.go Resolved
Comment thread atc/api/teamserver/rename.go Resolved
Comment thread atc/api/teamserver/set.go Resolved
Comment thread atc/step_validator.go Resolved
Comment thread atc/configwarning.go Resolved

@aoldershaw aoldershaw left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great so far! I think we might have to slightly rethink the approach so that we error on setting new pipelines/teams rather than just emit warnings (ignore me, I missed your discussion with @vito), but otherwise this is awesome work. Much appreciated!

Just have a few nits for now, will do more thorough acceptance on it soon.

@vito

vito commented Jul 15, 2020 •

Copy link
Copy Markdown
Contributor

@aoldershaw We decided to go with warnings instead of errors until pipelines instances (#5808) lands. Otherwise, if we enforce valid identifiers first, some users would become blocked as their previously-valid name generation schemes would no longer be functional and they would have to resort to pretty ugly sanitization schemes like github.com-SLASH-foo.

This concern was mentioned here: concourse/rfcs#40 (comment)

Right now the RFC states...:

Existing data will still be fully functional and writable (i.e. updated with fly set-pipeline, fly set-team), and Concourse can emit warnings for any invalid identifiers (including the pipeline/team name itself) instead of erroring out completely.

After one year, we can turn these warnings into errors.

When I wrote this I originally intended this to apply only to already-existing data, but now that we're here it might be wise to just have all cases result in warnings and then switch to errors after some period of time so that folks have enough time to adapt their patterns to things like pipeline instances (...and so we have time to polish pipeline instances).

This would simplify the transition from 3 steps (Warn/Warn, Warn/Error w/ #5808 done, Error/Error after 1 year) down to 2 steps (Warn/Warn, Error/Error after 1 year) which may be easier to reason about.

What do y'all think? Should I amend the RFC?

@aoldershaw aoldershaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey, sorry for taking so long to review this! I have a couple small suggestions

Comment thread atc/configwarning.go Outdated
if identifier != "" && !validIdentifiers.MatchString(identifier) {
return &ConfigWarning{
Type: "invalid_identifier",
Message: fmt.Sprintf("%s: %s", strings.Join(context, ""), fmt.Sprintf("'%s' is not a valid identifier", identifier)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we can provide more context as to what a valid identifier is, since to a new user (or to an old user who isn't familiar with the valid identifiers RFC), it might not be obvious. While we will have this documented, perhaps it's better to tell the user what exactly was wrong with their identifier, or give a brief summary of what a valid identifier is. That could just be the responsibility of fly when it encounters an invalid_identifier warning, or we could encode this information into the Message itself...not sure what the best approach is.

Since the validation logic is pretty simple, maybe it's worth not using a regex at all (which looks a bit intimidating at this point) and instead do the validation manually. This way, we can give more fine-grained warning messages that can help users out (e.g. 'some_job' is not a valid identifier: illegal character '_' or '123abc' is not a valid identifier: must start with a letter)

What do you think about that approach?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure! Let's add a brief summary for must start with and illegal character. Should we print a single item (the left most one) or a list?

That could just be the responsibility of fly when it encounters an invalid_identifier warning, or we could encode this information into the Message itself...not sure what the best approach is.

Encoding the details in the Message will keep consistency between client-side and server-side validation.

Since the validation logic is pretty simple, maybe it's worth not using a regex at all (which looks a bit intimidating at this point) and instead do the validation manually.

If it's ok with you, I'd keep using a regex for now... There's a simple way to catch the details using them.

@mouellet
mouellet force-pushed the 5810-valid-identifiers branch from 4771844 to 4ad9bf8 Compare July 20, 2020 18:35

@aoldershaw aoldershaw left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It feels really nice to use, and the errors are pretty intuitive. I have 2 small requests:

  1. Would it be possible for fly to link to the schema.identifier docs (https://concourse-ci.org/config-basics.html#schema.identifier) when there is an invalid_identifier warning? I think it would probably make sense to just do it once after we print out all of the warnings, rather than printing it out for every warning. So, something like:
$ fly set-pipeline -p Test -c invalid-identifiers.yml
...

DEPRECATION WARNING:
  - pipeline: 'Test' is not a valid identifier: must start with a lowercase letter
  - resources.new_repo: 'new_repo' is not a valid identifier: illegal character '_'
  - jobs.set a pipeline: 'set a pipeline' is not a valid identifier: illegal character ' '
  - jobs.set a pipeline.plan.do[0].get(new_repo): 'new_repo' is not a valid identifier: illegal character '_'

identifier schema documentation: https://concourse-ci.org/config-basics.html#schema.identifier

...or if you have any other ideas, feel free to do something else - I just feel it's valuable to have some easy access to the documentation so that users aren't just faced with illegal character without knowing what the legal characters are!

  1. Speaking of docs 😁 would it be possible to update the schema.identifier section of the docs? It's all isolated here https://github.com/concourse/docs/blob/c3ce45b93efcb2850e4912afb2feba7e4513c465/lit/docs/config/basic-schemas.lit#L63-L80 from what I can tell. I'd still provide your updated regex, but now that it's a little harder to read, I'd also provide a short list of bullet points that describe the schema rules at a high level (starts with lowercase, only lowercase letters, nums, '.', '-')

Thanks again! Also saw you created a draft PR for pipeline instances - that's awesome, looking forward to seeing that in action

mouellet added 17 commits July 21, 2020 12:44
concourse#5810

Signed-off-by: Mathieu Ouellet <[email protected]>

@aoldershaw aoldershaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks for making the changes so quickly!

@aoldershaw
aoldershaw merged commit f184cf4 into concourse:master Jul 22, 2020
@vito vito changed the title valid identifiers Emit warnings for invalid identifiers Jul 29, 2020
@aoldershaw aoldershaw added the release/documented Documentation and release notes have been updated. label Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement release/documented Documentation and release notes have been updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce restrictions for valid identifiers

4 participants