Skip to content
New issue

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

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

Already on GitHub? # to your account

info: skip client-side warning about seccomp profile on API >= 1.42 #3230

Merged
merged 1 commit into from
Aug 24, 2021
Merged
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
30 changes: 27 additions & 3 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/cli/templates"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/go-units"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -254,9 +255,6 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
for _, o := range so.Options {
switch o.Key {
case "profile":
if o.Value != "default" {
Copy link
Member Author

@thaJeztah thaJeztah Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpuguy83 updated; PTAL

Alternatively, I could do:

Suggested change
if o.Value != "default" {
if o.Value != "default" && o.Value != "builtin" && versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {

Which would bring a smaller patch, but I tried to also group the warning with the other warnings (printed at the end) instead of having it "half-way" the docker info output here. Happy to change though if you think that's an issue.

fmt.Fprintln(dockerCli.Err(), " WARNING: You're not using the default seccomp profile")
}
fmt.Fprintln(dockerCli.Out(), " Profile:", o.Value)
}
}
Expand Down Expand Up @@ -421,6 +419,9 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
}

func printServerWarnings(dockerCli command.Cli, info types.Info) {
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {
printSecurityOptionsWarnings(dockerCli, info)
}
if len(info.Warnings) > 0 {
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
return
Expand All @@ -430,6 +431,29 @@ func printServerWarnings(dockerCli command.Cli, info types.Info) {
printServerWarningsLegacy(dockerCli, info)
}

// printSecurityOptionsWarnings prints warnings based on the security options
// returned by the daemon.
// DEPRECATED: warnings are now generated by the daemon, and returned in
// info.Warnings. This function is used to provide backward compatibility with
// daemons that do not provide these warnings. No new warnings should be added
// here.
func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
if info.OSType == "windows" {
return
}
kvs, _ := types.DecodeSecurityOptions(info.SecurityOptions)
for _, so := range kvs {
if so.Name != "seccomp" {
continue
}
for _, o := range so.Options {
if o.Key == "profile" && o.Value != "default" && o.Value != "builtin" {
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING: You're not using the default seccomp profile")
}
}
}
}

// printServerWarningsLegacy generates warnings based on information returned by the daemon.
// DEPRECATED: warnings are now generated by the daemon, and returned in
// info.Warnings. This function is used to provide backward compatibility with
Expand Down