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

Support secrets manager JSON secrets #342

Open
agabeev-godaddy opened this issue Nov 11, 2022 · 4 comments
Open

Support secrets manager JSON secrets #342

agabeev-godaddy opened this issue Nov 11, 2022 · 4 comments
Labels
8.10-candidate aws-λ-extension AWS Lambda Extension community Issues and PRs created by the community enhancement New feature or request triage Issues and PRs that need to be triaged

Comments

@agabeev-godaddy
Copy link

Is your feature request related to a problem? Please describe.
Common way to store secrets in AWS secrets manager is in a JSON format.
However, current implementation supports only plain string value when processing ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_ID environment variable:
https://github.com/elastic/apm-aws-lambda/blob/main/app/aws.go#L70

It may be useful to support json secrets as well.

Describe the solution you'd like
We may consider to introduce second level environment variables, like
ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_JSON_FIELD
ELASTIC_APM_SECRETS_MANAGER_API_KEY_JSON_FIELD

If these env variables are set, prior to using secret value, we may attempt to parse string secret value into unstructured JSON map and retrieve token/apikey from map based on provided json field, before this lines:
https://github.com/elastic/apm-aws-lambda/blob/main/app/aws.go#L41
https://github.com/elastic/apm-aws-lambda/blob/main/app/aws.go#L52

Describe alternatives you've considered

  1. flattening and copying secret value as plain text in the secrets manager - unfortunately it does not work well for our use case.

Additional context
Existing doc: https://www.elastic.co/guide/en/apm/lambda/current/aws-lambda-secrets-manager.html

@agabeev-godaddy agabeev-godaddy added the enhancement New feature or request label Nov 11, 2022
@github-actions github-actions bot added aws-λ-extension AWS Lambda Extension community Issues and PRs created by the community triage Issues and PRs that need to be triaged labels Nov 11, 2022
@axw
Copy link
Member

axw commented Nov 28, 2022

@agabeev-godaddy thanks for opening the issue. Sounds reasonable to accept JSON, particularly since AWS recommends encoding secrets as JSON in their docs.

We may consider to introduce second level environment variables, like
ELASTIC_APM_SECRETS_MANAGER_SECRET_TOKEN_JSON_FIELD
ELASTIC_APM_SECRETS_MANAGER_API_KEY_JSON_FIELD

Is this important for your use case? Would it be acceptable if we were to expect well-defined, non-configurable, keys like "secret_token" and "api_key"? As a user, you would specify the secret ID, and its contents would have a well-defined format like:

{
    "secret_token": "<secret token>"
}

This would be similar to how AWS services expect JSON secrets with a specific JSON structure: https://docs.aws.amazon.com/secretsmanager/latest/userguide/reference_secret_json_structure.html

@agabeev-godaddy
Copy link
Author

Hi @axw , sorry for late reply,

Can we use well-defined keys as fallback value, like 'secert_token' / 'api_key', but still allow to override?
Do you have concern regarding parsing raw map structure?
Also if will be nice, if parser is tolerant to additional fields in json.

Thanks,
Artyom

@axw
Copy link
Member

axw commented Jan 24, 2023

Can we use well-defined keys as fallback value, like 'secert_token' / 'api_key', but still allow to override?

It's technically possible, but I'd like to understand why this is important. Could you please describe your use case(s) for overriding the keys?

Do you have concern regarding parsing raw map structure?

No - I'd just like to keep things simple, and follow the existing approach used by AWS services.

Also if will be nice, if parser is tolerant to additional fields in json.

Definitely 👍

@agabeev-godaddy
Copy link
Author

@axw , the reason behind is that there is a process which manages different ESSP installations and different keys are already in place. It may be hard to adjust, but I think it is manageable.

However, we can go with approach you are suggested if we support additional fields in json.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.10-candidate aws-λ-extension AWS Lambda Extension community Issues and PRs created by the community enhancement New feature or request triage Issues and PRs that need to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants