Starting Sandbox with JWT token

Hi,

This question is meant to gather information on how to start a simple Sandbox (without Navigator nor JSON-API) that will support a token like a real Ledger does.

The start sandbox command is:

daml sandbox --log-level-root=INFO --log-level-canton=INFO --log-level-stdout=INFO >> $D/sandbox.log 2>&1 &

According to this tutorial i should pass it a JWT

Questions:

  1. Where do i pass the JWT token?
  2. Which claims should such a token consists (readAs, actAs, Participants etc…)
  3. Is there a way to achive this auth without a certificate file? Only supply HMAC RS 256 token?

Thanks

Response from @Jozsef_Vigh

Hi
When starting the sandbox you shall provide a configuration file that includes the type and the path of your certificate. The sample file can be seen in your attached screenshot. Then your sandbox start command will look like this:

daml sandbox -c /your_path/auth.conf --log-level-root=INFO --log-level-canton=INFO --log-level-stdout=INFO >> $D/sandbox.log 2>&1 &

To generate the certification file you may run the following command:

openssl req -nodes -new -x509 -keyout sandbox.key -out sandbox.crt

You may find other types of certification possibilities here.
The generated .crt file’s path should be put into the config file that you pass in as an argument when starting the sandbox.

Every client method has an overload that allows a token to be passed

This way the Ledger API requests will be required to include a JWT token for interacting with the ledger. Here is an example of that if you are using the Java bindings.
Regarding your second question, I can not give you a definitive answer as it depends on your use case.
You may use HMAC RS 256, but for production, it is not considered safe. It is mentioned under a warning section in the documentation.

canton.participants.sandbox.ledger-api.auth-services = [{ type = unsafe-jwt-hmac-256 secret = "not-safe-for-production" }]

Bests,
József

For some reason his response is pending at the moment, will get that fixed later! but trying to get this to you asap, hope it helps!

Hi

When starting the sandbox you shall provide a configuration file that includes the type and the path of your certificate. The sample file can be seen in your attached screenshot. Then your sandbox start command will look like this:

daml sandbox  -c /your_path/auth.conf --log-level-root=INFO --log-level-canton=INFO --log-level-stdout=INFO >> $D/sandbox.log 2>&1 &

To generate the certification file you may run the following command:

openssl req -nodes -new -x509 -keyout sandbox.key -out sandbox.crt

You may find other types of certification possibilities here.

The generated .crt file’s path should be put into the config file that you pass in as an argument when starting the sandbox.

Every client method has an overload that allows a token to be passed

This way the Ledger API requests will be required to include a JWT token for interacting with the ledger. Here is an example of that if you are using the Java bindings.

Regarding your second question, I can not give you a definitive answer as it depends on your use case.

You may use HMAC RS 256, but for production, it is not considered safe. It is mentioned under a warning section in the documentation.

canton.participants.sandbox.ledger-api.auth-services = [{
    type = unsafe-jwt-hmac-256
    secret = "not-safe-for-production"
}]

Bests,
József

2 Likes

Thanks @Jozsef_Vigh for your elaborated answer.

I want to start the sandbox with the less strict approach which you mentioned lastly in your reply (shared secret) :

canton.participants.sandbox.ledger-api.auth-services = [{
    type = unsafe-jwt-hmac-256
    secret = "XXX"
}]

My question is not how to do so since it’s fairly straight forward (just create a token with the same secret in auth.conf) but rather on the concept itself:

Once i create the JWT token with a secret XXX and provide an auth.conf as above (containing same secret), how do i leverage it when starting a sandbox?

I mean, do i pass the auth.conf path to the command as shown below and then my Sandbox will accept all secured API’s with every possible token as long as those tokens generated with XXX secret?

e.g All JSON-API, damlhub and gRPC based requests which pass a token to the Ledger will be authenticated as long as the token used with it was generated with XXX secret?

daml sandbox -c path/to/canton/config

From the docs:

Thanks in advance,
Liav

Yes, if you use the secret Sandbox will accept all tokens as valid that are signed with the given secret. The token being valid doesn’t mean that your request is properly authorized though, e.g., consider a token with actAs = alice and you send a request that requires actAs = bob. Your request will still get rejected.
So the secret controls whether the token is a valid token but the ledger still checks the claims within the token as usual.

Thanks @cocreature

Will this token based on shared secret can be used to create/allocate parties so upon exercising a command on their behalf will be accepted (regardless on their actAs and readAs prevliges which you explained)?

For allocating tokens, you need a token with admin claims but there are no requirements on actAs/readAs.

1 Like