-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WebSockets Next: Support for secure upgrade with security annotations only #40957
WebSockets Next: Support for secure upgrade with security annotations only #40957
Conversation
This comment has been minimized.
This comment has been minimized.
3818f2a
to
b02154a
Compare
🙈 The PR is closed and the preview is expired. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea looks good.
Might be unrelated to this PR, but how can a user implement sub-protocol negotiation?
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot review the security parts but the rest looks good.
...-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/HttpUpgradeSecurityCheck.java
Outdated
Show resolved
Hide resolved
...est/java/io/quarkus/websockets/next/test/security/HttpUpgradeRolesAllowedAnnotationTest.java
Show resolved
Hide resolved
...va/io/quarkus/websockets/next/test/security/HttpUpgradePermissionsAllowedAnnotationTest.java
Show resolved
Hide resolved
...st/java/io/quarkus/websockets/next/test/security/HttpUpgradeAuthenticatedAnnotationTest.java
Show resolved
Hide resolved
@cescoffier First of all, we should describe the current subprotol support. The server can configure a list of supported subprotocols (globally, not per-endpoint). Now if a client sends the With a custom |
b02154a
to
5332010
Compare
Status for workflow
|
Status for workflow
|
Thanks @michalvavrik, it looks fine but a bit complex to review from PTO 🙂, so will do next week |
@sberyozkin ping. Did you get a chance to review the security parts? |
|
||
Other options for securing HTTP upgrade requests, such as using the security annotations, will be explored in the future. | ||
IMPORTANT: HTTP upgrade is only secured when a security annotation is declared on an endpoint class next to the `@WebSocket` annotation. | ||
Placing a security annotation on an endpoint bean will not secure bean methods, only the HTTP upgrade. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik So, in the example above, open()
is secured and echo
is not ? It would be unexpected IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the example above "open" and "echo" are not secured, but HTTP upgrade is secured. The HTTP upgrade happens before "open" and "echo", therefore they are only not secured if you inject "Endpoint" class as a bean into another CDI bean and call these methods directly.
That is:
@Inject
Endpoint endpoint
public void do() {
endpoint.open();
}
if we were to secure echo
, it would mean for every single message is performed authorization despite known result (you know it will pass because the HTTP upgrade is secured).
I can point you to tests that asserts security is not relaxed where not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik Michal, these are low level technical details that HTTP upgrade happens before onOpen
, to me, on onOpen
actually represents a successful HTTP upgrade completion, even if it is not quite a correct picture.
Let me clarify how it aligns with #40534.
So there we have an HTTP security policy securing an upgrade:
quarkus.http.auth.permission.secured.paths=/end
quarkus.http.auth.permission.secured.policy=authenticated
and then we have
@WebSocket(path = "/end")
public class Endpoint {
@Inject
SecurityIdentity currentIdentity;
@RolesAllowed("admin")
@OnTextMessage
String echo(String message) {
return message;
}
}
so @RolesAllowed
must be placed on the echo
method to ensure the current security identity is present and matches the sec constraint before echo
is called.
Let's say, with your PR, I only want that echo
is accessed by the non-anonymous security identity.
Are you saying we must do:
@WebSocket(path = "/end")
@Authenticated
public class Endpoint {
@Inject
SecurityIdentity currentIdentity;
@Authenticated
@OnTextMessage
String echo(String message) {
return message;
}
}
to have echo
secured ?
Also, does
@WebSocket(path = "/end")
@RolesAllowed("admin")
public class Endpoint {
}
works for a secure HTTP upgrade ? And if yes, should users also duplicate @RolesAllowed("admin") on the echo
method for the echo
be secured ?
I guess, all I'm asking, why can't we have a single @Authenticated
at the class level, and not require users duplicate across various methods like onOpen, onEcho, etc, if all users want is, for ex, an authenticated access ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying we must do:
@WebSocket(path = "/end") @Authenticated public class Endpoint { @Inject SecurityIdentity currentIdentity; @Authenticated @OnTextMessage String echo(String message) { return message; } }
to have
echo
secured ?
Nope, @Authenticated
declared on an endpoint means that no callback can be called for non-anonymous security identity. In other words, we secure the HTTP upgrade and if the check fails then no method declared on the endpoint is invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does
@WebSocket(path = "/end") @RolesAllowed("admin") public class Endpoint { }
works for a secure HTTP upgrade ? And if yes, should users also duplicate @RolesAllowed("admin") on the echo method for the echo be secured ?
It's the same principle, i.e. no need to duplicate the annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you suggest a message @sberyozkin ? It's optional, but I'd appreciate it. Otherwise I'll try to rewrite it, but I don't know if it will fit your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO noone will inject endpoint and use it as CDI bean
May be this is the source of the confusion on my behalf and simply dropping this message will help ? See, I'm not thinking as a user in terms of CDI beans, when I see an example like
@WebSocket(path = "/end")
@Authenticated
public class Endpoint {
@Inject
SecurityIdentity currentIdentity;
@OnTextMessage
String echo(String message) {
return message;
}
}
I expect that the callback echo
and onOpen
methods are secured, I don't want to inject this endpoint anywhere, it is like a JAX-RS resource, we don't inject it somewhere else...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why reading Placing a security annotation on an endpoint bean will not secure bean methods, only the HTTP upgrade.
confuses me a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think small follow-up docs PR where we can iterate would be better than do it on this PR as CI takes longer and I think we need more than attempt. +1 to merge this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please merge for this PR to make it to 3.12.
I suggest to rework the message related to the securing the upgrade vs the onOpen/onTextMesage callbacks if possible, but is not a requirement for this PR
OK, let me merge it myself then |
closes: #40622