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

Implement support to disable registry filtering in Containerd #373

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#373](https://github.com/spegel-org/spegel/pull/373) Implement support to disable registry filtering in Containerd.

### Changed

### Deprecated
Expand Down
9 changes: 7 additions & 2 deletions pkg/oci/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,17 @@ func getEventImage(e typeurl.Any) (string, EventType, error) {
}
}

func createFilters(registries []url.URL) (string, string) {
func createFilters(filterRegistries []url.URL) (string, string) {
registryHosts := []string{}
for _, registry := range registries {
for _, registry := range filterRegistries {
registryHosts = append(registryHosts, strings.ReplaceAll(registry.Host, `.`, `\\.`))
}
listFilter := fmt.Sprintf(`name~="^(%s)/"`, strings.Join(registryHosts, "|"))
if len(registryHosts) == 0 {
// Filter images that do not have a registry in it's reference,
// as we cant mirror images without registries.
listFilter = `name~="^.+/"`
}
eventFilter := fmt.Sprintf(`topic~="/images/create|/images/update|/images/delete",event.%s`, listFilter)
return listFilter, eventFilter
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/oci/containerd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ func TestCreateFilter(t *testing.T) {
registries []string
}{
{
name: "only registries",
name: "with registry filtering",
registries: []string{"https://docker.io", "https://gcr.io"},
expectedListFilter: `name~="^(docker\\.io|gcr\\.io)/"`,
expectedEventFilter: `topic~="/images/create|/images/update|/images/delete",event.name~="^(docker\\.io|gcr\\.io)/"`,
},
{
name: "additional image filtes",
registries: []string{"https://docker.io", "https://gcr.io"},
expectedListFilter: `name~="^(docker\\.io|gcr\\.io)/"`,
expectedEventFilter: `topic~="/images/create|/images/update|/images/delete",event.name~="^(docker\\.io|gcr\\.io)/"`,
name: "without registry filtering",
registries: []string{},
expectedListFilter: `name~="^.+/"`,
expectedEventFilter: `topic~="/images/create|/images/update|/images/delete",event.name~="^.+/"`,
},
}
for _, tt := range tests {
Expand Down