Skip to content

fix: keep the honeytoken secret when other deployments still mount it - #67

Merged
mariotrace merged 2 commits into
dynatrace-oss:mainfrom
knQzx:fix/keep-shared-honeytoken-secret
Sep 4, 2026
Merged

mariotrace merged 2 commits into
dynatrace-oss:mainfrom
knQzx:fix/keep-shared-honeytoken-secret

Conversation

@knQzx

@knQzx knQzx commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

removeDecoyWithVolumeMount deletes the honeytoken secret unconditionally, and the comment explains it away with a guarantee that does not exist:

// This might fail if the secret is still being used by another pod, we ignore the error
_ = r.Delete(ctx, &secret)

the API server does not block deleting a secret that is still mounted, the pods simply fail to start the next time they are scheduled

that matters because the secret is not scoped to a policy or a workload. generateSecretName hashes only filePath + ":" + fileContent, so every deployment in a namespace that matches the trap mounts the very same secret, and two DeceptionPolicy objects with identical path and content share it too

so narrowing one policy, or removing a trap from one deployment, deletes a secret that other deployments still reference. they keep running on the mounted copy until the first restart and then sit in ContainerCreating with secret not found, while their honeytoken quietly disappears

this checks the remaining deployments in the namespace before deleting. the secret is also kept when the deployment update failed, because then this deployment still mounts it, and volume.Secret is now guarded against nil. added tests for the sole-user, shared-user and failed-update cases

@knQzx
knQzx force-pushed the fix/keep-shared-honeytoken-secret branch from e04fb83 to 81f987a Compare August 10, 2026 14:46
// mounted by other deployments that match the trap. Kubernetes does not stop us from deleting
// a secret that is still in use, their pods would just fail to start on the next restart,
// so we have to check the remaining deployments ourselves. We also keep the secret when the
// update above failed, because then this deployment still mounts it.

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.

Just a nit to prefer a briefer comment to match the surrounding code style:

// Before deleting the secret, we should check for other mounters because the secret
// could be shared and in-use by other deployments with matching trap content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

shortened to your version, thanks!

// a secret that is still in use, their pods would just fail to start on the next restart,
// so we have to check the remaining deployments ourselves. We also keep the secret when the
// update above failed, because then this deployment still mounts it.
if secretName != "" && err == nil {

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.

[PRAISE] That is a solid function, thank you for finding this! 🥳

@knQzx
knQzx force-pushed the fix/keep-shared-honeytoken-secret branch from 66beb59 to 03c883c Compare September 3, 2026 22:03
@mariotrace
mariotrace merged commit c001345 into dynatrace-oss:main Sep 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants