fix(sandbox): pass explicit user to docker exec for UID-mapped containers
After tai sandbox containers start as root with dynamic UID mapping, docker exec defaults to root. Add User field to ExecOptions and hardcode "sandbox" in Box.Exec/Stream to ensure commands run as the correct user. Made-with: Cursor
This commit is contained in:
parent
2084e20479
commit
c987bd687f
3 changed files with 5 additions and 0 deletions
|
|
@ -93,6 +93,7 @@ func (b *Box) Exec(ctx context.Context, cmd []string, opts ...ExecOption) (*Exec
|
||||||
result, err := res.Runtime.Exec(ctx, b.containerID, cmd, tairuntime.ExecOptions{
|
result, err := res.Runtime.Exec(ctx, b.containerID, cmd, tairuntime.ExecOptions{
|
||||||
WorkDir: cfg.WorkDir,
|
WorkDir: cfg.WorkDir,
|
||||||
Env: cfg.Env,
|
Env: cfg.Env,
|
||||||
|
User: "sandbox",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -123,6 +124,7 @@ func (b *Box) Stream(ctx context.Context, cmd []string, opts ...ExecOption) (*Ex
|
||||||
handle, err := res.Runtime.ExecStream(ctx, b.containerID, cmd, tairuntime.ExecOptions{
|
handle, err := res.Runtime.ExecStream(ctx, b.containerID, cmd, tairuntime.ExecOptions{
|
||||||
WorkDir: cfg.WorkDir,
|
WorkDir: cfg.WorkDir,
|
||||||
Env: cfg.Env,
|
Env: cfg.Env,
|
||||||
|
User: "sandbox",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ func (d *dockerCore) exec(ctx context.Context, id string, cmd []string, opts Exe
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
WorkingDir: opts.WorkDir,
|
WorkingDir: opts.WorkDir,
|
||||||
Env: envSlice(opts.Env),
|
Env: envSlice(opts.Env),
|
||||||
|
User: opts.User,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
}
|
}
|
||||||
|
|
@ -143,6 +144,7 @@ func (d *dockerCore) execStream(ctx context.Context, id string, cmd []string, op
|
||||||
Cmd: cmd,
|
Cmd: cmd,
|
||||||
WorkingDir: opts.WorkDir,
|
WorkingDir: opts.WorkDir,
|
||||||
Env: envSlice(opts.Env),
|
Env: envSlice(opts.Env),
|
||||||
|
User: opts.User,
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
AttachStdout: true,
|
AttachStdout: true,
|
||||||
AttachStderr: true,
|
AttachStderr: true,
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ type ContainerInfo struct {
|
||||||
type ExecOptions struct {
|
type ExecOptions struct {
|
||||||
WorkDir string
|
WorkDir string
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
|
User string // container exec user; empty = container default (container.Config.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecResult holds output from an exec command.
|
// ExecResult holds output from an exec command.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue