Skip to content

CertAuthority watcher filtering#10020

Merged
r0mant merged 28 commits intomasterfrom
espadolini/ca-watcher-filter
Feb 19, 2022
Merged

CertAuthority watcher filtering#10020
r0mant merged 28 commits intomasterfrom
espadolini/ca-watcher-filter

Conversation

@espadolini
Copy link
Copy Markdown
Contributor

@espadolini espadolini commented Jan 28, 2022

This PR:

  • fixes the filtering on CA updates that trigger a rotation state sync
  • makes it so that watchers can filter CertAuthority resources by type (host/user/jwt) and name, and adds the appropriate CA filter to the cache for Node roles (host CAs with a name that matches the cluster name, all user CAs) and for the syncRotationStateCycle loop (only host CAs from the current cluster)
  • adds the same filtering support to the cache initialization, so we don't fetch unnecessary data
  • adds filtering on the server side for older node clients, gated by version number
  • fixes potential inconsistencies in CAs when adding a trusted cluster/remote cluster relationship
  • filters out spurious CA updates that would result in no changes

Fixes #9895.

The version cutoff for applying the server-side filter was set to 9.0.0; any backport at v7 and earlier should remove the client side filters and rely on that, as clients are allowed to connect to auth servers with a higher major version that don't have the backport yet.

@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch 7 times, most recently from 293c5d5 to 8954967 Compare February 1, 2022 23:02
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from 8954967 to bf9376b Compare February 1, 2022 23:26
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from bf9376b to 2d2cb6d Compare February 1, 2022 23:27
@espadolini
Copy link
Copy Markdown
Contributor Author

espadolini commented Feb 1, 2022

Open questions:

  • should we add a CertAuthorityFilter in protobuf form, if it's only ever used for translating to and from a watcher's filter map?
  • does the design of the filter need product decision? It's technically exposed API
  • how should the version cutoff work? Anything less than the next point release at time of backport? Should it be backport-only?

@espadolini espadolini changed the title CA replication filter CertAuthority watcher filtering Feb 1, 2022
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from 2d2cb6d to 04db0a4 Compare February 2, 2022 10:40
@russjones russjones requested a review from rosstimothy February 2, 2022 18:08
fspmarshall
fspmarshall previously approved these changes Feb 2, 2022
Copy link
Copy Markdown
Contributor

@fspmarshall fspmarshall left a comment

Choose a reason for hiding this comment

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

Added some minor nits, but LGTM overall.

Comment thread lib/auth/grpcserver.go Outdated
Comment thread lib/auth/grpcserver.go Outdated
Comment thread lib/auth/rotate.go Outdated
Comment thread lib/auth/trustedcluster.go Outdated
Comment thread lib/auth/trustedcluster.go Outdated
Comment thread lib/auth/trustedcluster.go Outdated
@espadolini espadolini marked this pull request as ready for review February 3, 2022 14:48
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Overall looks good. Can you add some test coverage for the things you added/fixed?

This still lets us do the CA filtering for the Node cache and the
syncRotationStateCycle watcher without adding new data to CAs.
As a bonus, the cache can now fetch only the required CAs on
initialization.
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from 2e089d2 to bd70797 Compare February 15, 2022 17:43
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch 2 times, most recently from ead3b88 to 67d97a0 Compare February 16, 2022 00:49
Comment thread lib/auth/grpcserver.go Outdated
Comment thread lib/auth/grpcserver.go
Comment thread lib/auth/grpcserver.go Outdated
Comment thread lib/cache/collections.go Outdated
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from 103898e to 051ed4c Compare February 17, 2022 08:37
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from 051ed4c to f148698 Compare February 17, 2022 08:39
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from cadf294 to dd40196 Compare February 18, 2022 17:08
@espadolini espadolini force-pushed the espadolini/ca-watcher-filter branch from dd40196 to e8f2a9b Compare February 18, 2022 19:45
Comment on lines +82 to +84
if services.CertAuthoritiesEquivalent(existing, ca) {
return nil
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@espadolini @fspmarshall I'm a little worried that silently skipping updates like this might result into very subtle bugs where e.g. we forget to update CertAuthoritiesEquivalent method after introducing another CA field or something. What do you think about at least logging it here?

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.

CertAuthoritiesEquivalent is defined as cmp.Equal skipping the metadata ID field so we shouldn't miss anything. Adding a debug log line would be fine, anything more would get quite spammy however.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah yes, I forgot it does cmp.Equal, should be fine then.

Comment thread lib/service/connect.go
continue
}
if ca.GetType() != types.HostCA && ca.GetClusterName() != conn.ClientIdentity.ClusterName {
if ca.GetType() != types.HostCA || ca.GetClusterName() != conn.ClientIdentity.ClusterName {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is that intended change?

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.

Yes, the original version had a bug and called syncRotationStateAndBroadcast unnecessarily often; syncRotationStateAndBroadcast only ever cares about the local host CA, so it should be called when just that one has potentially changed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Got it, thanks for the clarification.

@r0mant r0mant enabled auto-merge (squash) February 19, 2022 00:27
@r0mant r0mant merged commit 6033148 into master Feb 19, 2022
@r0mant r0mant deleted the espadolini/ca-watcher-filter branch February 19, 2022 00:48
espadolini added a commit that referenced this pull request Mar 2, 2022
espadolini added a commit that referenced this pull request Jun 29, 2022
Including similar changes to the v7 backport
espadolini added a commit that referenced this pull request Jun 29, 2022
CertAuthority watcher filtering (#10020)

Including similar changes to the v7 backport
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.

Filter CA replication to nodes

4 participants