vendor: update buildkit to v0.32.0-rc1
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/api/services/control/control.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/api/types/worker.proto
|
||||
|
||||
|
||||
+5
-1
@@ -279,8 +279,12 @@ func (e *ExecOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, []
|
||||
addCap(&e.constraints, pb.CapExecMetaNetwork)
|
||||
}
|
||||
|
||||
if security != SecurityModeSandbox {
|
||||
switch security {
|
||||
case SecurityModeSandbox:
|
||||
case SecurityModeInsecure:
|
||||
addCap(&e.constraints, pb.CapExecMetaSecurity)
|
||||
default:
|
||||
return "", nil, nil, nil, pb.ValidateSecurityMode(security)
|
||||
}
|
||||
|
||||
if p := e.proxyEnv; p != nil {
|
||||
|
||||
+3
-2
@@ -14,6 +14,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/v2/defaults"
|
||||
distreference "github.com/distribution/reference"
|
||||
"github.com/moby/buildkit/client/llb"
|
||||
"github.com/moby/buildkit/client/llb/sourceresolver"
|
||||
@@ -1451,8 +1452,8 @@ func grpcClientConn(ctx context.Context) (context.Context, *grpc.ClientConn, err
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithUnaryInterceptor(grpcerrors.UnaryClientInterceptor),
|
||||
grpc.WithStreamInterceptor(grpcerrors.StreamClientInterceptor),
|
||||
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(16 << 20)),
|
||||
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(16 << 20)),
|
||||
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)),
|
||||
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
|
||||
}
|
||||
|
||||
//nolint:staticcheck // ignore SA1019 NewClient has different behavior and needs to be tested
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/frontend/gateway/pb/gateway.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/session/auth/auth.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/session/filesync/filesync.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/session/secrets/secrets.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/session/sshforward/ssh.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/session/upload/upload.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/solver/errdefs/errdefs.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/solver/pb/ops.proto
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package pb
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
func ValidateSecurityMode(mode SecurityMode) error {
|
||||
switch mode {
|
||||
case SecurityMode_SANDBOX, SecurityMode_INSECURE:
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid security mode %d", mode)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/sourcepolicy/pb/policy.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/sourcepolicy/policysession/policysession.proto
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/util/apicaps/pb/caps.proto
|
||||
|
||||
|
||||
+7
@@ -212,6 +212,13 @@ func (cli *GitCLI) Run(ctx context.Context, args ...string) (_ []byte, err error
|
||||
"HOMEPATH",
|
||||
"GIT_CONFIG_GLOBAL",
|
||||
"GIT_CONFIG_SYSTEM",
|
||||
// When git runs as root under sudo it consults SUDO_UID to trust
|
||||
// repositories owned by the user who invoked sudo, so client-side
|
||||
// callers such as `sudo docker build` don't trip git's "detected
|
||||
// dubious ownership" check and silently lose commit provenance.
|
||||
// This mirrors git's own default behavior and does not disable
|
||||
// safe.directory checks. See docker/buildx#3855.
|
||||
"SUDO_UID",
|
||||
} {
|
||||
if v, ok := os.LookupEnv(ev); ok {
|
||||
cmd.Env = append(cmd.Env, ev+"="+v)
|
||||
|
||||
+14
-2
@@ -14,6 +14,17 @@ const defaultPort = 22
|
||||
|
||||
var errCallbackDone = errors.New("callback failed on purpose")
|
||||
|
||||
// knownHostsServerID formats a host identifier for a known_hosts entry. A
|
||||
// non-standard port must be rendered as "[host]:port" so that ssh matches the
|
||||
// entry when connecting (see the SSH_KNOWN_HOSTS format in sshd(8)); the
|
||||
// default port is rendered as a bare hostname.
|
||||
func knownHostsServerID(hostname, port string) string {
|
||||
if port == "" || port == strconv.Itoa(defaultPort) {
|
||||
return hostname
|
||||
}
|
||||
return fmt.Sprintf("[%s]:%s", hostname, port)
|
||||
}
|
||||
|
||||
// addDefaultPort appends a default port if hostport doesn't contain one
|
||||
func addDefaultPort(hostport string, defaultPort int) string {
|
||||
_, _, err := net.SplitHostPort(hostport)
|
||||
@@ -28,11 +39,12 @@ func addDefaultPort(hostport string, defaultPort int) string {
|
||||
func SSHKeyScan(server string) (string, error) {
|
||||
var key string
|
||||
KeyScanCallback := func(hostport string, remote net.Addr, pubKey ssh.PublicKey) error {
|
||||
hostname, _, err := net.SplitHostPort(hostport)
|
||||
hostname, port, err := net.SplitHostPort(hostport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key = strings.TrimSpace(fmt.Sprintf("%s %s", hostname, string(ssh.MarshalAuthorizedKey(pubKey))))
|
||||
serverID := knownHostsServerID(hostname, port)
|
||||
key = strings.TrimSpace(fmt.Sprintf("%s %s", serverID, string(ssh.MarshalAuthorizedKey(pubKey))))
|
||||
return errCallbackDone
|
||||
}
|
||||
config := &ssh.ClientConfig{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc-gen-go v1.36.11-devel
|
||||
// protoc v3.14.0
|
||||
// source: github.com/moby/buildkit/util/stack/stack.proto
|
||||
|
||||
|
||||
+3
-13
@@ -14,23 +14,13 @@ func init() {
|
||||
|
||||
func initContext(ctx context.Context) context.Context {
|
||||
// open-telemetry/opentelemetry-specification#740
|
||||
parent := os.Getenv("TRACEPARENT")
|
||||
state := os.Getenv("TRACESTATE")
|
||||
parent := os.Getenv("TRACEPARENT") // https://www.w3.org/TR/trace-context/#traceparent-header
|
||||
state := os.Getenv("TRACESTATE") // https://www.w3.org/TR/trace-context/#tracestate-header
|
||||
|
||||
if parent != "" {
|
||||
tc := propagation.TraceContext{}
|
||||
return tc.Extract(ctx, &textMap{parent: parent, state: state})
|
||||
}
|
||||
|
||||
// deprecated: removed in v0.11.0
|
||||
// previously defined in https://github.com/open-telemetry/opentelemetry-swift/blob/4ea467ed4b881d7329bf2254ca7ed7f2d9d6e1eb/Sources/OpenTelemetrySdk/Trace/Propagation/EnvironmentContextPropagator.swift#L14-L15
|
||||
parent = os.Getenv("OTEL_TRACE_PARENT")
|
||||
state = os.Getenv("OTEL_TRACE_STATE")
|
||||
|
||||
if parent == "" {
|
||||
return ctx
|
||||
}
|
||||
|
||||
tc := propagation.TraceContext{}
|
||||
return tc.Extract(ctx, &textMap{parent: parent, state: state})
|
||||
return ctx
|
||||
}
|
||||
|
||||
-9
@@ -15,15 +15,6 @@ func Environ(ctx context.Context) []string {
|
||||
|
||||
var env []string
|
||||
|
||||
// deprecated: removed in v0.11.0
|
||||
// previously defined in https://github.com/open-telemetry/opentelemetry-swift/blob/4ea467ed4b881d7329bf2254ca7ed7f2d9d6e1eb/Sources/OpenTelemetrySdk/Trace/Propagation/EnvironmentContextPropagator.swift#L14-L15
|
||||
if tm.parent != "" {
|
||||
env = append(env, "OTEL_TRACE_PARENT="+tm.parent)
|
||||
}
|
||||
if tm.state != "" {
|
||||
env = append(env, "OTEL_TRACE_STATE="+tm.state)
|
||||
}
|
||||
|
||||
// open-telemetry/opentelemetry-specification#740
|
||||
if tm.parent != "" {
|
||||
env = append(env, "TRACEPARENT="+tm.parent)
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ func (fn TraceExporterDetector) DetectMetricExporter() (sdkmetric.Exporter, erro
|
||||
}
|
||||
|
||||
func detectExporter[T any](envVar string, fn func(d ExporterDetector) (T, bool, error)) (exp T, err error) {
|
||||
ignoreErrors, _ := strconv.ParseBool("OTEL_IGNORE_ERROR")
|
||||
ignoreErrors, _ := strconv.ParseBool(os.Getenv("OTEL_IGNORE_ERROR"))
|
||||
|
||||
if n := os.Getenv(envVar); n != "" {
|
||||
d, ok := detectors[n]
|
||||
|
||||
+7
@@ -198,6 +198,13 @@ func (d *hashedRecordSignedEntity) Certificate() *x509.Certificate {
|
||||
return d.cert.Certificate()
|
||||
}
|
||||
|
||||
func (d *hashedRecordSignedEntity) Intermediates() []*x509.Certificate {
|
||||
if d.isDHI {
|
||||
return nil
|
||||
}
|
||||
return d.cert.Intermediates()
|
||||
}
|
||||
|
||||
func (d *hashedRecordSignedEntity) PublicKey() verify.PublicKeyProvider {
|
||||
if d.isDHI {
|
||||
return bundle.PublicKey{}
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package user
|
||||
|
||||
|
||||
+116
-113
@@ -56,11 +56,11 @@ type IDMap struct {
|
||||
Count int64
|
||||
}
|
||||
|
||||
func parseLine(line []byte, v ...interface{}) {
|
||||
func parseLine(line []byte, v ...any) {
|
||||
parseParts(bytes.Split(line, []byte(":")), v...)
|
||||
}
|
||||
|
||||
func parseParts(parts [][]byte, v ...interface{}) {
|
||||
func parseParts(parts [][]byte, v ...any) {
|
||||
if len(parts) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -97,12 +97,7 @@ func parseParts(parts [][]byte, v ...interface{}) {
|
||||
}
|
||||
|
||||
func ParsePasswdFile(path string) ([]User, error) {
|
||||
passwd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer passwd.Close()
|
||||
return ParsePasswd(passwd)
|
||||
return ParsePasswdFileFilter(path, nil)
|
||||
}
|
||||
|
||||
func ParsePasswd(passwd io.Reader) ([]User, error) {
|
||||
@@ -154,13 +149,7 @@ func ParsePasswdFilter(r io.Reader, filter func(User) bool) ([]User, error) {
|
||||
}
|
||||
|
||||
func ParseGroupFile(path string) ([]Group, error) {
|
||||
group, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer group.Close()
|
||||
return ParseGroup(group)
|
||||
return ParseGroupFileFilter(path, nil)
|
||||
}
|
||||
|
||||
func ParseGroup(group io.Reader) ([]Group, error) {
|
||||
@@ -168,7 +157,7 @@ func ParseGroup(group io.Reader) ([]Group, error) {
|
||||
}
|
||||
|
||||
func ParseGroupFileFilter(path string, filter func(Group) bool) ([]Group, error) {
|
||||
group, err := os.Open(path)
|
||||
group, err := openUserFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -180,52 +169,22 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) {
|
||||
if r == nil {
|
||||
return nil, errors.New("nil source for group-formatted data")
|
||||
}
|
||||
rd := bufio.NewReader(r)
|
||||
out := []Group{}
|
||||
|
||||
// Read the file line-by-line.
|
||||
for {
|
||||
var (
|
||||
isPrefix bool
|
||||
wholeLine []byte
|
||||
err error
|
||||
)
|
||||
var (
|
||||
s = bufio.NewScanner(r)
|
||||
out = []Group{}
|
||||
)
|
||||
|
||||
// Read the next line. We do so in chunks (as much as reader's
|
||||
// buffer is able to keep), check if we read enough columns
|
||||
// already on each step and store final result in wholeLine.
|
||||
for {
|
||||
var line []byte
|
||||
line, isPrefix, err = rd.ReadLine()
|
||||
if err != nil {
|
||||
// We should return no error if EOF is reached
|
||||
// without a match.
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Simple common case: line is short enough to fit in a
|
||||
// single reader's buffer.
|
||||
if !isPrefix && len(wholeLine) == 0 {
|
||||
wholeLine = line
|
||||
break
|
||||
}
|
||||
|
||||
wholeLine = append(wholeLine, line...)
|
||||
|
||||
// Check if we read the whole line already.
|
||||
if !isPrefix {
|
||||
break
|
||||
}
|
||||
}
|
||||
// A group's user_list may be arbitrarily long, so allow lines that are
|
||||
// much larger than bufio.Scanner's default maximum token size (64 KiB).
|
||||
s.Buffer(nil, 1024*1024)
|
||||
|
||||
for s.Scan() {
|
||||
// There's no spec for /etc/passwd or /etc/group, but we try to follow
|
||||
// the same rules as the glibc parser, which allows comments and blank
|
||||
// space at the beginning of a line.
|
||||
wholeLine = bytes.TrimSpace(wholeLine)
|
||||
if len(wholeLine) == 0 || wholeLine[0] == '#' {
|
||||
line := bytes.TrimSpace(s.Bytes())
|
||||
if len(line) == 0 || line[0] == '#' {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -235,12 +194,17 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) {
|
||||
// root:x:0:root
|
||||
// adm:x:4:root,adm,daemon
|
||||
p := Group{}
|
||||
parseLine(wholeLine, &p.Name, &p.Pass, &p.Gid, &p.List)
|
||||
parseLine(line, &p.Name, &p.Pass, &p.Gid, &p.List)
|
||||
|
||||
if filter == nil || filter(p) {
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
type ExecUser struct {
|
||||
@@ -257,12 +221,12 @@ type ExecUser struct {
|
||||
func GetExecUserPath(userSpec string, defaults *ExecUser, passwdPath, groupPath string) (*ExecUser, error) {
|
||||
var passwd, group io.Reader
|
||||
|
||||
if passwdFile, err := os.Open(passwdPath); err == nil {
|
||||
if passwdFile, err := openUserFile(passwdPath); err == nil {
|
||||
passwd = passwdFile
|
||||
defer passwdFile.Close()
|
||||
}
|
||||
|
||||
if groupFile, err := os.Open(groupPath); err == nil {
|
||||
if groupFile, err := openUserFile(groupPath); err == nil {
|
||||
group = groupFile
|
||||
defer groupFile.Close()
|
||||
}
|
||||
@@ -270,6 +234,38 @@ func GetExecUserPath(userSpec string, defaults *ExecUser, passwdPath, groupPath
|
||||
return GetExecUser(userSpec, defaults, passwd, group)
|
||||
}
|
||||
|
||||
// parseNumeric parses the given UID or GID value to an integer and within
|
||||
// the minID - maxID range.
|
||||
//
|
||||
// While the Linux kernel allows the max UID to be MaxUint32 - 2,
|
||||
// and the OCI Runtime Spec has no definition about the max UID, we require
|
||||
// the UID to be <= MaxInt32.
|
||||
//
|
||||
// See https://github.com/containerd/containerd/commit/de1341c201ffb0effebbf51d00376181968c8779
|
||||
func parseNumeric(val string) (int, bool, error) {
|
||||
if val == "" {
|
||||
return 0, false, nil
|
||||
}
|
||||
id, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
if errors.Is(err, strconv.ErrSyntax) {
|
||||
// Discard the error, because non-numeric values are expected
|
||||
// when passing a username or group-name.
|
||||
return 0, false, nil
|
||||
}
|
||||
if errors.Is(err, strconv.ErrRange) {
|
||||
return 0, true, ErrRange
|
||||
}
|
||||
// Other errors ("invalid base", "invalid bit size"); should never
|
||||
// happen with strconv.Atoi.
|
||||
return 0, false, err
|
||||
}
|
||||
if id < minID || id > maxID {
|
||||
return 0, true, ErrRange
|
||||
}
|
||||
return id, true, nil
|
||||
}
|
||||
|
||||
// GetExecUser parses a user specification string (using the passwd and group
|
||||
// readers as sources for /etc/passwd and /etc/group data, respectively). In
|
||||
// the case of blank fields or missing data from the sources, the values in
|
||||
@@ -315,8 +311,14 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
|
||||
// Convert userArg and groupArg to be numeric, so we don't have to execute
|
||||
// Atoi *twice* for each iteration over lines.
|
||||
uidArg, uidErr := strconv.Atoi(userArg)
|
||||
gidArg, gidErr := strconv.Atoi(groupArg)
|
||||
uidArg, isUID, err := parseNumeric(userArg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gidArg, isGID, err := parseNumeric(groupArg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Find the matching user.
|
||||
users, err := ParsePasswdFilter(passwd, func(u User) bool {
|
||||
@@ -325,8 +327,8 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
return u.Uid == user.Uid
|
||||
}
|
||||
|
||||
if uidErr == nil {
|
||||
// If the userArg is numeric, always treat it as a UID.
|
||||
if isUID {
|
||||
// If the userArg is a valid numeric value, always treat it as a UID.
|
||||
return uidArg == u.Uid
|
||||
}
|
||||
|
||||
@@ -352,18 +354,11 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
// If we can't find a user with the given username, the only other valid
|
||||
// option is if it's a numeric username with no associated entry in passwd.
|
||||
|
||||
if uidErr != nil {
|
||||
if !isUID {
|
||||
// Not numeric.
|
||||
return nil, fmt.Errorf("unable to find user %s: %w", userArg, ErrNoPasswdEntries)
|
||||
}
|
||||
user.Uid = uidArg
|
||||
|
||||
// Must be inside valid uid range.
|
||||
if user.Uid < minID || user.Uid > maxID {
|
||||
return nil, ErrRange
|
||||
}
|
||||
|
||||
// Okay, so it's numeric. We can just roll with this.
|
||||
}
|
||||
|
||||
// On to the groups. If we matched a username, we need to do this because of
|
||||
@@ -381,7 +376,7 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
return false
|
||||
}
|
||||
|
||||
if gidErr == nil {
|
||||
if isGID {
|
||||
// If the groupArg is numeric, always treat it as a GID.
|
||||
return gidArg == g.Gid
|
||||
}
|
||||
@@ -401,18 +396,11 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
// If we can't find a group with the given name, the only other valid
|
||||
// option is if it's a numeric group name with no associated entry in group.
|
||||
|
||||
if gidErr != nil {
|
||||
if !isGID {
|
||||
// Not numeric.
|
||||
return nil, fmt.Errorf("unable to find group %s: %w", groupArg, ErrNoGroupEntries)
|
||||
}
|
||||
user.Gid = gidArg
|
||||
|
||||
// Must be inside valid gid range.
|
||||
if user.Gid < minID || user.Gid > maxID {
|
||||
return nil, ErrRange
|
||||
}
|
||||
|
||||
// Okay, so it's numeric. We can just roll with this.
|
||||
}
|
||||
} else if len(groups) > 0 {
|
||||
// Supplementary group ids only make sense if in the implicit form.
|
||||
@@ -426,55 +414,80 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// groupArg is a parsed group argument for [GetAdditionalGroups].
|
||||
type groupArg struct {
|
||||
name string
|
||||
gid int
|
||||
isNumeric bool
|
||||
}
|
||||
|
||||
// matches reports whether group g satisfies the argument. Numeric arguments
|
||||
// are matched by GID only, others by name.
|
||||
func (ag groupArg) matches(g Group) bool {
|
||||
if ag.isNumeric {
|
||||
return g.Gid == ag.gid
|
||||
}
|
||||
return g.Name == ag.name
|
||||
}
|
||||
|
||||
// GetAdditionalGroups looks up a list of groups by name or group id
|
||||
// against the given /etc/group formatted data. If a group name cannot
|
||||
// be found, an error will be returned. If a group id cannot be found,
|
||||
// or the given group data is nil, the id will be returned as-is
|
||||
// provided it is in the legal range.
|
||||
func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, error) {
|
||||
addtlGroups := make([]groupArg, len(additionalGroups))
|
||||
for i, ag := range additionalGroups {
|
||||
gid, ok, err := parseNumeric(ag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addtlGroups[i] = groupArg{
|
||||
name: ag,
|
||||
gid: gid,
|
||||
isNumeric: ok,
|
||||
}
|
||||
}
|
||||
|
||||
groups := []Group{}
|
||||
if group != nil {
|
||||
var err error
|
||||
groups, err = ParseGroupFilter(group, func(g Group) bool {
|
||||
for _, ag := range additionalGroups {
|
||||
if g.Name == ag || strconv.Itoa(g.Gid) == ag {
|
||||
for _, ag := range addtlGroups {
|
||||
if ag.matches(g) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to find additional groups %v: %w", additionalGroups, err)
|
||||
return nil, fmt.Errorf("unable to find additional groups %v: %w", additionalGroups, err)
|
||||
}
|
||||
}
|
||||
|
||||
gidMap := make(map[int]struct{})
|
||||
for _, ag := range additionalGroups {
|
||||
for _, ag := range addtlGroups {
|
||||
var found bool
|
||||
for _, g := range groups {
|
||||
// if we found a matched group either by name or gid, take the
|
||||
// first matched as correct
|
||||
if g.Name == ag || strconv.Itoa(g.Gid) == ag {
|
||||
if _, ok := gidMap[g.Gid]; !ok {
|
||||
gidMap[g.Gid] = struct{}{}
|
||||
found = true
|
||||
break
|
||||
if ag.matches(g) {
|
||||
// take the first matched group as correct
|
||||
if g.Gid < minID || g.Gid > maxID {
|
||||
return nil, ErrRange
|
||||
}
|
||||
gidMap[g.Gid] = struct{}{}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// we asked for a group but didn't find it. let's check to see
|
||||
// if we wanted a numeric group
|
||||
// We asked for a group but didn't find it. Numeric group IDs may be
|
||||
// used as-is even when they are not present in /etc/group; non-numeric
|
||||
// group names must be found.
|
||||
if !found {
|
||||
gid, err := strconv.ParseInt(ag, 10, 64)
|
||||
if err != nil {
|
||||
if !ag.isNumeric {
|
||||
// Not a numeric ID either.
|
||||
return nil, fmt.Errorf("Unable to find group %s: %w", ag, ErrNoGroupEntries)
|
||||
return nil, fmt.Errorf("unable to find group %s: %w", ag.name, ErrNoGroupEntries)
|
||||
}
|
||||
// Ensure gid is inside gid range.
|
||||
if gid < minID || gid > maxID {
|
||||
return nil, ErrRange
|
||||
}
|
||||
gidMap[int(gid)] = struct{}{}
|
||||
gidMap[ag.gid] = struct{}{}
|
||||
}
|
||||
}
|
||||
gids := []int{}
|
||||
@@ -498,12 +511,7 @@ func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int
|
||||
}
|
||||
|
||||
func ParseSubIDFile(path string) ([]SubID, error) {
|
||||
subid, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer subid.Close()
|
||||
return ParseSubID(subid)
|
||||
return ParseSubIDFileFilter(path, nil)
|
||||
}
|
||||
|
||||
func ParseSubID(subid io.Reader) ([]SubID, error) {
|
||||
@@ -551,12 +559,7 @@ func ParseSubIDFilter(r io.Reader, filter func(SubID) bool) ([]SubID, error) {
|
||||
}
|
||||
|
||||
func ParseIDMapFile(path string) ([]IDMap, error) {
|
||||
r, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
return ParseIDMap(r)
|
||||
return ParseIDMapFileFilter(path, nil)
|
||||
}
|
||||
|
||||
func ParseIDMap(r io.Reader) ([]IDMap, error) {
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
//go:build gofuzz
|
||||
// +build gofuzz
|
||||
|
||||
package user
|
||||
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// maxUserFileBytes caps how much data is read from any user-database file.
|
||||
// User database files are expected to be relatively small. 10 MiB provides
|
||||
// generous headroom while bounding memory usage.
|
||||
const maxUserFileBytes = 10 << 20
|
||||
|
||||
// openUserFile attempts to open a user-database file with a limitedFile
|
||||
// capped at maxUserFileBytes. It produces an error if the given path is
|
||||
// a non-regular file.
|
||||
func openUserFile(path string) (*limitedFile, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return nil, err
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
_ = f.Close()
|
||||
return nil, &os.PathError{
|
||||
Op: "open",
|
||||
Path: path,
|
||||
Err: errors.New("not a regular file"),
|
||||
}
|
||||
}
|
||||
|
||||
return &limitedFile{
|
||||
File: f,
|
||||
// Allow one byte past the cap so an overflow surfaces as an
|
||||
// error rather than a silent EOF that the parser would treat as
|
||||
// a clean end-of-file (and miss any entries past the cap).
|
||||
LimitedReader: &io.LimitedReader{R: f, N: maxUserFileBytes + 1},
|
||||
name: path,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type limitedFile struct {
|
||||
*os.File
|
||||
*io.LimitedReader
|
||||
name string
|
||||
}
|
||||
|
||||
func (l *limitedFile) Read(p []byte) (int, error) {
|
||||
n, err := l.LimitedReader.Read(p)
|
||||
if l.LimitedReader.N == 0 {
|
||||
return n, &os.PathError{
|
||||
Op: "read",
|
||||
Path: l.name,
|
||||
Err: fmt.Errorf("file exceeds %d bytes", maxUserFileBytes),
|
||||
}
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
Reference in New Issue
Block a user