UNPKG

@ji-constructs/ecs-jwt-keypair

Version:

This is an [AWS CDK](https://aws.amazon.com/cdk/) L3 Construct for creating PEM format keypairs in [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) which can be used for RS256 JWT signing/verification.

38 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EcsJwtKeyPair = void 0; const aws_cdk_lib_1 = require("aws-cdk-lib"); const aws_ecs_1 = require("aws-cdk-lib/aws-ecs"); const aws_secretsmanager_1 = require("aws-cdk-lib/aws-secretsmanager"); const cdk_ec2_key_pair_1 = require("cdk-ec2-key-pair"); const constructs_1 = require("constructs"); class EcsJwtKeyPair extends constructs_1.Construct { constructor(scope, id, props = {}) { var _a; super(scope, id); const stackName = aws_cdk_lib_1.Stack.of(this).stackName; const resourcePrefix = stackName.length > 30 ? stackName.slice(0, 15) + stackName.slice(-15) : stackName; this.keyPair = new cdk_ec2_key_pair_1.KeyPair(this, 'KeyPair', { resourcePrefix, name: (_a = props.keyName) !== null && _a !== void 0 ? _a : this.node.addr, storePublicKey: true, publicKeyFormat: cdk_ec2_key_pair_1.PublicKeyFormat.PEM, }); this.secrets = { privateKey: aws_secretsmanager_1.Secret.fromSecretCompleteArn(this, 'JwtPrivateKey', this.keyPair.privateKeyArn), publicKey: aws_secretsmanager_1.Secret.fromSecretCompleteArn(this, 'JwtPublicKey', this.keyPair.publicKeyArn), }; this.ecsSecrets = { privateKey: aws_ecs_1.Secret.fromSecretsManager(this.secrets.privateKey), publicKey: aws_ecs_1.Secret.fromSecretsManager(this.secrets.publicKey), }; } grantRead(taskRole) { this.keyPair.grantReadOnPrivateKey(taskRole); this.keyPair.grantReadOnPublicKey(taskRole); } } exports.EcsJwtKeyPair = EcsJwtKeyPair; //# sourceMappingURL=ecs-jwt-keypair.js.map