Skip to content
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

ssa: Extend CEL immutable error detection #660

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ssa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ func IsKustomization(object *unstructured.Unstructured) bool {
return false
}

var matchImmutableFieldErr = regexp.MustCompile(`.*is\simmutable.*`)
// Match CEL immutable error variants.
var matchImmutableFieldErrors = []*regexp.Regexp{
regexp.MustCompile(`.*is\simmutable.*`),
regexp.MustCompile(`.*immutable\sfield.*`),
}

// IsImmutableError checks if the given error is an immutable error.
func IsImmutableError(err error) bool {
Expand All @@ -297,8 +301,10 @@ func IsImmutableError(err error) bool {

// Detect immutable errors returned by custom admission webhooks and Kubernetes CEL
// https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/#immutablility-after-first-modification
if matchImmutableFieldErr.MatchString(err.Error()) {
return true
for _, fieldError := range matchImmutableFieldErrors {
if fieldError.MatchString(err.Error()) {
return true
}
}

return false
Expand Down
Loading