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

Document how and when to add classes/permissions/packages to the engine module #4647

Open
keturn opened this issue May 3, 2021 · 4 comments
Labels
Category: Doc Requests, Issues and Changes targeting javadoc and module documentation Status: Needs Investigation Requires to be debugged or checked for feasibility, etc.

Comments

@keturn
Copy link
Member

keturn commented May 3, 2021

From a comment in #4622:

I see - I was wondering whether these [engineModules] are subsystems or something like that.

Ah, you may have got that idea from the ModuleManager constructor argument named classesOnClasspathsToAddToEngine, which is handled in loadEngineModule. Those are subsystems:

// add all subsystem as engine module part. (needs for ECS classes loaded from external subsystems)
allSubsystems.stream().map(Object::getClass).forEach(this::addToClassesOnClasspathsToAddToEngine);

The lists of allowed packages and classes are used in a straightforward manner, from what I've been able to tell. You list a thing there, and it gets used in a conditional somewhere that does a direct comparison against the list. If it's allowed, then any module is allowed to load that class and do whatever it wants with it.

The things that get passed to a Reflections configuration, on the other hand, are not so direct. Reflections isn't really there to provide permissions checks. Reflections data is used to answer questions of "What classes have this annotation?" and "What are the subtypes of this class?"

– but we want to make sure the answers to those queries don't return things from modules that aren't active.
– and failing to get the answer you expected from one of those things can sure look a whole lot like when a thing is missing from the permission list.

We could use clarity on when a class needs to be

the Module.classPredicate being a thing that's either new to v7 or was just well-hidden in v5. You can have a class that the security policy and clasloaders all allow you to load, but something may ask ModuleEnvironment.getModuleProviding about it, and if no modules recognize it then it's not usable for some purposes after all.

oh and also these should probably line up somehow? https://github.com/MovingBlocks/gestalt/blob/4b6ea6d50176da0ac0d93a9186f1b44ba2cb12c4/gestalt-module/src/main/java/org/terasology/gestalt/module/Module.java#L56-L57

  • fileSources: Any sources of files that compose the module. Must not be null - can be EmptyFileSource
  • classpaths: Any extra classpaths to load for the module
@keturn keturn added the Category: Doc Requests, Issues and Changes targeting javadoc and module documentation label May 3, 2021
@keturn keturn added this to the v4.4.1 milestone May 3, 2021
@keturn
Copy link
Member Author

keturn commented May 3, 2021

Related: #4639

@jdrueckert jdrueckert added the Status: Needs Investigation Requires to be debugged or checked for feasibility, etc. label May 16, 2021
@keturn
Copy link
Member Author

keturn commented May 19, 2021

Some notes from discord:

That's the crux of it. What is in the “engine module”? We made sure to move a lot of stuff in to the org.terasology.engine namespace, which makes it somewhat easier to tell what isn't engine, but that wasn't sufficient because there are still things inside org.terasology.engine that shouldn't be module-accessible, as well as things outside (subsystems, TeraNUI) that should.

Complicated by the fact that it's not only a question of “are you authorized to reference this class." We can make classes accessible without putting them in a module.

The other questions are things like “does this class need to belong to a specific module? e.g. to generate a URI for it“ and ”do we need a ModuleEnvironment to be able to answer queries like getSubtypesOf or getTypesAnnotatedWith for this class?“

@jdrueckert jdrueckert modified the milestones: v5.0.0, v5.1.0 Jun 12, 2021
@keturn keturn modified the milestones: v5.1.0, v5.2.0 Aug 15, 2021
@keturn
Copy link
Member Author

keturn commented Aug 27, 2021

Some notes from #4799 as a case study:

  • If a class from a third-party library fails to load, but you can reference that class directly from engine code, that class (or the package containing it) needs to be added to the list in ExternalApiWhitelist. These lists only use exact matches, wildcards don't work here.

  • If a library fails to read a system property, and that property is not something that needs to be kept secret, you can add read permission for it as done here:

    // In theory, PropertyPermission has wildcard matching and "reactor.*" should be sufficient to grant read access to all
    // reactor configuration properties.
    permissionSet.grantPermission(new PropertyPermission("reactor.*", "read"));
    // In practice, the permission checks fail unless these are each named explicitly.
    permissionSet.grantPermission(new PropertyPermission("reactor.bufferSize.x", "read"));

    (though if we get many more of those we should refactor them out of that method)

@jdrueckert jdrueckert modified the milestones: v5.2.0, 5.3.0 Dec 6, 2021
@jdrueckert jdrueckert modified the milestones: 5.3.0, 5.4.0 Sep 4, 2022
@Spoorthy1423
Copy link

Hey!! I would like to work on this issue @keturn , actually i already started working and i hope it fulfills the requirements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Doc Requests, Issues and Changes targeting javadoc and module documentation Status: Needs Investigation Requires to be debugged or checked for feasibility, etc.
Projects
None yet
Development

No branches or pull requests

3 participants