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

[CWS] fix docker image parsing in ptracer #31400

Merged
merged 1 commit into from
Nov 25, 2024
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
24 changes: 9 additions & 15 deletions pkg/security/ptracer/container_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ package ptracer
import (
"encoding/json"
"os"
"strings"
"time"

"github.com/DataDog/datadog-agent/pkg/security/proto/ebpfless"
"github.com/DataDog/datadog-agent/pkg/util/containers/image"
)

// ECSMetadata defines ECS metadata
Expand Down Expand Up @@ -68,20 +68,14 @@ func newContainerContext(containerID string) (*ebpfless.ContainerContext, error)
ctx.Name = data.DockerName
}
if data.Image != "" {
image := data.Image
lastSlash := strings.LastIndex(image, "/")
lastColon := strings.LastIndex(image, ":")
if lastColon > -1 && lastColon > lastSlash {
ctx.ImageTag = image[lastColon+1:]
image = image[:lastColon]
}
if lastSlash > -1 {
ctx.ImageShortName = image[lastSlash+1:]
} else {
ctx.ImageShortName = image
}
if ctx.ImageShortName != "" && ctx.ImageTag == "" {
ctx.ImageTag = "latest"
_, _, shortImageName, tag, err := image.SplitImageName(data.Image)
if err == nil {
ctx.ImageShortName = shortImageName
if tag != "" {
ctx.ImageTag = tag
} else {
ctx.ImageTag = "latest"
}
}
}
}
Expand Down
Loading