mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
11e52c4df6
* v1/plugins: Address race in config access I ran into this race condition on another PR: https://github.com/open-policy-agent/opa/actions/runs/16655603110/job/47139789057 I have tried to make all manager.Config access thread-safe by adding new getters for used values. GetConfig is regrettably based on a JSON roundtrip deep copy of the config. This us used in tests (fine) but also in the discovery plugin: https://github.com/open-policy-agent/opa/blob/2d014a89bbbc307d7204817220146ffae992e838/v1/plugins/discovery/discovery.go#L122 getPluginSet is very tightly coupled to the manager.Config and because of it's dependencies on status and the other plugins packages, it's hard to break out. So, for now, I think this is an improvement and worth getting a second opinion on before more refactoring. Signed-off-by: Charlie Egan <charlie@styra.com> * v1/config: Use add Clone to config This makes the use of the manager's config more thread-safe and consistent without more API changes. Signed-off-by: Charlie Egan <charlie@styra.com> * topdown: Add clone() funcs for config structs NamedValueCacheConfig.Clone, InterQueryBuiltinValueCacheConfig.Clone and InterQueryBuiltinCacheConfig.Clone have been added. All Clone methods return a deep copy of the struct. This is tested for missed new fields using PopulateAllFields, a generic function that stuffs structs with values for all fields. Signed-off-by: Charlie Egan <charlie@styra.com> * plugins: Clone new config Signed-off-by: Charlie Egan <charlie@styra.com> --------- Signed-off-by: Charlie Egan <charlie@styra.com>