Skip to content
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ curl -fsSLO https://github.com/opf/recense/releases/latest/download/install.sh
sudo sh install.sh
```

The installer verifies the release archive checksum, installs binaries under `/opt/recense/bin`, and starts `recense.service`. Rerun with a release tag to upgrade or downgrade: `sudo sh install.sh v0.2.2`.
The installer verifies the release archive checksum, installs binaries under `/opt/recense/bin`, and starts `recense.service`. Rerun with a release tag to upgrade or downgrade: `sudo sh install.sh v0.2.3`.

```sh
sudo systemctl status recense
Expand All @@ -40,7 +40,7 @@ For EC2-backed EKS or other Linux Kubernetes nodes with containerd and CRI v1:

```sh
helm upgrade --install recense \
https://github.com/opf/recense/releases/download/v0.2.2/recense-0.2.2.tgz \
https://github.com/opf/recense/releases/download/v0.2.3/recense-0.2.3.tgz \
--namespace recense --create-namespace \
--set clusterName=production-eks \
--set environment=production
Expand Down Expand Up @@ -145,3 +145,15 @@ Filter logs by `service.name = recense`, then by event type:
Keep all detected packages in scope. Use dashboard filters to prioritize High/Critical findings and available fixes. Counts represent package/advisory matches, not unique CVEs. Choose the latest successful scan per target before aggregating; summing several days repeats findings. Show failed scans and scan age separately.

Schema 3 uses standard OpenTelemetry names for service, host, cluster, and deployment identity. All custom fields use `recense.`. Scanned-container metadata uses `recense.target.*`; collector resource attributes identify the Recense pod. Old field aliases are not emitted.

### Container image identity

For CRI/containerd, `recense.target.image.name` comes from container status.
`recense.target.image.reference` holds the repository-qualified registry digest
(for example, `registry/app@sha256:…`). `recense.target.image.id` remains the
runtime image ID; it may identify the image configuration rather than the
manifest shown in ECR. Registry references are empty when unavailable. Docker
discovery currently reports its image name and runtime ID only.

These fields describe the image used to create the container. Scans inspect its
running filesystem, which can differ from the original image.
4 changes: 2 additions & 2 deletions charts/recense/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: recense
description: Host and container software inventory and vulnerability logs
type: application
version: 0.2.2
appVersion: "0.2.2"
version: 0.2.3
appVersion: "0.2.3"
2 changes: 1 addition & 1 deletion charts/recense/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
repository: ghcr.io/opf/recense
tag: "0.2.2"
tag: "0.2.3"
pullPolicy: IfNotPresent
imagePullSecrets: []
clusterName: ""
Expand Down
1 change: 1 addition & 0 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func containerFields(c container, runtimeName string) Event {
"recense.target.container.runtime": runtimeName,
"recense.target.image.id": c.ImageID,
"recense.target.image.name": c.ImageName,
"recense.target.image.reference": c.ImageReference,
"recense.target.k8s.namespace.name": c.PodNamespace,
"recense.target.k8s.pod.name": c.PodName,
"recense.target.k8s.container.name": c.PodContainer,
Expand Down
16 changes: 13 additions & 3 deletions internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ func (f *criFixture) ListContainers(_ context.Context, r *cri.ListContainersRequ
if r.Filter.State.State != cri.ContainerState_CONTAINER_RUNNING {
panic("wrong filter")
}
return &cri.ListContainersResponse{Containers: []*cri.Container{{Id: "c1", ImageRef: "sha256:config", Image: &cri.ImageSpec{Image: "app:latest"}, Metadata: &cri.ContainerMetadata{Name: "api"}, Labels: map[string]string{"io.kubernetes.pod.name": "api-123", "io.kubernetes.pod.namespace": "prod"}}}}, nil
return &cri.ListContainersResponse{Containers: []*cri.Container{{Id: "c1", ImageRef: "sha256:config", Image: &cri.ImageSpec{Image: "sha256:config"}, Metadata: &cri.ContainerMetadata{Name: "api"}, Labels: map[string]string{"io.kubernetes.pod.name": "api-123", "io.kubernetes.pod.namespace": "prod"}}}}, nil
}
func (f *criFixture) ContainerStatus(_ context.Context, r *cri.ContainerStatusRequest) (*cri.ContainerStatusResponse, error) {
if !r.Verbose || r.ContainerId != "c1" {
panic("wrong status request")
}
return &cri.ContainerStatusResponse{Status: &cri.ContainerStatus{State: cri.ContainerState_CONTAINER_RUNNING}, Info: map[string]string{"info": `{"pid":456,"secret":"never-log"}`}}, nil
return &cri.ContainerStatusResponse{Status: &cri.ContainerStatus{State: cri.ContainerState_CONTAINER_RUNNING, Image: &cri.ImageSpec{Image: "registry.example/app:release"}, ImageRef: "registry.example/app@sha256:manifest"}, Info: map[string]string{"info": `{"pid":456,"secret":"never-log"}`}}, nil
}
func TestCRIDiscoveryReadsPID(t *testing.T) {
socket := testSocket(t)
Expand All @@ -208,7 +208,7 @@ func TestCRIDiscoveryReadsPID(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(rows) != 1 || rows[0].ImageID != "sha256:config" || rows[0].PID != 456 || rows[0].PodNamespace != "prod" {
if len(rows) != 1 || rows[0].ImageID != "sha256:config" || rows[0].PID != 456 || rows[0].PodNamespace != "prod" || rows[0].ImageName != "registry.example/app:release" || rows[0].ImageReference != "registry.example/app@sha256:manifest" {
t.Fatalf("bad discovery: %#v", rows)
}
}
Expand Down Expand Up @@ -343,3 +343,13 @@ func testSocket(t *testing.T) string {
t.Cleanup(func() { os.RemoveAll(dir) })
return filepath.Join(dir, "s")
}

func TestRegistryReferenceDoesNotMislabelConfigID(t *testing.T) {
if registryReference("sha256:config") != "" {
t.Fatal("configuration ID is not a registry reference")
}
fields := containerFields(container{ImageID: "sha256:config", ImageName: "registry/app:tag", ImageReference: "registry/app@sha256:manifest"}, "containerd")
if fields["recense.target.image.reference"] != "registry/app@sha256:manifest" || fields["recense.target.image.id"] != "sha256:config" {
t.Fatalf("bad image fields: %#v", fields)
}
}
36 changes: 25 additions & 11 deletions internal/agent/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
var errContainerStopped = errors.New("container is no longer running")

type container struct {
ID, Name, ImageID, ImageName, PodName, PodNamespace, PodContainer string
PID int
ID, Name, ImageID, ImageName, ImageReference, PodName, PodNamespace, PodContainer string
PID int
}

func discover(ctx context.Context, c Config) ([]container, string, string, error) {
Expand Down Expand Up @@ -132,15 +132,15 @@ func criContainers(ctx context.Context, socket string) ([]container, error) {
if r.Metadata != nil {
name = r.Metadata.Name
}
pid, err := criPID(ctx, cri.NewRuntimeServiceClient(conn), r.Id)
pid, imageStatus, err := criStatus(ctx, cri.NewRuntimeServiceClient(conn), r.Id)
if errors.Is(err, errContainerStopped) {
continue
}
if err != nil {
return nil, err
}

result = append(result, container{ID: r.Id, Name: name, ImageID: r.ImageRef, ImageName: r.GetImage().GetImage(), PID: pid, PodName: r.Labels["io.kubernetes.pod.name"], PodNamespace: r.Labels["io.kubernetes.pod.namespace"], PodContainer: name})
result = append(result, container{ID: r.Id, Name: name, ImageID: r.ImageRef, ImageName: imageStatus.GetImage().GetImage(), ImageReference: registryReference(imageStatus.ImageRef), PID: pid, PodName: r.Labels["io.kubernetes.pod.name"], PodNamespace: r.Labels["io.kubernetes.pod.namespace"], PodContainer: name})
}
return result, nil
}
Expand Down Expand Up @@ -173,28 +173,42 @@ func dockerPID(ctx context.Context, client *http.Client, id string) (int, error)
return status.State.Pid, nil
}

func criPID(ctx context.Context, client cri.RuntimeServiceClient, id string) (int, error) {
func criStatus(ctx context.Context, client cri.RuntimeServiceClient, id string) (int, *cri.ContainerStatus, error) {
response, err := client.ContainerStatus(ctx, &cri.ContainerStatusRequest{ContainerId: id, Verbose: true})
if status.Code(err) == codes.NotFound {
return 0, errContainerStopped
return 0, nil, errContainerStopped
}
if err != nil {
return 0, fmt.Errorf("CRI container status: %w", err)
return 0, nil, fmt.Errorf("CRI container status: %w", err)
}
if response.Status == nil || response.Status.State != cri.ContainerState_CONTAINER_RUNNING {
return 0, errContainerStopped
return 0, nil, errContainerStopped
}
// Runtime info may contain environment secrets; decode only the PID.
var info struct {
PID int `json:"pid"`
}
if err := json.Unmarshal([]byte(response.Info["info"]), &info); err != nil {
return 0, fmt.Errorf("invalid CRI process metadata")
return 0, nil, fmt.Errorf("invalid CRI process metadata")
}
if info.PID <= 1 {
return 0, fmt.Errorf("runtime did not provide a running container PID")
return 0, nil, fmt.Errorf("runtime did not provide a running container PID")
}
return info.PID, nil
return info.PID, response.Status, nil
}

// Only repository-qualified references identify an image in a registry.
// Some runtimes return a bare configuration ID in ImageRef instead.
func registryReference(ref string) string {
if strings.Contains(ref, "@") {
return ref
}
return ""
}

func criPID(ctx context.Context, client cri.RuntimeServiceClient, id string) (int, error) {
pid, _, err := criStatus(ctx, client, id)
return pid, err
}

// Runtime identity must still match at scan time, even if the discovered PID
Expand Down
Loading