Ticket 10049 - JWT token question
Summary: JWT token question
Status: RESOLVED INFOGIVEN
Alias: None
Product: Slurm
Classification: Unclassified
Component: slurmrestd (show other tickets)
Version: 20.02.5
Hardware: Linux Linux
: 4 - Minor Issue
Assignee: Nate Rini
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2020-10-23 08:33 MDT by Simran
Modified: 2026-02-17 03:36 MST (History)
1 user (show)

See Also:
Site: Roche/PHCIX
Slinky Site: ---
Alineos Sites: ---
Atos/Eviden Sites: ---
Confidential Site: ---
Coreweave sites: ---
Cray Sites: ---
DS9 clusters: ---
Google sites: ---
HPCnow Sites: ---
HPE Sites: ---
IBM Sites: ---
NOAA SIte: ---
NoveTech Sites: ---
Nvidia HWinf-CS Sites: ---
OCF Sites: ---
Recursion Pharma Sites: ---
SFW Sites: ---
SNIC sites: ---
Tzag Elita Sites: ---
Linux Distro: ---
Machine Name:
CLE Version:
Version Fixed:
Target Release: ---
DevPrio: ---
Emory-Cloud Sites: ---


Attachments

Note You need to log in before you can comment on or make changes to this ticket.
Description Simran 2020-10-23 08:33:04 MDT
Hello,

We are testing integration with an external dkube mlaas application with our HPC cluster using slurm's rest api.  Our developers have the following observation/question:

After installing slumrestd and enabling auth/jwt. https://slurm.schedmd.com/jwt.html

1) The way JWT is working is different from what we originally thought. Slumrestd is able to verify only the JWTs which are generated by slurm. 
scontrol token username=$USER
The above command returns the token, and using that in curl APIs works. But, passing DKube generated JWT does not work as slurm does not recognize it.

Is there a way for us to generate the token remotely or would each user have to generate their own token and pass that back to dkube to use.  This would limit us in automating our workflow and I am sure there is a better way to do this and I might just be missing something.

Any guidance you can provide would be helpful.

Regards,
-Simran
Comment 1 Nate Rini 2020-10-23 09:40:26 MDT
(In reply to Simran from comment #0)
> 1) The way JWT is working is different from what we originally thought.
> Slumrestd is able to verify only the JWTs which are generated by slurm. 
> scontrol token username=$USER
> The above command returns the token, and using that in curl APIs works. But,
> passing DKube generated JWT does not work as slurm does not recognize it.

Any JWT token passed to the slurmrestd (which is sent to slurmctld) must have the correct claims and use "HS256" signature signed with the same key as provided to slurmctld.

> sun -> username
> exp -> unix timestamp of expiration date
> iat -> unix timestamp of creation date (optional)

An easy way to verify the payload has the correct claims is put them into https://jwt.io/. Please make sure to only test tokens that are from test systems that have been revoked/invalidated.
Comment 2 Simran 2020-10-23 10:14:11 MDT
Thanks Nate for the quick reply.  

