Update osbuild/images to v0.77.0
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
725c5cdb25
commit
a9923febd8
40 changed files with 252 additions and 169 deletions
54
vendor/github.com/osbuild/images/internal/pathpolicy/path_policy.go
generated
vendored
54
vendor/github.com/osbuild/images/internal/pathpolicy/path_policy.go
generated
vendored
|
|
@ -1,54 +0,0 @@
|
|||
package pathpolicy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
)
|
||||
|
||||
type PathPolicy struct {
|
||||
Deny bool // explicitly do not allow this entry
|
||||
Exact bool // require and exact match, no subdirs
|
||||
}
|
||||
|
||||
type PathPolicies = PathTrie
|
||||
|
||||
// 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 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")
|
||||
}
|
||||
|
||||
// ensure that only clean paths are valid
|
||||
if fsPath != path.Clean(fsPath) {
|
||||
return fmt.Errorf("path must be canonical")
|
||||
}
|
||||
|
||||
node, left := pol.Lookup(fsPath)
|
||||
policy, ok := node.Payload.(PathPolicy)
|
||||
if !ok {
|
||||
panic("programming error: invalid path trie 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)
|
||||
}
|
||||
|
||||
// exact match or recursive path allowed
|
||||
return nil
|
||||
}
|
||||
123
vendor/github.com/osbuild/images/internal/pathpolicy/path_trie.go
generated
vendored
123
vendor/github.com/osbuild/images/internal/pathpolicy/path_trie.go
generated
vendored
|
|
@ -1,123 +0,0 @@
|
|||
package pathpolicy
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// splits the path into its individual components. Retruns the
|
||||
// empty list if the path is just the absolute root, i.e. "/".
|
||||
func pathTrieSplitPath(path string) []string {
|
||||
path = strings.Trim(path, "/")
|
||||
if path == "" {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
return strings.Split(path, "/")
|
||||
}
|
||||
|
||||
type PathTrie struct {
|
||||
Name []string
|
||||
Paths []*PathTrie
|
||||
Payload interface{}
|
||||
}
|
||||
|
||||
// match checks if the given trie is a prefix of path
|
||||
func (trie *PathTrie) match(path []string) bool {
|
||||
if len(trie.Name) > len(path) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range trie.Name {
|
||||
if path[i] != trie.Name[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (trie *PathTrie) get(path []string) (*PathTrie, []string) {
|
||||
if len(path) < 1 {
|
||||
panic("programming error: expected root node")
|
||||
}
|
||||
|
||||
var node *PathTrie
|
||||
for i := range trie.Paths {
|
||||
if trie.Paths[i].match(path) {
|
||||
node = trie.Paths[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// no subpath match, we are the best match
|
||||
if node == nil {
|
||||
return trie, path
|
||||
}
|
||||
|
||||
// node, or one of its sub-nodes, is a match
|
||||
prefix := len(node.Name)
|
||||
|
||||
// the node is a perfect match, return it
|
||||
if len(path) == prefix {
|
||||
return node, nil
|
||||
}
|
||||
|
||||
// check if any sub-path's of node match
|
||||
return node.get(path[prefix:])
|
||||
}
|
||||
|
||||
func (trie *PathTrie) add(path []string) *PathTrie {
|
||||
node := &PathTrie{Name: path}
|
||||
|
||||
if trie.Paths == nil {
|
||||
trie.Paths = make([]*PathTrie, 0, 1)
|
||||
}
|
||||
|
||||
trie.Paths = append(trie.Paths, node)
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
// 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{}}
|
||||
|
||||
keys := make([]string, 0, len(entries))
|
||||
for k := range entries {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, k := range keys {
|
||||
node, left := root.Lookup(k)
|
||||
|
||||
if len(left) > 0 {
|
||||
node = node.add(left)
|
||||
}
|
||||
|
||||
node.Payload = entries[k]
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
if len(root.Name) != 0 {
|
||||
panic("programming error: lookup on non-root trie node")
|
||||
}
|
||||
|
||||
elements := pathTrieSplitPath(path)
|
||||
|
||||
if len(elements) == 0 {
|
||||
return root, elements
|
||||
}
|
||||
|
||||
return root.get(elements)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue