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

identity: Fix user-space security identity lookup in cluster mesh #13205

Merged

Conversation

gandro
Copy link
Member

@gandro gandro commented Sep 17, 2020

When looking up a security identity (either by its numeric id or by
labels) in user-space (e.g. in Hubble or the API), we want to ensure to
also include identities owned by remote clusters in cluster mesh too.

Before this commit, GetIdentities function of the identity allocator
(e.g. used for cilium identity list) would return all global
identities (i.e. including the ones from remote clusters as well), while
LookupIdentity{,ByID} would only return identitiies found the main
kvstore, ignoring any attached remote kvstores. This commit

This fixes multiple missed annotations which can occur in cluster-mesh
setups:

  • Hubble failed to annotate identities from remote clusters (Hubble fails to resolve identities across a cluster mesh. #13076).

  • While the API would list remote identities in /v1/identities,
    performing a lookup on identities from remote clusters via API would
    fail with a "not found error". This 404 could be observed in
    cilium identity get <remote-id> or in cilium bpf policy get.

  • DNS proxy logrecords would not have the destination endpoint labels
    populated.

  • The CiliumEndpoint.Status.Policy CRD field would not contain
    labels for identities for remote clusters (if CEP status updates
    were enabled).

Fixes: #13076

Fix bug where Hubble and the Cilium CLI would fail to resolve security identities across a cluster mesh.

@gandro gandro added release-note/bug This PR fixes an issue in a previous release of Cilium. area/clustermesh Relates to multi-cluster routing functionality in Cilium. labels Sep 17, 2020
@gandro gandro requested a review from a team as a code owner September 17, 2020 14:33
@gandro gandro requested a review from a team September 17, 2020 14:33
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.4 Sep 17, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.7.10 Sep 17, 2020
@@ -201,7 +201,8 @@ func (w *identityWatcher) stop() {

// LookupIdentity looks up the identity by its labels but does not create it.
// This function will first search through the local cache and fall back to
// querying the kvstore.
// querying all connected kvstores (first the main kvstore, followed by any
// watched remote kvstores in clustermesh)
func (m *CachingIdentityAllocator) LookupIdentity(ctx context.Context, lbls labels.Labels) *identity.Identity {
Copy link
Member Author

@gandro gandro Sep 17, 2020

Choose a reason for hiding this comment

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

Note to reviewers: While we surely want to fix the lookup in this function for the API to work correctly (any identity returned by /v1/identities should also be fetchable via labels), the only non-API call site (outside of unit tests) of this function is in the IPCache:

if id := IdentityAllocator.LookupIdentity(context.TODO(), cidr.GetCIDRLabels(prefix)); id != nil {

IPCache is performing a lookup on CIDR labels. I don't think we want to send that lookup to remote kvstores (since CIDR identies are always local), so maybe we have to introduce an additional lookup function for the IPCache usecase? Unfortunatley I'm not too familiar with local identity management, so feedback welcome.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, CIDR identities are purely local to the agent (not even shared across the cluster), so we should follow up to change the lookup function to reflect this usage.

@tgraf tgraf self-requested a review September 17, 2020 14:53
@gandro
Copy link
Member Author

gandro commented Sep 17, 2020

test-me-please

Copy link
Member

@tgraf tgraf left a comment

Choose a reason for hiding this comment

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

LGTM except for what we discussed on Zoom

When looking up a security identity (either by its numeric id or by
labels) in user-space (e.g. in Hubble or the API), we want to ensure to
also include identities owned by remote clusters in cluster mesh too.

Before this commit, `GetIdentities` function of the identity allocator
(e.g. used for `cilium identity list`) would return all global
identities (i.e. including the ones from remote clusters as well), while
`LookupIdentity{,ByID}` would only return identities found the main
kvstore, ignoring any indentities cached from remote kvstores.

This fixes multiple missed annotations which can occur in cluster-mesh
setups:

  - Hubble failed to annotate identities from remote clusters (#13076).

  - While the API would list remote identities in `/v1/identities`,
    performing a lookup on identities from remote clusters via API would
    fail with a "not found error". This 404 could be observed in
    `cilium identity get <remote-id>` or in `cilium bpf policy get`.

  - DNS proxy logrecords would not have the destination endpoint labels
    populated.

  - The `CiliumEndpoint.Status.Policy` CRD field would not contain
    labels for identities for remote clusters (if CEP status updates
    were enabled).

Fixes: #13076

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
@gandro gandro force-pushed the pr/gandro/hubble-fix-identity-lookup-in-cluster-mesh branch from 4d2ed3b to b2ea910 Compare September 17, 2020 17:14
@gandro
Copy link
Member Author

gandro commented Sep 17, 2020

Pushed the discussed change to not query remote backends in order avoid accidental DDoS. We now only check the remote caches. Diff of change since approval

@gandro
Copy link
Member Author

gandro commented Sep 17, 2020

test-me-please

@@ -201,7 +201,8 @@ func (w *identityWatcher) stop() {

// LookupIdentity looks up the identity by its labels but does not create it.
// This function will first search through the local cache and fall back to
// querying the kvstore.
// querying all connected kvstores (first the main kvstore, followed by any
// watched remote kvstores in clustermesh)
func (m *CachingIdentityAllocator) LookupIdentity(ctx context.Context, lbls labels.Labels) *identity.Identity {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, CIDR identities are purely local to the agent (not even shared across the cluster), so we should follow up to change the lookup function to reflect this usage.

@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 Sep 17, 2020
@joestringer joestringer merged commit 72f6685 into master Sep 17, 2020
@joestringer joestringer deleted the pr/gandro/hubble-fix-identity-lookup-in-cluster-mesh branch September 17, 2020 19:29
@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.10 Sep 17, 2020
@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.10 Sep 17, 2020
@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.4 Sep 18, 2020
@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.10 Sep 18, 2020
@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.4 Sep 21, 2020
@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.4 Sep 21, 2020
gandro added a commit that referenced this pull request Sep 22, 2020
Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
qmonnet pushed a commit that referenced this pull request Sep 22, 2020
Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
vadorovsky pushed a commit that referenced this pull request Sep 25, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
vadorovsky pushed a commit that referenced this pull request Sep 25, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
gandro added a commit that referenced this pull request Sep 29, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit that referenced this pull request Sep 29, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
gandro added a commit that referenced this pull request Sep 29, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
aanm pushed a commit that referenced this pull request Sep 29, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
christarazi pushed a commit that referenced this pull request Sep 29, 2020
[ upstream commit f3424a3 ]

Reserved and CIDR identities are local to the agent and not stored in
the kvstore. This commit changes the identity cache to avoid performing
a kvstore lookup for CIDR entries (which is currently done when a CIDR
identity is released).

This is a follow-up to
#13205 (comment)

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
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. 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.10
Backport done to v1.7
1.8.4
Backport done to v1.8
Development

Successfully merging this pull request may close these issues.

Hubble fails to resolve identities across a cluster mesh.
5 participants