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

chore: rename auth token to api key in docs #7

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

- [Node.js®](https://nodejs.org/) v16+
- [Node Package Manager (npm)](https://www.npmjs.com/)
- A Momento auth token JSON file created in the [Momento console](https://console.gomomento.com/tokens)
- A Momento api key JSON file created in the [Momento console](https://console.gomomento.com/tokens)
- AWS [command line tools](https://aws.amazon.com/cli/)

## How to update Momento Javascript SDK
Expand All @@ -30,22 +30,22 @@ AWS_PROFILE=<YOUR_AWS_PROFILE_NAME> ./scripts/deploy.sh

Below is a list of optional environment variables you can pass in to deploy.sh:

- `AUTO_ROTATION_IN_DAYS:` override the schedule (in days) in which the auth token will be refreshed. **Default:** 1 day
- `AUTO_ROTATION_IN_DAYS:` override the schedule (in days) in which the api key will be refreshed. **Default:** 1 day
- `KMS_KEY_ARN`: override if you want to use your own KMS key to encrypt your secret in Secrets Manager. **Default:** `null`
- `MOMENTO_AUTH_TOKEN_SECRET_NAME`: override the name of the Secret created by the stack to store your auth token, multiple names can be added here separated by commas, this will allow the lambda to rotate multiple secrets. **Default:** `momento/authentication-token` **Example** `momento/auth-token-0,momento/auth-token-1`
- `SKIP_TEST_STEP_ENV_KEY_VALUE`: override if you want to skip the auth token testing, this will also disable CloudWatch Metrics. **Default:** `false`
- `MOMENTO_AUTH_TOKEN_SECRET_NAME`: override the name of the Secret created by the stack to store your api key, multiple names can be added here separated by commas, this will allow the lambda to rotate multiple secrets. **Default:** `momento/authentication-token` **Example** `momento/auth-token-0,momento/auth-token-1`
- `SKIP_TEST_STEP_ENV_KEY_VALUE`: override if you want to skip the api key testing, this will also disable CloudWatch Metrics. **Default:** `false`

Test environment variables

- `USE_STUB_KEY_VALUE`: override if you would like to stub out client responses, this is for testing purposes and no auth token will be refreshed while this is `true`. **Default:** `false`
- `USE_STUB_KEY_VALUE`: override if you would like to stub out client responses, this is for testing purposes and no api key will be refreshed while this is `true`. **Default:** `false`
- `MOCK_TOKEN_ENV_KEY_VALUE`: override if you would like to return a different mocked response from Secrets Manager for `getSecret` calls, requires `USE_STUB_KEY_VALUE` to be `true`. **Default:** `{}`
- `MOCK_TOKEN_STATUS_ENV_KEY_VALUE`: override if you would like to return a different mocked response for token status, this is to test cloudwatch Metrics, requires `USE_STUB_KEY_VALUE` to be `true`. **Default:** `[['AWSCURRENT', TokenStatus.VALID], ['AWSPENDING', TokenStatus.VALID]]`

Upon completion of deployment, your secrets will be created in AWS Secret Manager, however, they now need to be populated. This can be done through AWS Secrets Manager console, or through the aws cli.

For more info on what needs to be stored and where to get the token, checkout the [README](./README.md) `Prerequisites` section.

The JSON Auth Token file can then be used to create a secret in AWS secret manager, like so
The JSON api key file can then be used to create a secret in AWS secret manager, like so

```shell
aws secretsmanager create-secret --name "momento/authentication-token" --secret-string file://momento_token_info.json
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-alpha.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md)


# Momento auth token refresh using an AWS Lambda function
# Momento api key refresh using an AWS Lambda function

This repo provides an example solution to manage and auto-refresh Momento authentication tokens for best security practices. This is done via a Node.js&reg; 16 function deployed to AWS Lambda in your AWS account.

## Prerequisites

1. An AWS account with a role which can run AWS CDK
2. A Momento auth token downloaded from the [Momento console](https://console.gomomento.com/tokens) to a JSON file.
2. A Momento api key downloaded from the [Momento console](https://console.gomomento.com/tokens) to a JSON file.

If you need a Momento auth token, [log into the Momento console](https://console.gomomento.com/tokens) and generate one using the UI.
If you need a Momento api key, [log into the Momento console](https://console.gomomento.com/tokens) and generate one using the UI.

Instructions on how to generate your token can be found [in our public docs](https://docs.momentohq.com/getting-started#step-2-create-an-authentication-token-in-the-momento-console).

The generated result should be downloaded as a JSON file for safe keeping, named `momento_token.info.json`. Open this fil The contents of the downloaded JSON file will look like:

```json
{
"authToken": "<jwt auth token>",
"apiKey": "<jwt api key>",
"refreshToken": "<refresh token>",
"validUntil": "<epoch timestamp when token expires>"
}
```

## Deploying the Lambda function to an AWS account

Using the command line; deploy the function, IAM role, auth token, etc., via CLI, with the following instructions:
Using the command line; deploy the function, IAM role, api key, etc., via CLI, with the following instructions:

[DEPLOYMENT](./DEPLOYMENT.md)

Expand All @@ -45,16 +45,16 @@ With the Lambda function in this repo deployed, you can manually invoke the Lamb

If you've overriden the default secret name, then replace `momento/authentication-token` with your custom name.

## Retrieving auth token from secret manager
## Retrieving api key from secret manager

Your application simply needs to retrieve the newly-generated secret from AWS Secrets Manager. The secret name (unless overwritten) is `momento/authentication-token`, the token is stored in three key value parts, authToken, refreshToken, and validUntil.
Your application simply needs to retrieve the newly-generated secret from AWS Secrets Manager. The secret name (unless overwritten) is `momento/authentication-token`, the token is stored in three key value parts, apiKey, refreshToken, and validUntil.

Example using the AWS CLI and `jq`:

```shell
aws secretsmanager get-secret-value --secret-id "momento/authentication-token" | jq '.SecretString | fromjson'
{
"authToken": "<jwt auth token>",
"apiKey": "<jwt api key>",
"refreshToken": "<refresh token>",
"validUntil": "<epoch timestamp when token expires>"
}
Expand Down
16 changes: 8 additions & 8 deletions README.template.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{{ ossHeader }}

# Momento auth token refresh using an AWS Lambda function
# Momento api key refresh using an AWS Lambda function

This repo provides an example solution to manage and auto-refresh Momento authentication tokens for best security practices. This is done via a Node.js&reg; 16 function deployed to AWS Lambda in your AWS account.

## Prerequisites

1. An AWS account with a role which can run AWS CDK
2. A Momento auth token downloaded from the [Momento console](https://console.gomomento.com/tokens) to a JSON file.
2. A Momento api key downloaded from the [Momento console](https://console.gomomento.com/tokens) to a JSON file.

If you need a Momento auth token, [log into the Momento console](https://console.gomomento.com/tokens) and generate one using the UI.
If you need a Momento api key, [log into the Momento console](https://console.gomomento.com/tokens) and generate one using the UI.

Instructions on how to generate your token can be found [in our public docs](https://docs.momentohq.com/getting-started#step-2-create-an-authentication-token-in-the-momento-console).

The generated result should be downloaded as a JSON file for safe keeping, named `momento_token.info.json`. Open this fil The contents of the downloaded JSON file will look like:

```json
{
"authToken": "<jwt auth token>",
"apiKey": "<jwt api key>",
"refreshToken": "<refresh token>",
"validUntil": "<epoch timestamp when token expires>"
}
```

## Deploying the Lambda function to an AWS account

Using the command line; deploy the function, IAM role, auth token, etc., via CLI, with the following instructions:
Using the command line; deploy the function, IAM role, api key, etc., via CLI, with the following instructions:

[DEPLOYMENT](./DEPLOYMENT.md)

Expand All @@ -41,16 +41,16 @@ With the Lambda function in this repo deployed, you can manually invoke the Lamb

If you've overriden the default secret name, then replace `momento/authentication-token` with your custom name.

## Retrieving auth token from secret manager
## Retrieving api key from secret manager

Your application simply needs to retrieve the newly-generated secret from AWS Secrets Manager. The secret name (unless overwritten) is `momento/authentication-token`, the token is stored in three key value parts, authToken, refreshToken, and validUntil.
Your application simply needs to retrieve the newly-generated secret from AWS Secrets Manager. The secret name (unless overwritten) is `momento/authentication-token`, the token is stored in three key value parts, apiKey, refreshToken, and validUntil.

Example using the AWS CLI and `jq`:

```shell
aws secretsmanager get-secret-value --secret-id "momento/authentication-token" | jq '.SecretString | fromjson'
{
"authToken": "<jwt auth token>",
"apiKey": "<jwt api key>",
"refreshToken": "<refresh token>",
"validUntil": "<epoch timestamp when token expires>"
}
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/lib/infrastructure-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {NodejsFunction} from 'aws-cdk-lib/aws-lambda-nodejs';
import path = require('path');

interface AuthTokenOptions {
// The name you would like to give to the Secret containing your Momento auth token,
// The name you would like to give to the Secret containing your Momento api key,
// multiple secrets can be refreshed by adding a comma spliced list
momentoAuthTokenSecretName?: string[];
// Override this if you wish to change when the secret is automatically rotated.
Expand Down
4 changes: 2 additions & 2 deletions lambda/src/clients/momento-refresh/refresh-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class MomentoRefreshManager implements MomentoRefresh {
if (listResponse instanceof ListCaches.Error) {
if (this.invalidAuthTokenResponse.includes(listResponse.errorCode())) {
console.warn(
`Invalid auth token for stage ${
`Invalid api key for stage ${
versionStage ? versionStage : 'undefined'
}, client error code: ${listResponse.errorCode()}`
);
return TokenStatus.INVALID;
} else {
// This is best effort, if we get an error other then an authentication error, we can just move on
console.warn(
`Failed to test auth token, client error code: ${listResponse.errorCode()}`
`Failed to test api key, client error code: ${listResponse.errorCode()}`
);
return TokenStatus.NOT_TESTED;
}
Expand Down
4 changes: 2 additions & 2 deletions lambda/src/process-token-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class ProcessTokenRefresh {

switch (pendingTokenStatus) {
case TokenStatus.VALID:
console.log('Valid auth token, nothing else to do.');
console.log('Valid api key, nothing else to do.');
break;
case TokenStatus.INVALID:
{
Expand All @@ -183,7 +183,7 @@ export class ProcessTokenRefresh {
SECRET_CURRENT
);
Common.logAndThrow(
`Failed to refresh auth token for secret, ${secretId}`
`Failed to refresh api key for secret, ${secretId}`
);
}
}
Expand Down