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

clustermesh: Ignore symlink files on fsnotify events #14565

Merged
merged 1 commit into from
Jan 12, 2021

Conversation

tgraf
Copy link
Member

@tgraf tgraf commented Jan 8, 2021

Kubernetes secrets are mapped into the pod using symlinks. The initial
scan was already correctly ignoring symlinks but the fsnotify events
have not been. This has resulted in invalid cluster configurations being
added:

ClusterMesh:            0/3 clusters ready, 0 global-services
   cluster2: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established
   ..2021_01_08_21_11_57.892158678: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established
   ..data: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established

Fixes: 076b018 ("Inter cluster connectivity (ClusterMesh)")

Kubernetes secrets are mapped into the pod using symlinks. The initial
scan was already correctly ignoring symlinks but the fsnotify events
have not been. This has resulted in invalid cluster configurations being
added:

```
ClusterMesh:            0/3 clusters ready, 0 global-services
   cluster2: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established
   ..2021_01_08_21_11_57.892158678: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established
   ..data: not-ready, 0 nodes, 0 identities, 0 services, 0 failures (last: never)
   └  Waiting for initial connection to be established
```

Fixes: 076b018 ("Inter cluster connectivity (ClusterMesh)")

Signed-off-by: Thomas Graf <thomas@cilium.io>
@tgraf tgraf added kind/bug This is a bug in the Cilium logic. release-note/bug This PR fixes an issue in a previous release of Cilium. area/clustermesh Relates to multi-cluster routing functionality in Cilium. needs-backport/1.7 labels Jan 8, 2021
@tgraf tgraf requested a review from a team as a code owner January 8, 2021 22:22
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.10.0 Jan 8, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.7 Jan 8, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.9.2 Jan 8, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.7.13 Jan 8, 2021
@aanm
Copy link
Member

aanm commented Jan 8, 2021

@kaworu can we reuse the same code done for hubble-relay certificates in here? It looks to me the code use in both places have the same functionalities

@tgraf
Copy link
Member Author

tgraf commented Jan 8, 2021

test-me-please

@tgraf
Copy link
Member Author

tgraf commented Jan 8, 2021

@kaworu can we reuse the same code done for hubble-relay certificates in here? It looks to me the code use in both places have the same functionalities

I agree that's a good refactoring but we should fix the existing code first so we back backport the minimal fix.

@tgraf
Copy link
Member Author

tgraf commented Jan 11, 2021

retest-gke

@kaworu
Copy link
Member

kaworu commented Jan 11, 2021

@kaworu can we reuse the same code done for hubble-relay certificates in here? It looks to me the code use in both places have the same functionalities

If I understand correctly, the use case is a little different between clustermesh and hubble mTLS. In the clustermesh case we don't know what paths are going to show up, whereas in the Hubble mTLS case we know all the paths we should watch at startup. Although this should not be blocking (if correct) the change is probably not trivial and separate warrant a refactor as @tgraf suggested.

Question: here we are watching the symlinks under /var/lib/cilium/clustermesh and avoiding the files pointed to in the /var/lib/cilium/clustermesh/..2021_01_11_12_28_37.877026628/ directory correct? If yes, do we get update events when the backing files change? I believe we don't, and that is why pkg/crypto/certloader/fswatcher is complex. cc @gandro

@gandro
Copy link
Member

gandro commented Jan 11, 2021

Question: here we are watching the symlinks under /var/lib/cilium/clustermesh and avoiding the files pointed to in the /var/lib/cilium/clustermesh/..2021_01_11_12_28_37.877026628/ directory correct? If yes, do we get update events when the backing files change? I believe we don't, and that is why pkg/crypto/certloader/fswatcher is complex. cc @gandro

Yes, I agree with your statement: Because K8s uses indirect symlinks (see example below), the code here will observe cluster file being added and clusters being removed, but not cluster files being modified. Not sure how much of an issue that is, I lack a bit conext when it comes to clustermesh.

As a reminder, the symlink structure of K8s is as follows:

/var/lib/cilium/clustermesh/..data -> ..2021_01_01_01_01_01.11111111
/var/lib/cilium/clustermesh/cluster1 -> ..data/cluster1

Thus /var/lib/cilium/clustermesh/cluster1 is an indirect symlink that resolves to /var/lib/cilium/clustermesh/..data1/cluster1 which resolves to /var/lib/cilium/clustermesh/..2021_01_01_01_01_01.11111111/cluster1

When K8s updates the secret mount (e.g. when a cluster file is modified), the new version of each file is copied into a new directory called ..2021_02_02_02_02_02.22222222 and the ..data symlink is redirected:

/var/lib/cilium/clustermesh/..data -> ..2021_02_02_02_02_02.22222222

Now the /var/lib/cilium/clustermesh/cluster1 symlink now resolves to /var/lib/cilium/clustermesh/..2021_02_02_02_02_02.22222222/cluster1 even though the cluster1 symlink itself has not been touched at all. This update is missed by the fsnotify code here.

The old and new code here will pick up the creation and deletion of the /var/lib/cilium/clustermesh/cluster1 symlink, but not the rewrite of the ..data symlink.

However: I believe the fact that cluster file modifications are not tracked is already present in the old version of the code (because the ..foo directories are not watched in either version), so in that sense this PR does not change the behavior in this regard

@tgraf
Copy link
Member Author

tgraf commented Jan 11, 2021

Yes, the lack of notification is potentially an issue although the primary use case is to detect new files and deletions as modifications will be extremely rare. The cluster name to IP mapping is not in the secret but in the hostAliases of the DaemonSet itself. A change in the secrets would only occur if a cluster changes its TLS certificates.

@gandro
Copy link
Member

gandro commented Jan 12, 2021

GKE scaling failure https://jenkins.cilium.io/job/Cilium-PR-K8s-GKE/3892/

retest-gke

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jan 12, 2021
@gandro gandro merged commit f034507 into master Jan 12, 2021
@gandro gandro deleted the pr/tgraf/fix-clustermesh-config-filter branch January 12, 2021 12:41
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.9 in 1.9.2 Jan 14, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.9 to Backport done to v1.9 in 1.9.2 Jan 18, 2021
This was referenced Jan 19, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.8 in 1.8.7 Jan 20, 2021
This was referenced Jan 20, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.7 in 1.7.13 Jan 20, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.7 to Backport done to v1.7 in 1.7.13 Jan 21, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.8 to Backport done to v1.8 in 1.8.7 Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustermesh Relates to multi-cluster routing functionality in Cilium. kind/bug This is a bug in the Cilium logic. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium.
Projects
No open projects
1.7.13
Backport done to v1.7
1.8.7
Backport done to v1.8
1.9.2
Backport done to v1.9
Development

Successfully merging this pull request may close these issues.

None yet

7 participants