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

[WFCORE-4395] Move the JDBCRealm Mapper validation to model time check #6172

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

pedro-hos
Copy link
Contributor


return keyMapper;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the Mapper validation, but I don't know if we still need to have this code on we can just remove the InvalidKeyException from the interface, and call this without those validations (both if). I guess that we can keep the throw new OperationFailedException("Invalid key type.", e); only at the checkKeyMappers. Or do we need those validations on Runtime time as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this method back where it was? AFAICT it doesn't need to move, and moving it makes this diff very hard to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless @fjuma disagrees, +1 to getting rid of 'throws InvalidKeyException'. None of the impls throw it.

If we keep it we should fix the i18 of this OFE. Exceptions should not have hard coded English messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for getting rid of the throws InvalidKeyException.

@pedro-hos
Copy link
Contributor Author

This is the error when try to startup with more than one mapper:

12:04:39,177 INFO  [org.jboss.as] (MSC service thread 1-4) WFLYSRV0049: WildFly 34.0.0.Beta1-SNAPSHOT (WildFly Core 26.0.0.Beta4-SNAPSHOT) starting
12:04:39,210 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 10) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "elytron"),
    ("jdbc-realm" => "servlet-security-jdbc-realm")
]) - failure description: "WFLYELY00034: A principal query can only have a single key mapper"
12:04:39,212 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) "WFLYCTL0193: Failed executing subsystem elytron boot operations"
12:04:39,212 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("parallel-subsystem-boot") failed - address: ([]) - failure description: "\"WFLYCTL0193: Failed executing subsystem elytron boot operations\""
12:04:39,214 FATAL [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0056: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details. - Server configuration file in use: standalone.xml - Minimum feature stability level: community

}

try {
keyMapper = mapperResource.toPasswordKeyMapper(context, propertyNode);
Copy link
Contributor

@bstansberry bstansberry Sep 11, 2024

Choose a reason for hiding this comment

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

This is not allowed. The toPasswordKeyMapper implementations do work that is not meant for Stage.MODEL (all the resolveModelAttribute calls).

Copy link
Contributor

Choose a reason for hiding this comment

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

That said, my impression reading this is that it's not necessary to call this in Stage.MODEL. This entire try/catch can go away. Looking (quickly) at all the impls of this interface, none of them do anything that is relevant to Stage.MODEL.

There's separate logic called in populateModel that validates the individual mapper configs, so the various things done in the toPasswordKeyMapper impls is not a necessary part of the Stage.MODEL validation. All that's needed here is checking that there is only config element.

@pedro-hos
Copy link
Contributor Author

@bstansberry I have made the changes to check that we have only one mapper by principal-query during the Model stage. I keep the InvalidKeyException so far, until we decide to keep or remove it.

@pedro-hos
Copy link
Contributor Author

@bstansberry / @fjuma I have made the changes. Please, let me know if I need to make any other improvements. Thanks

@wildfly-ci

This comment was marked as off-topic.


@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
List<ModelNode> principalQueries = PrincipalQueryAttributes.PRINCIPAL_QUERIES_7_0.resolveModelAttribute(context, operation).asList();
Copy link
Contributor

Choose a reason for hiding this comment

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

@pedro-hos Unfortunately 'resolveModelAttribute' shouldn't be called in Stage.MODEL. Expressions meant to be resolved from secure sources (i.e. Elytron credential stores) can't be resolved in MODEL. We don't ban their use in MODEL (i.e. throw an exception) because there are a couple valid cases, but this isn't one. (The odds of such an expression being used here are probably minuscule, but we shouldn't rely on that.)

I think the thing to do is:

ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
ModelNode queries = model.get(PrincipalQueryAttributes.PRINCIPAL_QUERIES_7_0.getName());

And then inspect 'queries'.

The 'ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();' is because by the time this runs the 'operation' contents have already been processed and stored into the model. It is better to use the results of that work (which may have somehow transformed things) that to rely on the original operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I have made the changes. Thank you for the feedback

Copy link
Contributor

@bstansberry bstansberry left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @pedro-hos

@pedro-hos
Copy link
Contributor Author

Thank you

@yersan yersan added the ready-for-merge This PR is ready to be merged and fulfills all requirements label Oct 16, 2024
@yersan yersan merged commit 45005b6 into wildfly:main Oct 16, 2024
12 checks passed
@yersan
Copy link
Collaborator

yersan commented Oct 16, 2024

Thanks @fjuma @pedro-hos @bstansberry

@pedro-hos pedro-hos deleted the WFCORE-4395 branch October 16, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to be merged and fulfills all requirements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants