We have our huge monolithic 1gp legacy package as well as 2gp extension package. And there are some secret configs (e.g. s3 keys, twillio account creds etc. in protected custom settings) in 1gp package which should be available in 2gp extension but only internally.
The simplest solution is to create global method in 1gp to return these settings. But it would introduce security issue, allowing subscribers to call this method from org level itself and inspect configs.
In case of 2gp-2gp packages relationship we could have used @NamespaceAccessible annotation to open method only to packages inside the same namespace. But what techniques can be used to achieve similar outcome for 1gp-2gp communication across different namespaces?
Unfortunately, it seems like there are no methods in Apex to return current or parent namespaces, i.e. to be able to hardcode checking at code level whether call is coming from allowed namespace etc. Any ideas would be appreciated re how to organize such protection in reliable but still simple way.