prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Adding ability to shift issue time of token (iat) backwards due to"token is issued in the future (iat)" error

Open simonobe opened this issue 7 years ago • 1 comments

Is your feature request related to a problem? Please describe. We are making deployments of prisma using prisma deploy daily from our local dev machines. The prisma cluster itself is however running remotly on aws. As a consequence, often times it happens that the clocks get desynchronized and we receive Prisma deploy Error: Token is issued in the future (iat) when running the command. We tried several methods to synchronize the clocks but since our infrastructure is very changeable it was no use. Describe the solution you'd like As we use prisma deploy within automated scripts we simply need this to work. Below I propose an alternative.

Describe alternatives you've considered I am proposing to introduce new environment variable i.e PRISMA_MANAGEMENT_BACKDATE_TOKEN. This would be a numeric value determining amount of seconds that the token would be backdated. This value can easily be accessed in here: https://github.com/prisma/prisma/blob/master/cli/packages/prisma-yml/src/Cluster.ts just as the PRISMA_MANAGEMENT_API_SECRET is accesed. Then the function getLocalToken() specifically lines 89-92 can be changed from this:

this.cachedToken = jwt.sign({ grants }, secret, {
          expiresIn: '5y',
          algorithm,
        })

to this:

const iat = process.env.PRISMA_MANAGEMENT_BACKDATE_TOKEN
   ? Math.floor(Date.now() / 1000) - process.env.PRISMA_MANAGEMENT_BACKDATE_TOKEN
   : Math.floor(Date.now() / 1000)
this.cachedToken = jwt.sign({ grants, iat: iat }, secret, {
          expiresIn: '5y',
          algorithm,
        })

This would solve our problem. If the variable is not set, iat corresponds to the current time (which corresponds to how the function behaves now). If the environment variable is set, then the token is backdated which would solve our problem. I am willing to create a fork and implement this. I was just curious if this makes sense, or if there is more rational way to solve our problem. Additional context Add any other context or screenshots about the feature request here.

simonobe avatar Sep 12 '19 13:09 simonobe

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 27 '19 13:10 stale[bot]