1
0
mirror of https://github.com/goharbor/harbor.git synced 2025-01-15 20:22:01 +01:00

fix: ignore untagged artifact when perform immutable policy ()

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
Chenyu Zhang 2022-02-22 15:18:29 +08:00 committed by GitHub
parent 8d05007eb5
commit 490fe4e5b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions
src/pkg/immutable/match/rule

View File

@ -2,6 +2,7 @@ package rule
import ( import (
"context" "context"
"github.com/goharbor/harbor/src/controller/immutable" "github.com/goharbor/harbor/src/controller/immutable"
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
iselector "github.com/goharbor/harbor/src/lib/selector" iselector "github.com/goharbor/harbor/src/lib/selector"
@ -54,8 +55,9 @@ func (rm *Matcher) Match(ctx context.Context, pid int64, c iselector.Candidate)
continue continue
} }
tagSelector := r.TagSelectors[0] tagSelector := r.TagSelectors[0]
// for immutable policy, should not keep untagged artifacts by default.
selector, err = index.Get(tagSelector.Kind, tagSelector.Decoration, selector, err = index.Get(tagSelector.Kind, tagSelector.Decoration,
tagSelector.Pattern, "") tagSelector.Pattern, "{\"untagged\": false}")
if err != nil { if err != nil {
return false, err return false, err
} }

View File

@ -1,6 +1,9 @@
package rule package rule
import ( import (
"os"
"testing"
"github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/controller/immutable" "github.com/goharbor/harbor/src/controller/immutable"
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
@ -9,8 +12,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"os"
"testing"
) )
// MatchTestSuite ... // MatchTestSuite ...
@ -130,6 +131,19 @@ func (s *MatchTestSuite) TestImmuMatch() {
isMatch, err = match.Match(orm.Context(), 1, c4) isMatch, err = match.Match(orm.Context(), 1, c4)
s.require.Equal(isMatch, false) s.require.Equal(isMatch, false)
s.require.Nil(err) s.require.Nil(err)
// untagged case
c5 := selector.Candidate{
NamespaceID: 1,
Namespace: "library",
Repository: "redis",
// no tags
Tags: []string{},
Kind: selector.Image,
}
isMatch, err = match.Match(orm.Context(), 1, c5)
s.require.Equal(isMatch, false)
s.require.Nil(err)
} }
// TearDownSuite clears env for test suite // TearDownSuite clears env for test suite