Skip to content

Improve label format enforcement #4102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2020
Merged

Conversation

fspmarshall
Copy link
Contributor

Label key format requirements were only being enforced by json schema, which is only run on a subset of deserializing operations, and (unsurprisingly) only when the the format of origin is json. As a result, invalid labels were not detected when passing through the GRPC API, being inserted into the backend, or when propagating through the event system. This resulted in teleport working mostly correctly up until the point where it is restarted, at which point initialization of the auth server cache would fail, causing startup to fail.

This PR addresses the specific issue of labels, but I'm working on drafting an issue about the broader problem of inconsistent validation. I'm generally of the opinion that json schema validation in teleport does more harm than good, and I think problems like this are a prime example of why validation logic should not be tied to a specific serialization format.

Partially addresses #4034

@fspmarshall
Copy link
Contributor Author

retest this please

Copy link
Contributor

@webvictim webvictim left a comment

Choose a reason for hiding this comment

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

LGTM - wait for another review though!

Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

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

Looks good to me once the issues in the comments are addressed.

@fspmarshall fspmarshall force-pushed the fspmarshall/label-validation branch 2 times, most recently from 0babc2a to ca29d6a Compare July 23, 2020 18:17
@fspmarshall fspmarshall requested a review from awly July 23, 2020 18:18
Comment on lines 347 to 354
for key := range cmdLabels {
if !services.IsValidLabelKey(key) {
return trace.BadParameter("invalid label key: %q", key)
}
}
// make sure to clone labels to avoid
// concurrent writes to the map during reloads
cmdLabels = cmdLabels.Clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine this with the loop below.
Also, should labels be cloned to prevent concurrent writes?

Copy link
Contributor Author

@fspmarshall fspmarshall Jul 24, 2020

Choose a reason for hiding this comment

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

As far as I can tell, only cmdLabels is mutated. The labels value should be calculated once at program start based on the config file and/or command-line inputs.

edit: Decided to clone it anyway. I choose to live in fear.

@fspmarshall fspmarshall force-pushed the fspmarshall/label-validation branch from ca29d6a to a8af8c1 Compare July 24, 2020 04:41
@fspmarshall fspmarshall force-pushed the fspmarshall/label-validation branch from a8af8c1 to 5df6ab0 Compare July 24, 2020 05:05
@fspmarshall fspmarshall merged commit eefef4d into master Jul 24, 2020
@fspmarshall fspmarshall deleted the fspmarshall/label-validation branch July 27, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants