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

OpenAPI: enable auto security filter for auth policy via configuration #36460

Closed

Conversation

MikeEdgar
Copy link
Contributor

Allow the OpenAPI to have auto-added security scheme when an enabled HTTP auth policy is present. Currently, it requires auth to be enabled via @RolesAllowed or @Authenticated.

@MikeEdgar
Copy link
Contributor Author

MikeEdgar commented Oct 12, 2023

@phillip-kruger PTAL

If this meets the criteria for something that could be backported to 3.2, I'd be happy to do it 😄

@quarkus-bot
Copy link

quarkus-bot bot commented Oct 12, 2023

Failing Jobs - Building 6160c65

Status Name Step Failures Logs Raw logs Build scan
Native Tests - Windows - RESTEasy Jackson Setup GraalVM ⚠️ Check → Logs Raw logs

@@ -222,15 +223,15 @@ void registerAutoSecurityFilter(BuildProducer<SyntheticBeanBuildItem> syntheticB
SmallRyeOpenApiConfig openApiConfig,
OpenApiFilteredIndexViewBuildItem apiFilteredIndexViewBuildItem,
List<SecurityInformationBuildItem> securityInformationBuildItems,
OpenApiRecorder recorder) {
OpenApiRecorder recorder,
HttpBuildTimeConfig httpConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it can complicate a planned migration of this configuration to Runtime ? CC @michalvavrik

Copy link
Member

Choose a reason for hiding this comment

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

There will always need to be at least one build time property that will allow to you decide, if HTTP permissions are used not, for we need to decide if we produce beans (sure, we could also keep them there, in which case these changes are blocker). I'll comment below as well.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, but we produce it now anyway, so no build time properties needed, sorry.

Copy link
Member

Choose a reason for hiding this comment

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

So, answer is yes.

@phillip-kruger
Copy link
Member

@MikeEdgar LGTM - I'll let @sberyozkin approve. W.r.t backport, the only thing you need to do is add the backport label

OASFilter autoSecurityFilter = null;
if (openApiConfig.autoAddSecurity) {

if (openApiConfig.autoAddSecurity
Copy link
Member

@michalvavrik michalvavrik Oct 13, 2023

Choose a reason for hiding this comment

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

Now you are able to enable security with io.quarkus.smallrye.openapi.common.deployment.SmallRyeOpenApiConfig#autoAddSecurity and including security extension and either use RolessAlowed-Authenticated or HTTP permissions to have security enabled, correct?

I wonder what happens when user uses other HTTP Security Policies like Keycloak Authorization or has their own one because they implemented global policy due to our limited path matching capabilities? Users will have to specify securityScheme when they want it generated, rather then it being detected?

I can see why this is an improvement, but it will block moving HTTP permissions to runtime. Isn't that rather rare to have security extension added (you need to add it explicitly, right?) without securing anything? Why can't you simply add it always when security extension is present and if user don't want to add these schemes, they will set auto-add-security to false.

Also, the config property description says nothing about actually securing endpoints, therefore my proposed change would conform description This will automatically add security based on the security extension included (if any).. If you don't agree, please change the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now you are able to enable security with io.quarkus.smallrye.openapi.common.deployment.SmallRyeOpenApiConfig#autoAddSecurity and including security extension and either use RolessAlowed-Authenticated or HTTP permissions to have security enabled, correct?

@michalvavrik , that's correct. For your question on other policies, I think it depends on what HttpBuildTimeConfig and the SecurityInformationBuildItem look like for other/custom security policies. I'm thinking that the answer is what you said - the user would need to specify their own securityScheme and this approach only works when SecurityInformationBuildItem has one of the known SecurityModels.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for reply @MikeEdgar. I don't see any good reason why scheme shouldn't be generated when the security extension is present and SecurityInformationBuildItem is present as well. Just because someone doesn't use HTTP permissions and RBAC annotations, it doesn't mean they don't do security. Is there a point why you want to check HTTP permissions explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a point why you want to check HTTP permissions explicitly?

Only because it's what I needed for another project, but I think some more general approach would be better if it's possible.

Copy link
Member

Choose a reason for hiding this comment

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

Well, it's not a deal break, I suppose we can still migrate HTTP permissions and just add some flag for OpenAPI, but I'd appreciate if it was possible to not use HTTP permissions during the build time unless you need to. Whatever works for you, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

No objections there :-) I simply relied on docs in this for that's as much as I know about this thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should fix the configuration property description then :)

I'm not following why this would be changed. If there are multiple ways to configure the security - annotations, configuration, KC authorizer, etc. - why wouldn't it be preferable to use auto-add-security=false to disable the automatic security when not desired?

Copy link
Member

Choose a reason for hiding this comment

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

Auto security adds security (in OpenAPI) when nothing is configured in OpenAPI (annotations, configuration) but only if

  • Security extensions are added
  • Other (security) annotations and configuration are detected.

The second part are not in the description ....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it 👍. I think @michalvavrik's suggestion earlier was to remove the second part from the extension's code and allow users not wanting security to disable it using false. The issue I see is that if we require annotations, there are other possible ways to setup security that aren't supported.

Copy link
Member

Choose a reason for hiding this comment

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

Also remember, auto security for OpenAPI only run if there is not OpenAPI Security annotations. The user can always still add their own OpenAPI Security annotation when it's a special case.

@michalvavrik
Copy link
Member

FYI @MikeEdgar permissions are now runtime properties #36874

@MikeEdgar
Copy link
Contributor Author

Closing in favor of #38231 that does not depend on HTTP policy configurations.

@MikeEdgar MikeEdgar closed this Jan 16, 2024
@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Jan 16, 2024
@MikeEdgar MikeEdgar deleted the auto-security-by-config-policy branch January 27, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants