Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: new mode -l passthrough-tty #20774

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,12 @@ func AutocompleteImageVolume(cmd *cobra.Command, args []string, toComplete strin
}

// AutocompleteLogDriver - Autocomplete log-driver options.
// -> "journald", "none", "k8s-file", "passthrough"
// -> "journald", "none", "k8s-file", "passthrough", "passthrough-tty"
func AutocompleteLogDriver(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// don't show json-file
logDrivers := []string{define.JournaldLogging, define.NoLogging, define.KubernetesLogging}
if !registry.IsRemote() {
logDrivers = append(logDrivers, define.PassthroughLogging)
logDrivers = append(logDrivers, define.PassthroughLogging, define.PassthroughTTYLogging)
}
return logDrivers, cobra.ShellCompDirectiveNoFileComp
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func create(cmd *cobra.Command, args []string) error {
}
}

if cliVals.LogDriver != define.PassthroughLogging {
if cliVals.LogDriver != define.PassthroughLogging && cliVals.LogDriver != define.PassthroughTTYLogging {
fmt.Println(report.Id)
}
return nil
Expand Down Expand Up @@ -239,12 +239,17 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra

if cliVals.LogDriver == define.PassthroughLogging {
if term.IsTerminal(0) || term.IsTerminal(1) || term.IsTerminal(2) {
return vals, errors.New("the '--log-driver passthrough' option cannot be used on a TTY")
return vals, errors.New("the '--log-driver passthrough' option cannot be used on a TTY. If you really want it, use '--log-driver passthrough-tty'")
}
if registry.IsRemote() {
return vals, errors.New("the '--log-driver passthrough' option is not supported in remote mode")
}
}
if cliVals.LogDriver == define.PassthroughTTYLogging {
if registry.IsRemote() {
return vals, errors.New("the '--log-driver passthrough-tty' option is not supported in remote mode")
}
}

if !isInfra {
if c.Flag("cpu-period").Changed && c.Flag("cpus").Changed {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func run(cmd *cobra.Command, args []string) error {
runOpts.InputStream = nil
}

passthrough := cliVals.LogDriver == define.PassthroughLogging
passthrough := cliVals.LogDriver == define.PassthroughLogging || cliVals.LogDriver == define.PassthroughTTYLogging

// If attach is set, clear stdin/stdout/stderr and only attach requested
if cmd.Flag("attach").Changed {
Expand Down
4 changes: 3 additions & 1 deletion docs/source/markdown/options/log-driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
####> are applicable to all of those.
#### **--log-driver**=*driver*

Logging driver for the container. Currently available options are **k8s-file**, **journald**, **none** and **passthrough**, with **json-file** aliased to **k8s-file** for scripting compatibility. (Default **journald**).
Logging driver for the container. Currently available options are **k8s-file**, **journald**, **none**, **passthrough** and **passthrough-tty**, with **json-file** aliased to **k8s-file** for scripting compatibility. (Default **journald**).

The podman info command below displays the default log-driver for the system.
```
Expand All @@ -14,3 +14,5 @@ journald
The **passthrough** driver passes down the standard streams (stdin, stdout, stderr) to the
container. It is not allowed with the remote Podman client, including Mac and Windows (excluding WSL2) machines, and on a tty, since it is
vulnerable to attacks via TIOCSTI.

The **passthrough-tty** driver is the same as **passthrough** except that it also allows it to be used on a TTY if the user really wants it.
7 changes: 5 additions & 2 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *Container) StartAndAttach(ctx context.Context, streams *define.AttachSt
// Attach to the container before starting it
go func() {
// Start resizing
if c.LogDriver() != define.PassthroughLogging {
if c.LogDriver() != define.PassthroughLogging && c.LogDriver() != define.PassthroughTTYLogging {
registerResizeFunc(resize, c.bundlePath())
}

Expand Down Expand Up @@ -304,6 +304,9 @@ func (c *Container) Attach(streams *define.AttachStreams, keys string, resize <-
if c.LogDriver() == define.PassthroughLogging {
return fmt.Errorf("this container is using the 'passthrough' log driver, cannot attach: %w", define.ErrNoLogs)
}
if c.LogDriver() == define.PassthroughTTYLogging {
return fmt.Errorf("this container is using the 'passthrough-tty' log driver, cannot attach: %w", define.ErrNoLogs)
}
if !c.batched {
c.lock.Lock()
if err := c.syncContainer(); err != nil {
Expand Down Expand Up @@ -336,7 +339,7 @@ func (c *Container) Attach(streams *define.AttachStreams, keys string, resize <-
}

// Start resizing
if c.LogDriver() != define.PassthroughLogging {
if c.LogDriver() != define.PassthroughLogging && c.LogDriver() != define.PassthroughTTYLogging {
registerResizeFunc(resize, c.bundlePath())
}

Expand Down
3 changes: 3 additions & 0 deletions libpod/define/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const NoLogging = "none"
// PassthroughLogging is the string conmon expects when specifying to use the passthrough driver
const PassthroughLogging = "passthrough"

// PassthroughTTYLogging is the string conmon expects when specifying to use the passthrough driver even on a tty.
const PassthroughTTYLogging = "passthrough-tty"

// DefaultRlimitValue is the value set by default for nofile and nproc
const RLimitDefaultValue = uint64(1048576)

Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_attach_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// Does not check if state is appropriate.
// started is only required if startContainer is true.
func (r *ConmonOCIRuntime) Attach(c *Container, params *AttachOptions) error {
passthrough := c.LogDriver() == define.PassthroughLogging
passthrough := c.LogDriver() == define.PassthroughLogging || c.LogDriver() == define.PassthroughTTYLogging

if params == nil || params.Streams == nil {
return fmt.Errorf("must provide parameters to Attach: %w", define.ErrInternal)
Expand Down
2 changes: 1 addition & 1 deletion libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
logDriverArg = define.JournaldLogging
case define.NoLogging:
logDriverArg = define.NoLogging
case define.PassthroughLogging:
case define.PassthroughLogging, define.PassthroughTTYLogging:
logDriverArg = define.PassthroughLogging
//lint:ignore ST1015 the default case has to be here
default: //nolint:gocritic
Expand Down
2 changes: 1 addition & 1 deletion libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ func WithLogDriver(driver string) CtrCreateOption {
switch driver {
case "":
return fmt.Errorf("log driver must be set: %w", define.ErrInvalidArg)
case define.JournaldLogging, define.KubernetesLogging, define.JSONLogging, define.NoLogging, define.PassthroughLogging:
case define.JournaldLogging, define.KubernetesLogging, define.JSONLogging, define.NoLogging, define.PassthroughLogging, define.PassthroughTTYLogging:
break
default:
return fmt.Errorf("invalid log driver: %w", define.ErrInvalidArg)
Expand Down
20 changes: 20 additions & 0 deletions test/system/450-interactive.bats
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,24 @@ function teardown() {
is "$output" "hello$CR" "-i=false: no warning"
}


@test "podman run -l passthrough-tty" {
skip_if_remote

giuseppe marked this conversation as resolved.
Show resolved Hide resolved
# Requires conmon 2.1.10 or greater
want=2.1.10
run_podman info --format '{{.Host.Conmon.Path}}'
conmon_path="$output"
conmon_version=$($conmon_path --version | sed -ne 's/^.* version //p')
if ! printf "%s\n%s\n" "$want" "$conmon_version" | sort --check=quiet --version-sort; then
skip "need conmon >= $want; have $conmon_version"
fi

run tty <$PODMAN_TEST_PTY
expected_tty="$output"

run_podman run -v/dev:/dev --log-driver=passthrough-tty $IMAGE tty <$PODMAN_TEST_PTY
is "$output" "$expected_tty" "passthrough-tty: tty matches"
}

# vim: filetype=sh
Loading