-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add regexp.replace support in role templates #7152
Conversation
@stevenGravy Can you verify this solves the customers issue, I think they are using |
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.
@nklaassen looks good UX-wise, but need docs in this PR please
@klizhentas sure, https://goteleport.com/docs/access-controls/guides/role-templates/#interpolation-rules seems like a good place to add an example, I'll do that. @klizhentas @russjones what should the behaviour be when the expression does not match at all? As-is it will just pass the value through unchanged, but I'm realizing that may not be what we want. I'm thinking of a case like |
In the latest commit, all values which do not match the regular expression at all are filtered out |
@nklaassen Once this is merged, please backport to |
func (r regexpReplaceTransformer) transform(in string) (string, error) { | ||
// filter out inputs which to not match the regexp at all | ||
if !r.re.MatchString(in) { | ||
return "", nil |
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.
Shouldn't this return in
unmodified?
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.
I'm filtering out inputs which do not match the regex, that seems to be more useful and the behaviour people actually want. Empty strings are removed from the output set in Interpolate
.
@nklaassen filtering out non matching values is a good default for both allow and deny expressions |
Closes #3374
This PR adds support for
{{regexp.replace(namespace.variable, expression, replacement)}}
syntax in role templates.See the updated tests for some examples.