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

feat(aws-ssm): add decryption support for SecureString parameters #1241

Merged
merged 4 commits into from
Mar 27, 2025
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
Binary file added assets/aws-ssm/create-param.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/aws-ssm/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/aws-ssm/ssm-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion libs/providers/aws-ssm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,41 @@ OpenFeature.setProvider(
})
);
```

# AWS SSM Provider Configuration

## AwsSsmProviderConfig

| Property | Type | Description | Default |
|-----------------|--------------------|----------------------------------------------|---------|
| `ssmClientConfig` | `SSMClientConfig` | AWS SSM Client configuration options. | See [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ssm/) |
| `enableDecryption` | `boolean` | Enable decryption for SecureString parameters | false |
| `cacheOpts` | `LRUCacheConfig` | Configuration for the local LRU cache. | See below |

## LRUCacheConfig

| Property | Type | Description | Default |
|-----------|--------|------------------------------------------------|---------|
| `enabled` | `boolean` | Whether caching is enabled. | `false` |
| `ttl` | `number` | Time-to-live (TTL) for cached items (in ms). | `300000` (5 minutes) |
| `size` | `number` | Maximum number of items in the cache. | `1000` |




## Retrieve Feature Flag!

Create a new SSM Param called 'my-feature-flag' in your AWS Account and then retrieve it via OpenFeature Client!
Open your AWS Management Console and go to AWS System Manager service

![SSM-Menu](../../../assets/aws-ssm/search.png)

Go to Parameter Store

![Parameter-Store](../../../assets/aws-ssm/ssm-menu.png)

Create a new SSM Param called 'my-feature-flag' in your AWS Account and then retrieve it via OpenFeature Client!

![Create-Param](../../../assets/aws-ssm/create-param.png)

```
const featureFlags = OpenFeature.getClient();
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/aws-ssm/src/lib/aws-ssm-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AwsSsmProvider implements Provider {
cache: Cache;

constructor(config: AwsSsmProviderConfig) {
this.service = new SSMService(config.ssmClientConfig);
this.service = new SSMService(config.ssmClientConfig, config.enableDecryption);
this.cache = new Cache(config.cacheOpts);
}

Expand Down
4 changes: 2 additions & 2 deletions libs/providers/aws-ssm/src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export class Cache {
private enabled: boolean;
constructor(opts: LRUCacheConfig) {
this.cache = new LRUCache({
maxSize: opts.size,
maxSize: opts.size ?? 1000,
sizeCalculation: () => 1,
});
this.ttl = opts.ttl;
this.ttl = opts.ttl ?? 300000;
this.enabled = opts.enabled;
}

Expand Down
41 changes: 36 additions & 5 deletions libs/providers/aws-ssm/src/lib/ssm-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { GetParameterCommand, SSMClient, SSMClientConfig } from '@aws-sdk/client-ssm';
import {
GetParameterCommand,
SSMClient,
SSMClientConfig,
GetParameterCommandInput,
DescribeParametersCommand,
} from '@aws-sdk/client-ssm';
import { ResponseMetadata } from '@smithy/types';
import {
FlagNotFoundError,
Expand All @@ -11,9 +17,10 @@ import {

export class SSMService {
client: SSMClient;

constructor(config: SSMClientConfig) {
enableDecryption: boolean;
constructor(config: SSMClientConfig, enableDecryption?: boolean) {
this.client = new SSMClient(config);
this.enableDecryption = enableDecryption ?? false;
}

async getBooleanValue(name: string): Promise<ResolutionDetails<boolean>> {
Expand Down Expand Up @@ -78,10 +85,34 @@ export class SSMService {
}
}

async _isSecureString(name: string): Promise<boolean> {
const res = await this.client.send(
new DescribeParametersCommand({
ParameterFilters: [
{
Key: 'Name',
Values: [name],
},
],
}),
);

if (!res.Parameters) {
throw new FlagNotFoundError(`Unable to find an SSM Parameter with key ${name}`);
}
return res.Parameters[0].Type === 'SecureString';
}

async _getValueFromSSM(name: string): Promise<{ val: string; metadata: ResponseMetadata }> {
const command: GetParameterCommand = new GetParameterCommand({
const param: GetParameterCommandInput = {
Name: name,
});
};

if (this.enableDecryption) {
param.WithDecryption = await this._isSecureString(name);
}

const command: GetParameterCommand = new GetParameterCommand(param);

const res = await this.client.send(command);

Expand Down
5 changes: 3 additions & 2 deletions libs/providers/aws-ssm/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { SSMClientConfig } from '@aws-sdk/client-ssm';
export type AwsSsmProviderConfig = {
ssmClientConfig: SSMClientConfig;
cacheOpts: LRUCacheConfig;
enableDecryption?: boolean;
};

export type LRUCacheConfig = {
enabled: boolean;
ttl: number;
size: number;
ttl?: number;
size?: number;
};