package busauth import server "github.com/nats-io/nats-server/v2/server" // PermissionsFromSubjects adapts a subject-deriving function (e.g. // membership.SubjectACLFor, which maps an identity to the subjects of the rooms // it belongs to plus the client infrastructure subjects) into the PermissionsFunc // the ACL authenticator expects. The derived subjects are granted as BOTH the // publish and subscribe allow set, so a connection can only pub/sub on the // subjects it is entitled to. A derivation error is propagated so the caller // fails closed (denies the connection) rather than granting open access. // // This is the production wiring for the per-subject data-plane ACL (issue 0003e, // audit H4): membershipd passes PermissionsFromSubjects(membership.SubjectACLFor( // store)) to NewNkeyAuthenticatorACL. It lives in busauth (not membership) so the // membership package stays free of the nats-server dependency. func PermissionsFromSubjects(derive func(signPubHex string) ([]string, error)) PermissionsFunc { return func(signPubHex string) (*server.Permissions, error) { subjects, err := derive(signPubHex) if err != nil { return nil, err } sp := &server.SubjectPermission{Allow: subjects} return &server.Permissions{Publish: sp, Subscribe: sp}, nil } }