Giter VIP home page Giter VIP logo

Comments (9)

slaskis avatar slaskis commented on May 10, 2024 2

I'd love to see support for this using an environment variable such as SECURE_KEYS.

This way when hosting on a service like Heroku we could have rolling secure secrets up and running by just enabling this addon: https://devcenter.heroku.com/articles/securekey#provisioning-the-add-on

from crystal.

pvdvreede avatar pvdvreede commented on May 10, 2024

The other thing that would be nice to have is the ability to set what the aud claim should be on the command line. This would be great so that you could use services like auth0 etc as the authentication system that generates the jwt. For example their JWTs would have your client id as the aud: https://auth0.com/docs/jwt

from crystal.

calebmer avatar calebmer commented on May 10, 2024

Yeah, this does seem like a reasonable request. One thing I instantly think about is if you're secret is compromised is it really worth still accepting it? Even so the option to do a rolling change would be nice.

Also, how do you feel about removing aud support entirely? It seems to me like checking these properties could be easily set in a piece of middleware so it might not be worth adding a bunch of flags in PostGraphQL.

from crystal.

 avatar commented on May 10, 2024

I feel like the entire jwt auth could just be middleware, e.g. this is how I'd done it in koa:

export function checkAuthentication({ debug }) {
  return async (ctx, next) => {
    // get token from headers (or cookie in dev)
    const token = ctx.request.headers.authorization || (debug && ctx.cookies.get('Authorization'));
    ctx.assert(token, 401, 'No token supplied');

    let data;
    try {
      data = jwt.verify(token, sessionSecret);
    } catch (err) {
      ctx.throw(401, 'Incorrect token');
    }

    ctx.jwt = data;

    await next();
  };
}
export default function setupTransaction() {
  return async (ctx, next) => {
    const { pgClient, jwt } = ctx;
    const { role, tenantId } = jwt;

    // start transaction
    await pgClient.queryAsync('begin');
    await pgClient.queryAsync(`select set_config('role', '${role}', true)`);
    await pgClient.queryAsync(`select set_config('jwt.claims.tenant_id', '${tenantId}', true)`);

    await next();

    // commit transaction or rollback
    await pgClient.queryAsync('commit');
    pgClient.end();
  };
}

from crystal.

pvdvreede avatar pvdvreede commented on May 10, 2024

@calebmer good point about a compromised secret - it would be better to have downtime than allow that. I suppose this use case is more for standard secret rotation as a security policy than for when a secret is compromised.

I would be happy to have this stuff as a middleware so that I can customise the secret rotation and specific jwt claims as required. Does this mean we would need the library setup in #48?

from crystal.

calebmer avatar calebmer commented on May 10, 2024

Ah, wish you had left a comment on #48, just merged it 😊

Anyway, yeah making this customizable in some way does seem like a good idea. What you could do now is keep a secret that only an authentication middleware and PostGraphQL knows about and rotate a public facing secret in a middleware. So something like this process:

  1. Request comes in with a token.
  2. Your authentication middleware uses a rotating secret to verify the token.
  3. Your authentication middleware signs the token with the shared secret with PostGraphQL.
  4. Set the newly signed token to the Authorization header so PostGraphQL can use it.

Yeah it’s not ideal, but it could work and could be secure πŸ˜‰

from crystal.

sheerun avatar sheerun commented on May 10, 2024

Global secret seems really unsecure for me. I'd prefer per-user secrets with rolling change support.

The easiest way to implement it is via middleware like you mentioned

from crystal.

calebmer avatar calebmer commented on May 10, 2024

If anyone with more expertise then me wants to submit a PR for any of these methods, I’d happily merge it πŸ‘

from crystal.

benjie avatar benjie commented on May 10, 2024

I think this should be pretty easy to implement; so a PR would be welcome. You can also implement this yourself using pgSettings and bypassing the built in JWT support.

from crystal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.