Skip to content

Commit

Permalink
feat: support single line for app private key (#1368)
Browse files Browse the repository at this point in the history
* feat: support single line private keys

* docs: docs for the new key storage options

* docs: use original doc style

* style: use single quotes

* chore: fmt ts files

* docs: use original language more

* docs: use the original language more

* fix: use correct char code for new line

Co-authored-by: Callum <callum@domain.com>
  • Loading branch information
toast-gear and Callum committed Nov 9, 2021
1 parent 50737a2 commit 14183ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ resource "aws_iam_service_linked_role" "spot" {

Next create a second terraform workspace and initiate the module, or adapt one of the [examples](./examples).

Note that `github_app.key_base64` needs to be the base64-encoded `.pem` file, i.e., the output of `base64 app.private-key.pem` (not directly the content of `app.private-key.pem`).
Note that `github_app.key_base64` needs to be a base64-encoded string of the `.pem` file i.e. the output of `base64 app.private-key.pem`. The decoded string can either be a multiline value or a single line value with new lines represented with literal `\n` characters.

```terraform
module "github-runner" {
Expand Down
7 changes: 6 additions & 1 deletion modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ async function createAuth(installationId: number | undefined, ghesApiUrl: string
privateKey: Buffer.from(
await getParameterValue(process.env.PARAMETER_GITHUB_APP_KEY_BASE64_NAME),
'base64',
).toString(),
// replace literal \n characters with new lines to allow the key to be stored as a
// single line variable. This logic should match how the GitHub Terraform provider
// processes private keys to retain compatibility between the projects
)
.toString()
.replace('/[\\n]/g', String.fromCharCode(10)),
};
if (installationId) authOptions = { ...authOptions, installationId };

Expand Down

0 comments on commit 14183ac

Please sign in to comment.