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

Prevent mutations by entry cache callers #3215

Merged
merged 2 commits into from
Jul 1, 2022

Commits on Jul 1, 2022

  1. Prevent mutations by entry cache callers

    Recently, we introduced a change wherein the agents supply an output
    mask to the server (spiffe#3123) to reduce bandwidth usage.
    
    This exposed a bug in the interactions between the SVID API handler and
    the entry cache. The cache currently returns its owned copy of the entry
    to callers. This was done for performance reasons.... making a copy of
    each entry increases memory pressure in one of the hottest codepaths in
    the server.
    
    Due to this behavior however, the SVID handler, when applying the mask
    to remove fields from the entries before including them in the response,
    was inadvertently stripping off fields from entries within the cache.
    This was not only resulting in temporary data loss (e.g. dns names) on
    the entries (next cache refresh would restore the fields) but could
    easily become a data race, wherein entries could get mutated by multiple
    entities at once (since the fields are mutated concurrently without any
    sort of lock protection).
    
    This change updates the cache to clone the entries before returning them
    to the caller. Although this results in some increase in memory
    pressure, it is the cleanest, and most robust approach. If the increase
    in memory pressure turns out to be too much, we can explore other
    options, though those may come with a large cost in code complexity
    (e.g. on-demand cloning of shared data structure). Even if we did
    something cute, the GetAuthorizedEntries RPC is by far the most called
    RPC in the agent and would need to clone anyway to apply the mask.
    
    Fixes: spiffe#3184
    
    Signed-off-by: Andrew Harding <aharding@vmware.com>
    azdagron committed Jul 1, 2022
    Configuration menu
    Copy the full SHA
    4f70173 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5da6953 View commit details
    Browse the repository at this point in the history