Skip to content

fix(plugins/container): update docker containers on rename - #1602

Merged
poiana merged 1 commit into
falcosecurity:mainfrom
rajanpanth:container-docker-rename
Nov 4, 2026
Merged

poiana merged 1 commit into
falcosecurity:mainfrom
rajanpanth:container-docker-rename

Conversation

@rajanpanth

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area plugins

What this PR does / why we need it:

The docker listener of the container plugin's go-worker only subscribed to the create, start and destroy events. When docker compose up recreates a container, docker creates it under a temporary <old-id[:12]>_<name> name and renames it before starting it. With the default hooks: ['create'], the container was inspected while it still had the temporary name and nothing updated it afterwards, so container.name stayed wrong until Falco restarted. A plain docker rename of a running container was never picked up either, whatever the hooks.

This PR always subscribes to the docker rename event and re-inspects the container like on create/start. The C++ side already overwrites the cached container on a new "added" event, so the cached name and the rest of the metadata get refreshed. If the inspection after a rename fails, nothing is sent, so the cached metadata is kept instead of being replaced with the minimum set.

The rename subscription doesn't depend on the hooks setting: a rename isn't a lifecycle hook, it changes metadata of a container that may already be cached whatever hook reported it. An alternative would be a new opt-in rename hook value, but then the default config would stay broken for compose unless it became a default too. Happy to switch if maintainers prefer that.

A new TestDockerListenRename replays the compose sequence (create under the temporary name, then rename) against a fake Docker API that only sends the events matching the listener filters. It checks the final name with and without the create hook, and that a failed inspection on rename sends nothing.

Which issue(s) this PR fixes:

Fixes #1601

Special notes for your reviewer:

  • Each rename now produces an extra "added" async event for the container (the same thing happens today with the start hook).
  • Only docker is changed. Podman also emits rename events; I can extend podman.go the same way here or in a follow-up if you want.
  • Tested with the go-worker unit tests on Linux (WSL, docker daemon available). The new test fails without the change.
  • This change was prepared with AI assistance and reviewed by the author.

🤖 Generated with Claude Code

The docker listener only subscribed to the create, start and destroy
events. docker compose creates a recreated container under a temporary
`<old-id[:12]>_<name>` name and renames it before starting it, so with
the default `create` hook the cached container kept the temporary name
until Falco restarted; a `docker rename` was never picked up either.

Always subscribe to the rename event, whatever hooks are attached, and
re-inspect the container like on create and start. If the inspection
fails, keep the cached metadata instead of replacing them with the
minimum set.

Signed-off-by: rajanpanth <rajan.pantha@samriddhicollege.edu.np>
@poiana

poiana commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Welcome @rajanpanth! It looks like this is your first PR to falcosecurity/plugins 🎉

@leogr leogr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks! 🙏

@poiana poiana added the lgtm label Nov 4, 2026
@poiana

poiana commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: leogr, rajanpanth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana

poiana commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 387054d481e525e62148bced35aa7f1c5ac47981

@poiana poiana added the approved label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Rules files suggestions

@poiana
poiana merged commit dbc25c5 into falcosecurity:main Nov 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[container] docker: default create-only hook keeps compose's temporary container name (<id12>_<name>)

3 participants