Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for securing webtask execution #197

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

lzychowski
Copy link
Contributor

@lzychowski lzychowski commented Apr 12, 2018

To secure the execution of a webtask user can add the --auth flag to the create method. Currently the only supported authentication method is jwt.

for example:

wt create file.js --auth jwt --meta-file meta for V1 profiles
wt create file.js --auth jwt for V2 profiles

Deployments with V1 security enabled (required):

  • Set the wt-execution-aud metadata property which identifies the recipients that the JWT is intended for (requires wt-execution-iss to be specified as well).
  • Set the wt-execution-iss metadata property which identifies the principal that issued the JWT (requires wt-execution-aud to be specified as well).

Deployments with V2 security enabled (optional):

  • Set the wt-execution-aud metadata property which identifies the recipients that the JWT is intended for (requires wt-execution-iss to be specified as well).
  • Set the wt-execution-iss metadata property which identifies the principal that issued the JWT (requires wt-execution-aud to be specified as well).
  • If neither wt-execution-iss nor wt-execution-aud metadata properties are specified the wt cli will retrieve issuer and audience values from the deployment discovery endpoint. Automatic retrieval of the issuer and audience works only on deployments with V2 security turned on.

Additional metadata can be specified when using this flag:

  • Set the wt-execution-scope metadata property to the name of a custom scope that can be used for authorization of webtask execution.

See https://www.npmjs.com/package/@webtask/jwt-middleware for more details.

Copy link
Contributor

@ggoodman ggoodman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what alternative flag names might be possible. I think --secure might be a bit generic as there are many different approaches to securing a webtask.

bin/create.js Outdated
type: 'boolean'
},
'execution-scope': {
description: 'Set the wt-execution-scope metadata property to the name of a custom scope that can be used for authorization of webtask execution. Requires --secure flag to be set.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the wt-execution-scope

Missing a 'j'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the 'j' missing? I looked over 139-146...

const JWT_MIDDLEWARE = '@webtask/jwt-middleware';
const JWT_MIDDLEWARE_VERSION = '^1.4.0';

module.exports = secureWebtask = (args, options) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're accidentally creating a secureWebtask global here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const Request = Bluebird.promisifyAll(require('request'));
const Cli = require('structured-cli');

const MIDDLWARE_COMPILER = '@webtask/middleware-compiler';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that these are being used across several parts of the cli, I'd like to see these 'magic constants' centralized so that we only have to change one place to keep them up to date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

throw new Cli.error.serverError(`Unable to read response from the discovery endpoint.`);
}

args.meta['wt-execution-iss'] = body.authorization_server;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some checks to see that these are actually returned from the server?

});
}

function addMeta(args, res, options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, but is there any situation in which args.meta comes in as undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is. If I run wt create {file} -p {profile} --secure --execution-scope wt:exec there will be no args.meta at the time when secureWebtask.js gets called. The only way for args.meta to be set is if middleware or meta are set by the user.

args.meta['wt-middleware'] = JWT_MIDDLEWARE;
}

if (!args.syntheticDependencies[MIDDLWARE_COMPILER]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question, is there any code path in which args.syntheticDependencies hasn't been defined yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is. If I run wt create {file} -p {profile} --secure --execution-scope wt:exec there will be no syntheticDependencies at the time when secureWebtask.js gets called. The only way for syntheticDependencies to be set is if middleware or node-dependencies are set by the user.

@@ -44,6 +44,10 @@ function validateCreateArgs(args) {

}

if (args.profile.securityVersion === "v1" && args.secure){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember if we had decided to support custom issuers and custom audiences in the first iteration. What would you think about logic whereby either both --jwt-audience and --jwt-issuer are required or neither must be present. If neither are present, then we would fall back to discovering the defaults from the cluster.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggoodman do you mean additional CLI flags with values that take precedence over the call to the discovery endpoint? I think it is a good idea and I can add it to the CLI.

@glennblock
Copy link
Contributor

@lzychowski can you add a sample to the PR description showing the usage patterns for a CLI user?

Copy link
Contributor

@ggoodman ggoodman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following some discussions with the team, I wonder if we should rename jwt to something more explicit like jwt-rsa256 or...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants