Skip to content

Needs Claims JWT Support #717

@arnavdas88

Description

@arnavdas88

Proposed change

Please refer to the example: NATS by Example - Programmatic NKeys and JWTs

Authorization, Account Limits, and such are managed by Claims in Nats.io. The golang library nats-io/jwt provides methods to fetch and modify these Claims but there is no such provision in the python client. I believe the management of these Claims and subsequently the users, accounts, limits, etc. encompasses an integral part of the system and must have support in all the client libraries, including python.

Use case

Nats.io claims management, and control over users, accounts, limits, permissions, etc.

Sample Code

operatorKP = from_seed(b'SOALU7LPGJK2BDF7IHD7UZT6ZM23UMKYLGJLNN35QJSUI5BNR4DJRFH4R4')
accountKP = from_seed(b'SAALXUEDN2QR5KZDDSH5S4RIWAZDM7CVDG5HNJI2HS5LBVYFTLAQCOXZAU')
userKP = from_seed(b'SUALJTG5JNRQCQKFE652DV4XID522ALOHJNQVHKKDJNVGWHCLHOEXEROEM')

account_claims = Claims(
    name="my-account",
    jti="PBFES33GGIFZM6UGC7NY5ARHRBFVFU4UD7FS2WNLZH3KPGWFVEFQ",
    iat=1678973945,
    iss=operatorKP.public_key.decode(),
    sub=accountKP.public_key.decode(),
    nats=Account(
        limits=OperatorLimits(
            nats_limits=NatsLimits(data = -1, payload = -1, subs = -1),
            account_limits=AccountLimits(exports = -1, imports = -1, wildcards = True, conn = -1, leaf = -1),
            jetstream_limits=JetStreamLimits(disk_storage=-1, mem_storage=-1)
        ),
        default_permissions=Permissions(),
        generic_fields=GenericFields(version=2, type=Types.Account)
    )
)

Contribution

PR 716

Note: I dont have much of a clear understanding of how exactly the Operator, Account and User works with each other and why an Account defines an OperatorLimit, but following the methods in nats-io/jwt has lead me to creating this PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalEnhancement idea or proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions