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

External Environment Variables overwrite credentials in code #3

Open
joergrech opened this issue Aug 14, 2021 · 1 comment
Open

External Environment Variables overwrite credentials in code #3

joergrech opened this issue Aug 14, 2021 · 1 comment

Comments

@joergrech
Copy link

While this might be intentional I have the problem that AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from my environment are overwriting the credentials stated in the sourcecode. Is there an option to "force" credentials from the code?

Here is my code:

const { Client } = require('@elastic/elasticsearch')
// const elasticsearch = require('@elastic/elasticsearch')
const { createConnector } = require('aws-elasticsearch-js')

const domain = process.env.ES_HOST
const region = process.env.AWS_DEFAULT_REGION
const accessKeyId = process.env.AWS_ACCESS_KEY_ID
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY

// heads up: this is called on every request
const getCreds = (cb) => {
	// load creds from somewhere...
	const credentials = { accessKeyId, secretAccessKey }
	// or credentials = { sessionToken }
	const err = null // if you give an error, the request will abort
	cb(err, credentials)
}

export const es = new Client({
	node: domain,
	Connection: createConnector({ region, getCreds }),
})
@TheDeveloper
Copy link
Contributor

Hi @joergrech looks like your code there is still supplying the creds from the environment itself rather than a hard-code override. e.g.

const accessKeyId = process.env.AWS_ACCESS_KEY_ID
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY

is taking access keys from env.

If you wish to override in the code you can set these to something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants