nats-io / nats.rs

Rust client for NATS, the cloud native messaging system.
Apache License 2.0
1.07k stars 169 forks source link

Subscription Violation not returned as Subcribe error #1284

Open bella-WI opened 4 months ago

bella-WI commented 4 months ago

Observed behavior

Im expirementing with the auth callout and setting permissions for clients connecting to my nats-server. The following setup is happening:

  1. Im creating a client and connecting to the server with the following nats claims:
    User claims nats: UserClaimsNats { publish: NatsSubjectPermissions { allow: ["_INBOX.>"], deny: [] }, subscribe: NatsSubjectPermissions { allow: ["allowed_subject"], deny: [] }, jwt_type: "user", version: 2 }
  2. The nats connections is created without 'Authorization Violation Errors'
  3. Im subscribing to a subject that is not allowed:
    let _testsubscribe = nats_client
        .subscribe("this.is.not.allowed")
        .await
        .unwrap();
  4. Nats logs returning:
    [1] 2024/07/04 09:56:26.024888 [TRC] 172.20.0.6:37146 - cid:619 - <<- [SUB this.is.not.allowed 1]
    [1] 2024/07/04 09:56:26.024914 [TRC] 172.20.0.6:37146 - cid:619 - ->> [-ERR Permissions Violation for Subscription to "this.is.not.allowed"]
    [1] 2024/07/04 09:56:26.024936 [ERR] 172.20.0.6:37146 - cid:619 - Subscription Violation - User "system_account_test_client", Subject "this.is.not.allowed", SID 1
    [1] 2024/07/04 09:56:26.026861 [DBG] 172.20.0.6:37146 - cid:619 - Client connection closed: Client Closed
  5. unwarp() call on subcribe is not triggering a panic and the code continues.

Expected behavior

I would expect the subscribe to return an error in this case an the unwrap to trigger a warning.

Server and client version

nats-server: v2.10.16

Host environment

No response

Steps to reproduce

No response

Jarema commented 4 months ago

Subscription violations are not send as a response to a subscribe, but as an asynchronous message sent to the client. You can catch it with event callback

We're discussing options across the clients if that can be improved.

bella-WI commented 3 months ago

Any news on this topic?