Update osbuild/images to v0.79.0
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
9fcbcdb5dc
commit
62d8ad4efe
340 changed files with 15526 additions and 2999 deletions
27
vendor/github.com/osbuild/images/pkg/pathpolicy/path_policy.go
generated
vendored
27
vendor/github.com/osbuild/images/pkg/pathpolicy/path_policy.go
generated
vendored
|
|
@ -10,43 +10,36 @@ type PathPolicy struct {
|
|||
Exact bool // require and exact match, no subdirs
|
||||
}
|
||||
|
||||
type PathPolicies = PathTrie
|
||||
type PathPolicies struct {
|
||||
pathTrie *pathTrie[PathPolicy]
|
||||
}
|
||||
|
||||
// Create a new PathPolicies trie from a map of path to PathPolicy
|
||||
func NewPathPolicies(entries map[string]PathPolicy) *PathPolicies {
|
||||
|
||||
noType := make(map[string]interface{}, len(entries))
|
||||
|
||||
for k, v := range entries {
|
||||
noType[k] = v
|
||||
return &PathPolicies{
|
||||
pathTrie: newPathTrieFromMap[PathPolicy](entries),
|
||||
}
|
||||
|
||||
return NewPathTrieFromMap(noType)
|
||||
}
|
||||
|
||||
// Check a given path against the PathPolicies
|
||||
func (pol *PathPolicies) Check(fsPath string) error {
|
||||
|
||||
// Quickly check we have a path and it is absolute
|
||||
if fsPath == "" || fsPath[0] != '/' {
|
||||
return fmt.Errorf("path must be absolute")
|
||||
return fmt.Errorf("path %q must be absolute", fsPath)
|
||||
}
|
||||
|
||||
// ensure that only clean paths are valid
|
||||
if fsPath != path.Clean(fsPath) {
|
||||
return fmt.Errorf("path must be canonical")
|
||||
return fmt.Errorf("path %q must be canonical", fsPath)
|
||||
}
|
||||
|
||||
node, left := pol.Lookup(fsPath)
|
||||
policy, ok := node.Payload.(PathPolicy)
|
||||
if !ok {
|
||||
panic("programming error: invalid path trie payload")
|
||||
}
|
||||
node, left := pol.pathTrie.Lookup(fsPath)
|
||||
policy := node.Payload
|
||||
|
||||
// 1) path is explicitly not allowed or
|
||||
// 2) a subpath was match but an explicit match is required
|
||||
if policy.Deny || (policy.Exact && len(left) > 0) {
|
||||
return fmt.Errorf("path '%s ' is not allowed", fsPath)
|
||||
return fmt.Errorf("path %q is not allowed", fsPath)
|
||||
}
|
||||
|
||||
// exact match or recursive path allowed
|
||||
|
|
|
|||
24
vendor/github.com/osbuild/images/pkg/pathpolicy/path_trie.go
generated
vendored
24
vendor/github.com/osbuild/images/pkg/pathpolicy/path_trie.go
generated
vendored
|
|
@ -16,14 +16,14 @@ func pathTrieSplitPath(path string) []string {
|
|||
return strings.Split(path, "/")
|
||||
}
|
||||
|
||||
type PathTrie struct {
|
||||
type pathTrie[T any] struct {
|
||||
Name []string
|
||||
Paths []*PathTrie
|
||||
Payload interface{}
|
||||
Paths []*pathTrie[T]
|
||||
Payload T
|
||||
}
|
||||
|
||||
// match checks if the given trie is a prefix of path
|
||||
func (trie *PathTrie) match(path []string) bool {
|
||||
func (trie *pathTrie[T]) match(path []string) bool {
|
||||
if len(trie.Name) > len(path) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -37,12 +37,12 @@ func (trie *PathTrie) match(path []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (trie *PathTrie) get(path []string) (*PathTrie, []string) {
|
||||
func (trie *pathTrie[T]) get(path []string) (*pathTrie[T], []string) {
|
||||
if len(path) < 1 {
|
||||
panic("programming error: expected root node")
|
||||
}
|
||||
|
||||
var node *PathTrie
|
||||
var node *pathTrie[T]
|
||||
for i := range trie.Paths {
|
||||
if trie.Paths[i].match(path) {
|
||||
node = trie.Paths[i]
|
||||
|
|
@ -67,11 +67,11 @@ func (trie *PathTrie) get(path []string) (*PathTrie, []string) {
|
|||
return node.get(path[prefix:])
|
||||
}
|
||||
|
||||
func (trie *PathTrie) add(path []string) *PathTrie {
|
||||
node := &PathTrie{Name: path}
|
||||
func (trie *pathTrie[T]) add(path []string) *pathTrie[T] {
|
||||
node := &pathTrie[T]{Name: path}
|
||||
|
||||
if trie.Paths == nil {
|
||||
trie.Paths = make([]*PathTrie, 0, 1)
|
||||
trie.Paths = make([]*pathTrie[T], 0, 1)
|
||||
}
|
||||
|
||||
trie.Paths = append(trie.Paths, node)
|
||||
|
|
@ -81,8 +81,8 @@ func (trie *PathTrie) add(path []string) *PathTrie {
|
|||
|
||||
// Construct a new trie from a map of paths to their payloads.
|
||||
// Returns the root node of the trie.
|
||||
func NewPathTrieFromMap(entries map[string]interface{}) *PathTrie {
|
||||
root := &PathTrie{Name: []string{}}
|
||||
func newPathTrieFromMap[T any](entries map[string]T) *pathTrie[T] {
|
||||
root := &pathTrie[T]{Name: []string{}}
|
||||
|
||||
keys := make([]string, 0, len(entries))
|
||||
for k := range entries {
|
||||
|
|
@ -107,7 +107,7 @@ func NewPathTrieFromMap(entries map[string]interface{}) *PathTrie {
|
|||
// Lookup returns the node that is the prefix of path and
|
||||
// the unmatched path segment. Must be called on the root
|
||||
// trie node.
|
||||
func (root *PathTrie) Lookup(path string) (*PathTrie, []string) {
|
||||
func (root *pathTrie[T]) Lookup(path string) (*pathTrie[T], []string) {
|
||||
|
||||
if len(root.Name) != 0 {
|
||||
panic("programming error: lookup on non-root trie node")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue