-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
retest this please |
There was a problem hiding this 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!
There was a problem hiding this 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.
0babc2a
to
ca29d6a
Compare
lib/srv/regular/sshserver.go
Outdated
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ca29d6a
to
a8af8c1
Compare
a8af8c1
to
5df6ab0
Compare
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