{"_id":"@darren-valent/cdk-ec2-key-pair","name":"@darren-valent/cdk-ec2-key-pair","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@darren-valent/cdk-ec2-key-pair","description":"CDK Construct for managing EC2 key pairs","version":"0.0.0","license":"Apache-2.0","author":{"name":"Daniel Schroeder","url":"https://www.udondan.com/"},"awscdkio":{"twitter":"udondan"},"homepage":"https://github.com/udondan/cdk-ec2-key-pair","repository":{"type":"git","url":"git+https://github.com/Valent-Projects/cdk-ec2-key-pair.git"},"bugs":{"url":"https://github.com/udondan/cdk-ec2-key-pair/issues"},"keywords":["aws","cdk","aws-cdk","aws-cdk-construct","ec2","ec2-key-pair","cloudformation","cloudformation-custom-resource"],"stability":"stable","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"jsii","build:watch":"jsii -w","package":"jsii-pacmak","prepackage":"jsii && lambda/build"},"jsii":{"excludeTypescript":["lambda"],"outdir":"dist","targets":{"python":{"distName":"cdk-ec2-key-pair","module":"cdk_ec2_key_pair"},"dotnet":{"namespace":"CDK.EC2.KeyPair","packageId":"CDK.EC2.KeyPair"}}},"devDependencies":{"@types/node":"^18.11.3","@types/aws-lambda":"^8.10.92","@types/node-forge":"^1.0.0","aws-cdk-lib":"^2.0.0","aws-lambda":"^1.0.7","@aws-sdk/client-ec2":"^3.398.0","@aws-sdk/client-secrets-manager":"^3.398.0","jsii":"5.2.17","jsii-pacmak":"1.90.0","ts-node":"^10.4.0","typescript":"^5.2.2","constructs":"^10.0.0"},"peerDependencies":{"aws-cdk-lib":"^2.0.0","constructs":"^10.0.0"},"directories":{"lib":"lib","test":"test"},"dependencies":{"acorn":"^8.10.0","acorn-walk":"^8.2.0","ajv":"^8.12.0","ansi-regex":"^5.0.1","ansi-styles":"^4.3.0","arg":"^4.1.3","argparse":"^1.0.10","available-typed-arrays":"^1.0.5","aws-sdk":"^2.1477.0","balanced-match":"^1.0.2","base64-js":"^1.5.1","bowser":"^2.11.0","brace-expansion":"^1.1.11","braces":"^3.0.2","buffer":"^4.9.2","call-bind":"^1.0.5","camelcase":"^6.3.0","case":"^1.6.3","chalk":"^4.1.2","cliui":"^8.0.1","clone":"^2.1.2","codemaker":"^1.90.0","color-convert":"^2.0.1","color-name":"^1.1.4","commander":"^3.0.2","commonmark":"^0.30.0","concat-map":"^0.0.1","create-require":"^1.1.1","date-format":"^4.0.14","debug":"^4.3.4","decamelize":"^5.0.1","define-data-property":"^1.1.1","detect-indent":"^5.0.0","detect-newline":"^2.1.0","diff":"^4.0.2","downlevel-dts":"^0.11.0","emoji-regex":"^8.0.0","entities":"^2.0.3","escalade":"^3.1.1","escape-string-regexp":"^4.0.0","esprima":"^4.0.1","events":"^1.1.1","fast-deep-equal":"^3.1.3","fast-glob":"^3.3.1","fast-xml-parser":"^4.2.5","fastq":"^1.15.0","fill-range":"^7.0.1","flatted":"^3.2.9","for-each":"^0.3.3","fs-extra":"^10.1.0","fs.realpath":"^1.0.0","function-bind":"^1.1.2","get-caller-file":"^2.0.5","get-intrinsic":"^1.2.1","glob":"^7.2.3","glob-parent":"^5.1.2","glob-to-regexp":"^0.4.1","gopd":"^1.0.1","graceful-fs":"^4.2.11","has":"^1.0.4","has-flag":"^4.0.0","has-property-descriptors":"^1.0.0","has-proto":"^1.0.1","has-symbols":"^1.0.3","has-tostringtag":"^1.0.0","ieee754":"^1.1.13","inflight":"^1.0.6","inherits":"^2.0.4","interpret":"^1.4.0","is-arguments":"^1.1.1","is-callable":"^1.2.7","is-core-module":"^2.13.0","is-extglob":"^2.1.1","is-fullwidth-code-point":"^3.0.0","is-generator-function":"^1.0.10","is-glob":"^4.0.3","is-number":"^7.0.0","is-typed-array":"^1.1.12","isarray":"^1.0.0","jmespath":"^0.16.0","js-yaml":"^3.14.1","jsii-reflect":"^1.90.0","jsii-rosetta":"^1.90.0","json-schema-traverse":"^1.0.0","jsonfile":"^6.1.0","log4js":"^6.9.1","lru-cache":"^6.0.0","make-error":"^1.3.6","mdurl":"^1.0.1","merge2":"^1.4.1","micromatch":"^4.0.5","minimatch":"^3.1.2","minimist":"^1.2.8","ms":"^2.1.2","once":"^1.4.0","oo-ascii-tree":"^1.90.0","path-is-absolute":"^1.0.1","path-parse":"^1.0.7","picomatch":"^2.3.1","punycode":"^2.3.0","querystring":"^0.2.0","queue-microtask":"^1.2.3","rechoir":"^0.6.2","require-directory":"^2.1.1","require-from-string":"^2.0.2","resolve":"^1.22.8","reusify":"^1.0.4","rfdc":"^1.3.0","run-parallel":"^1.2.0","sax":"^1.2.1","semver":"^7.5.4","semver-intersect":"^1.4.0","set-function-length":"^1.1.1","shelljs":"^0.8.5","sort-json":"^2.0.1","spdx-license-list":"^6.7.0","sprintf-js":"^1.0.3","stream-chain":"^2.2.5","stream-json":"^1.8.0","streamroller":"^3.1.5","string-width":"^4.2.3","string.prototype.repeat":"^0.2.0","strip-ansi":"^6.0.1","strnum":"^1.0.5","supports-color":"^7.2.0","supports-preserve-symlinks-flag":"^1.0.0","to-regex-range":"^5.0.1","tslib":"^2.6.2","universalify":"^2.0.0","uri-js":"^4.4.1","url":"^0.10.3","util":"^0.12.5","uuid":"^8.3.2","v8-compile-cache-lib":"^3.0.1","watchpack":"^2.4.0","which-typed-array":"^1.1.13","workerpool":"^6.5.1","wrap-ansi":"^7.0.0","wrappy":"^1.0.2","xml2js":"^0.5.0","xmlbuilder":"^15.1.1","y18n":"^5.0.8","yallist":"^4.0.0","yargs":"^17.7.2","yargs-parser":"^21.1.1","yn":"^3.1.1"},"_id":"@darren-valent/cdk-ec2-key-pair@0.0.0","gitHead":"2fbc28d405f64a39356dd7645c400f15f87eba3a","_nodeVersion":"18.18.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-26X2Hlvw7fpHCp1zRtB8+8/ZPLh69LCqTQ6JzQs326qdWO4QpioZ2CSklrd5dsTDGX4vIq82wSB55Nd3R9pnDg==","shasum":"0cc87dedccc2c075476cfff0812a40d875195ff4","tarball":"https://registry.npmjs.org/@darren-valent/cdk-ec2-key-pair/-/cdk-ec2-key-pair-0.0.0.tgz","fileCount":85,"unpackedSize":2146945,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDNPLevI49/a1dtEnMtK+/cpVmk8XQmRGMUguf8q09O2wIgAzork3IAwxZ07YvLBCtSZyOwRq4m4d/SEnwaSrC34Uo="}]},"_npmUser":{"name":"darren-valent","email":"darren@valent-projects.com"},"maintainers":[{"name":"darren-valent","email":"darren@valent-projects.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cdk-ec2-key-pair_0.0.0_1697821134039_0.9641006176982188"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-20T16:58:53.925Z","0.0.0":"2023-10-20T16:58:54.348Z","modified":"2023-10-20T16:58:54.656Z"},"maintainers":[{"name":"darren-valent","email":"darren@valent-projects.com"}],"description":"CDK Construct for managing EC2 key pairs","homepage":"https://github.com/udondan/cdk-ec2-key-pair","keywords":["aws","cdk","aws-cdk","aws-cdk-construct","ec2","ec2-key-pair","cloudformation","cloudformation-custom-resource"],"repository":{"type":"git","url":"git+https://github.com/Valent-Projects/cdk-ec2-key-pair.git"},"author":{"name":"Daniel Schroeder","url":"https://www.udondan.com/"},"bugs":{"url":"https://github.com/udondan/cdk-ec2-key-pair/issues"},"license":"Apache-2.0","readme":"# CDK EC2 Key Pair\n\n[![Source](https://img.shields.io/badge/Source-GitHub-blue?logo=github)][source]\n[![Test](https://github.com/udondan/cdk-ec2-key-pair/workflows/Test/badge.svg)](https://github.com/udondan/cdk-ec2-key-pair/actions?query=workflow%3ATest)\n[![GitHub](https://img.shields.io/github/license/udondan/cdk-ec2-key-pair)][license]\n[![Docs](https://img.shields.io/badge/Construct%20Hub-cdk--ec2--key--pair-orange)][docs]\n\n[![npm package](https://img.shields.io/npm/v/cdk-ec2-key-pair?color=brightgreen)][npm]\n[![PyPI package](https://img.shields.io/pypi/v/cdk-ec2-key-pair?color=brightgreen)][PyPI]\n\n![Downloads](https://img.shields.io/badge/-DOWNLOADS:-brightgreen?color=gray)\n[![npm](https://img.shields.io/npm/dt/cdk-ec2-key-pair?label=npm&color=blueviolet)][npm]\n[![PyPI](https://img.shields.io/pypi/dm/cdk-ec2-key-pair?label=pypi&color=blueviolet)][PyPI]\n\n[AWS CDK] L3 construct for managing [EC2 Key Pairs].\n\nCloudFormation doesn't directly support creation of EC2 Key Pairs. This construct provides an easy interface for creating Key Pairs through a [custom CloudFormation resource]. The private key is stored in [AWS Secrets Manager].\n\n## Installation\n\nThis package has peer dependencies, which need to be installed along in the expected version.\n\nFor TypeScript/NodeJS, add these to your `dependencies` in `package.json`. For Python, add these to your `requirements.txt`:\n\n- cdk-ec2-key-pair\n- aws-cdk-lib (^2.0.0)\n- constructs (^10.0.0)\n\n## CDK compatibility\n\n- Version 3.x is compatible with the CDK v2.\n- Version 2.x is compatible with the CDK v1. There won't be regular updates for this.\n\n## Usage\n\n```typescript\nimport cdk = require('aws-cdk-lib');\nimport { Construct } from 'constructs';\nimport { KeyPair } from 'cdk-ec2-key-pair';\n\n// ...\n\n// Create the Key Pair\nconst key = new KeyPair(this, 'A-Key-Pair', {\n    name: 'a-key-pair',\n    description: 'This is a Key Pair',\n    storePublicKey: true, // by default the public key will not be stored in Secrets Manager\n});\n\n// Grant read access to the private key to a role or user\nkey.grantReadOnPrivateKey(someRole)\n\n// Grant read access to the public key to another role or user\nkey.grantReadOnPublicKey(anotherRole)\n\n// Use Key Pair on an EC2 instance\nnew ec2.Instance(this, 'An-Instance', {\n    keyName: key.keyPairName,\n    // ...\n})\n```\n\nThe private (and optionally the public) key will be stored in AWS Secrets Manager. The secret names by default are prefixed with `ec2-ssh-key/`. The private key is suffixed with `/private`, the public key is suffixed with `/public`. So in this example they will be stored as `ec2-ssh-key/a-key-pair/private` and `ec2-ssh-key/a-key-pair/public`.\n\nTo download the private key via AWS cli you can run:\n\n```bash\naws secretsmanager get-secret-value \\\n  --secret-id ec2-ssh-key/a-key-pair/private \\\n  --query SecretString \\\n  --output text\n```\n\n### Tag support\n\nThe construct supports tagging:\n\n```typescript\ncdk.Tags.of(key).add('someTag', 'some value');\n```\n\nWe also use tags to restrict update/delete actions to those, the construct created itself. The Lambda function, which backs the custom CFN resource, is not able to manipulate other keys/secrets. The tag we use for identifying these resources is `CreatedByCfnCustomResource` with value `CFN::Resource::Custom::EC2-Key-Pair`.\n\n### Updates\n\nSince an EC2 KeyPair cannot be updated, you cannot change any property related to the KeyPair. The code has checks in place which will prevent any attempt to do so. If you try, the stack will end in a failed state. In that case you can safely continue the rollback in the AWS console and ignore the key resource.\n\nYou can, however, change properties that only relate to the secrets. These are the KMS keys used for encryption, the `secretPrefix`, `description` and `removeKeySecretsAfterDays`.\n\n### Encryption\n\nSecrets in the AWS Secrets Manager by default are encrypted with the key `alias/aws/secretsmanager`.\n\nTo use a custom KMS key you can pass it to the Key Pair:\n\n```typescript\nconst kmsKey = new kms.Key(this, 'KMS-key');\n\nconst keyPair = new KeyPair(this, 'A-Key-Pair', {\n    name: 'a-key-pair',\n    kms: kmsKey,\n});\n```\n\nThis KMS key needs to be created in the same stack. You cannot use a key imported via ARN, because the keys access policy will need to be modified.\n\nTo use different KMS keys for the private and public key, use the `kmsPrivateKey` and `kmsPublicKey` instead:\n\n```typescript\nconst kmsKeyPrivate = new kms.Key(this, 'KMS-key-private');\nconst kmsKeyPublic = new kms.Key(this, 'KMS-key-public');\n\nconst keyPair = new KeyPair(this, 'A-Key-Pair', {\n    name: 'a-key-pair',\n    kmsPrivateKey: kmsKeyPrivate,\n    kmsPublicKey: kmsKeyPublic\n});\n```\n\n### Importing public key\n\nYou can create a key pair by importing the public key. Obviously, in this case the private key won't be available in secrets manager.\n\nThe public key has to be in OpenSSH format.\n\n```typescript\nnew KeyPair(this, 'Test-Key-Pair', {\n  name: 'imported-key-pair',\n  publicKey: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuMmbK...'\n});\n```\n\n### Using the key pair for CloudFront signed url/cookies\n\nYou can use this library for generating keys for CloudFront signed url/cookies.\n\nMake sure to set `publicKeyFormat` to `PublicKeyFormat.PEM` as that is the format required for CloudFront.\nYou also have to set `exposePublicKey` to `true` so you can actually get the public key.\n\n```typescript\n  const key = new KeyPair(this, 'Signing-Key-Pair', {\n      name: 'CFN-signing-key',\n      exposePublicKey: true,\n      storePublicKey: true,\n      publicKeyFormat: PublicKeyFormat.PEM\n  });\n\n  const pubKey = new cloudfront.PublicKey(this, 'Signing-Public-Key', {\n    encodedKey: key.publicKeyValue,\n  });\n  const trustedKeyGroupForCF = new cloudfront.KeyGroup(this, 'Signing-Key-Group', {\n    items: [ pubKey ]\n  });\n```\n\n   [AWS CDK]: https://aws.amazon.com/cdk/\n   [custom CloudFormation resource]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html\n   [EC2 Key Pairs]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html\n   [AWS Secrets Manager]: https://aws.amazon.com/secrets-manager/\n   [npm]: https://www.npmjs.com/package/cdk-ec2-key-pair\n   [PyPI]: https://pypi.org/project/cdk-ec2-key-pair/\n   [docs]: https://constructs.dev/packages/cdk-ec2-key-pair\n   [source]: https://github.com/udondan/cdk-ec2-key-pair\n   [license]: https://github.com/udondan/cdk-ec2-key-pair/blob/main/LICENSE\n","readmeFilename":"README.md"}