Skip to content

Commit 262703e

Browse files
author
Phil Varner
authored
add support for IAM auth to OpenSearch Serverless (#644)
* add support for IAM auth to OpenSearch Serverless * remove mod to serve
1 parent 7d74f55 commit 262703e

File tree

8 files changed

+1333
-202
lines changed

8 files changed

+1333
-202
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased] - TBD
99

10+
### Added
11+
12+
- Added support for AWS IAM authentication to AWS OpenSearch Serverless
13+
1014
### Changed
1115

16+
- Replaced use of aws-os-connection library for AWS IAM authentication with support
17+
in opensearch-js.
1218
- Default to OpenSearch 2.11
1319

1420
## [3.0.0] - 2023-11-09
@@ -380,7 +386,7 @@ Initial release, forked from [sat-api](https://github.com/sat-utils/sat-api/tree
380386

381387
Compliant with STAC 0.9.0
382388

383-
<!-- [Unreleased]: https://github.com/stac-utils/stac-api/compare/v2.4.0...main -->
389+
[Unreleased]: https://github.com/stac-utils/stac-api/compare/v2.4.0...main
384390
[3.0.0]: https://github.com/stac-utils/stac-api/compare/v2.4.0...v3.0.0
385391
[2.4.0]: https://github.com/stac-utils/stac-api/compare/v2.3.0...v2.4.0
386392
[2.3.0]: https://github.com/stac-utils/stac-api/compare/v2.2.3...v2.3.0

package-lock.json

Lines changed: 1305 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@
6565
"@aws-sdk/client-secrets-manager": "^3.441.0",
6666
"@aws-sdk/client-sns": "^3.431.0",
6767
"@aws-sdk/client-sqs": "^3.431.0",
68+
"@aws-sdk/credential-provider-node": "^3.458.0",
6869
"@aws-sdk/s3-request-presigner": "^3.458.0",
6970
"@mapbox/extent": "^0.4.0",
7071
"@opensearch-project/opensearch": "^2.4.0",
71-
"aws-os-connection": "^0.2.0",
7272
"cors": "^2.8.5",
7373
"express": "^4.18.2",
7474
"got": "^13.0.0",
@@ -85,9 +85,9 @@
8585
"zod": "^3.22.4"
8686
},
8787
"devDependencies": {
88-
"@tsconfig/node18": "^18.2.2",
8988
"@ava/typescript": "^4.1.0",
9089
"@stoplight/spectral-cli": "^6.11.0",
90+
"@tsconfig/node18": "^18.2.2",
9191
"@types/aws-lambda": "^8.10.125",
9292
"@types/cors": "^2.8.17",
9393
"@types/express": "^4.17.21",

src/lambdas/ingest/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/prefer-default-export */
22
import got from 'got' // eslint-disable-line import/no-unresolved
3-
import { createIndex } from '../../lib/databaseClient.js'
3+
import { createIndex } from '../../lib/database-client.js'
44
import { ingestItems, publishResultsToSns } from '../../lib/ingest.js'
55
import getObjectJson from '../../lib/s3-utils.js'
66
import logger from '../../lib/logger.js'

src/lib/databaseClient.js renamed to src/lib/database-client.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Client } from '@opensearch-project/opensearch'
2-
import { createAWSConnection as createAWSConnectionOS, awsGetCredentials } from 'aws-os-connection'
32

3+
// eslint-disable-next-line import/no-unresolved
4+
import { AwsSigv4Signer } from '@opensearch-project/opensearch/aws'
5+
import { defaultProvider } from '@aws-sdk/credential-provider-node'
46
import { SecretsManager, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
57

68
import collectionsIndexConfiguration from '../../fixtures/collections.js'
@@ -16,6 +18,17 @@ function createClientWithUsernameAndPassword(host, username, password) {
1618
})
1719
}
1820

21+
function createClientWithAwsAuth(host) {
22+
return new Client({
23+
...AwsSigv4Signer({
24+
region: process.env['AWS_REGION'] || 'us-west-2',
25+
service: host.endsWith('aoss.amazonaws.com') ? 'aoss' : 'es',
26+
getCredentials: () => defaultProvider()(),
27+
}),
28+
node: host
29+
})
30+
}
31+
1932
// Connect to a search database instance
2033
export async function connect() {
2134
let client
@@ -42,11 +55,7 @@ export async function connect() {
4255
} else if (envUsername && envPassword) {
4356
client = createClientWithUsernameAndPassword(host, envUsername, envPassword)
4457
} else {
45-
// authenticate with IAM, fine-grained perms not enabled
46-
client = new Client({
47-
...createAWSConnectionOS(await awsGetCredentials()),
48-
node: host
49-
})
58+
client = createClientWithAwsAuth(host)
5059
}
5160
}
5261

src/lib/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dbClient as _client, createIndex } from './databaseClient.js'
1+
import { dbClient as _client, createIndex } from './database-client.js'
22
import logger from './logger.js'
33

44
const COLLECTIONS_INDEX = process.env['COLLECTIONS_INDEX'] || 'collections'

src/lib/ingest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getItemCreated } from './database.js'
22
import { addItemLinks, addCollectionLinks } from './api.js'
3-
import { dbClient, createIndex } from './databaseClient.js'
3+
import { dbClient, createIndex } from './database-client.js'
44
import logger from './logger.js'
55
import { publishRecordToSns } from './sns.js'
66
import { isCollection, isItem } from './stac-utils.js'

tests/helpers/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { connect, createIndex } from '../../src/lib/databaseClient.js'
1+
import { connect, createIndex } from '../../src/lib/database-client.js'
22

33
/**
44
* @returns {Promise<void>}

0 commit comments

Comments
 (0)