(In reply to Nate Rini from comment #1)
> (In reply to Simran from comment #0)
> > 1) The way JWT is working is different from what we originally thought.
> > Slumrestd is able to verify only the JWTs which are generated by slurm. 
> > scontrol token username=$USER
> > The above command returns the token, and using that in curl APIs works. But,
> > passing DKube generated JWT does not work as slurm does not recognize it.
> 
> Any JWT token passed to the slurmrestd (which is sent to slurmctld) must
> have the correct claims and use "HS256" signature signed with the same key
> as provided to slurmctld.

When you say signed with the same key as provided to slurmctld, where/how are we providing the key to slurmctld.  Is this via some slurm config or via the api call somehow? 

> 
> > sun -> username
> > exp -> unix timestamp of expiration date
> > iat -> unix timestamp of creation date (optional)
> 
> An easy way to verify the payload has the correct claims is put them into
> https://jwt.io/. Please make sure to only test tokens that are from test
> systems that have been revoked/invalidated.
Comment 3 Nate Rini 2020-10-23 11:31:57 MDT
(In reply to Simran from comment #2)
> (In reply to Nate Rini from comment #1)
> > (In reply to Simran from comment #0)
> > Any JWT token passed to the slurmrestd (which is sent to slurmctld) must
> > have the correct claims and use "HS256" signature signed with the same key
> > as provided to slurmctld.
> 
> When you say signed with the same key as provided to slurmctld, where/how
> are we providing the key to slurmctld.  Is this via some slurm config or via
> the api call somehow?

The key is contents of jwt_hs256.key file in your StateSaveLocation. See this for better example on setup:
> https://slurm.schedmd.com/jwt.html

In your case, I would expect you to copy the key from dkube instead of randomly generating one using openssl command.
Comment 4 Simran 2020-10-28 09:21:45 MDT
Hi Nate,

Due to security reasons dkube is planning on regenerating the signing key on a regular basis.  Would a workflow like this be supported by slurm?  How could we automate this process on slurm and ensure that the key gets regenerated.  Do other customers using slurmrestd keep the same key once created or do they also use some automated process to regenerate the keys.  Assuming slurmctld would need to be restarted every time a new key is generated as well.

Thanks,
-Simran
Comment 5 Nate Rini 2020-10-28 09:56:39 MDT
(In reply to Simran from comment #4)
> Due to security reasons dkube is planning on regenerating the signing key on
> a regular basis.
Does dkube provide a method to verify a JWT key and determine which user it belongs to?

> Would a workflow like this be supported by slurm?
How long is a "regular basis"?

> How could we automate this process on slurm and ensure that the key gets
> regenerated.  
> Do other customers using slurmrestd keep the same key once
> created or do they also use some automated process to regenerate the keys.

This looks like a better use case for an authentication proxy.

> Assuming slurmctld would need to be restarted every time a new key is
> generated as well.
Correct, but only slurmctld (and slurmdbd in 20.11 if any accounting methods are used).
Comment 6 Simran 2020-10-28 14:17:13 MDT
Thanks Nate.  They have agreed to not change the signing key so we should not have a need to update this key often.  They were thinking on a quaterly basis, I think.  Is there a way to get a systemd script to start slurmrestd.  During our installation we can find systemd scripts for slurmctld and slurmdbd but not slurmrestd.

Regards,
-Simran

(In reply to Nate Rini from comment #5)
> (In reply to Simran from comment #4)
> > Due to security reasons dkube is planning on regenerating the signing key on
> > a regular basis.
> Does dkube provide a method to verify a JWT key and determine which user it
> belongs to?
> 
> > Would a workflow like this be supported by slurm?
> How long is a "regular basis"?
> 
> > How could we automate this process on slurm and ensure that the key gets
> > regenerated.  
> > Do other customers using slurmrestd keep the same key once
> > created or do they also use some automated process to regenerate the keys.
> 
> This looks like a better use case for an authentication proxy.
> 
> > Assuming slurmctld would need to be restarted every time a new key is
> > generated as well.
> Correct, but only slurmctld (and slurmdbd in 20.11 if any accounting methods
> are used).
Comment 7 Nate Rini 2020-10-28 14:28:07 MDT
(In reply to Simran from comment #6)
> They have agreed to not change the signing key so we should
> not have a need to update this key often.  They were thinking on a quarterly
> basis, I think.

Understood. There is the option to setup an authentication proxy that will use pam (or the auth system provided by dkube) to avoid the need for Slurm to use the same key as dkube. But if that works for your site, then it works for us.

> Is there a way to get a systemd script to start slurmrestd.
An example is here:
> https://github.com/naterini/slurm-gcp/commit/468d1f609dce934068b48e17945234453ff2e7f6#diff-e09e083af9035d60cde196b1095a7a0a4d54d94df6601a9c1fde3c43a3964315R646-R663

I'll have to look at getting one upstream.
Comment 8 Nate Rini 2020-10-29 14:55:54 MDT
(In reply to Nate Rini from comment #7)
> I'll have to look at getting one upstream.
Slurm 20.11 will now generate unit file:
> https://github.com/SchedMD/slurm/commit/e4b0cbe3dd2deef2da70fe91638208bd684c35f4

Do you have any more questions?
Comment 9 Simran 2020-10-29 16:03:44 MDT
(In reply to Nate Rini from comment #8)
> (In reply to Nate Rini from comment #7)
> > I'll have to look at getting one upstream.
> Slurm 20.11 will now generate unit file:
> > https://github.com/SchedMD/slurm/commit/e4b0cbe3dd2deef2da70fe91638208bd684c35f4
> 
> Do you have any more questions?

Not at the moment Nate.  Feel free to close this request and I can open a new one if something comes up.

Thanks,
-Simran
Comment 10 Nate Rini 2020-10-29 16:04:56 MDT
Closing per your response.

Thanks,
--Nate