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

[dy] Support reading authentication settings from AWS secrets manager #4674

Conversation

dy46
Copy link
Contributor

@dy46 dy46 commented Feb 28, 2024

Description

This PR adds support for reading settings from AWS secrets manager. Only some of the existing settings have been moved to using the new Settings class. Most server settings that are not secrets are still being directly read from environment variables.

In order to set the settings backend, the user will need to add a section to the project metadata. Here is an example to set the setting backend to AWS secrets manager:

settings_backend:
  backend_type: aws_secrets_manager
  prefix: default_repo/settings/

This PR also adds an observer to the project metadata file so that if there are any updates to that file, the settings backend can be updated.

How Has This Been Tested?

  • Tested with AWS secrets manager backend and reading settings
  • Tested existing auth methods
    • GHE
    • Gitlab
    • Bitbucket
    • Git
    • Okta
    • Google
    • AD
    • OIDC

Checklist

  • The PR is tagged with proper labels (bug, enhancement, feature, documentation)
  • I have performed a self-review of my own code
  • I have added unit tests that prove my fix is effective or that my feature works
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • If new documentation has been added, relative paths have been added to the appropriate section of docs/mint.json

cc:

@dy46 dy46 added the enhancement Polish or UX improvements label Feb 28, 2024
@@ -300,6 +304,13 @@ def set_project_uuid_from_metadata() -> None:
project_uuid = config.get('project_uuid')


def update_settings_on_metadata_change() -> None:
global project_uuid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the project_uuid used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops i'll remove that

except ClientError as error:
if error.response['Error']['Code'] == 'ResourceNotFoundException':
return None
raise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are other possible errors? do we not fall back to env variables for those errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. i'll log an error and return None

self.client = boto3.client('secretsmanager')
self.prefix = kwargs.get('prefix', '')

def _get(self, key: str, **kwargs) -> Optional[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also allow user to configure whether to use AWS secret cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, i'll add that

@dy46 dy46 force-pushed the 4598-storing-git-secrets-in-aws-secrets-manager-instead-of-environment-variables branch from e4050e9 to 438fdf5 Compare March 1, 2024 20:19
@dy46 dy46 changed the title [WIP][dy] Support reading authentication settings from AWS secrets manager [dy] Support reading authentication settings from AWS secrets manager Mar 5, 2024
@dy46
Copy link
Contributor Author

dy46 commented Mar 5, 2024

@wangxiaoyou1993 PTAL

@dy46 dy46 force-pushed the 4598-storing-git-secrets-in-aws-secrets-manager-instead-of-environment-variables branch from 438fdf5 to ececb04 Compare March 8, 2024 01:03
@wangxiaoyou1993
Copy link
Member

wangxiaoyou1993 commented Mar 8, 2024

Have you tested with all those different authentication methods?

@wangxiaoyou1993
Copy link
Member

can you also update the doc?

@dy46 dy46 force-pushed the 4598-storing-git-secrets-in-aws-secrets-manager-instead-of-environment-variables branch from b170fd7 to eb338ad Compare March 8, 2024 19:30
@dy46 dy46 merged commit c6ca6ef into master Mar 8, 2024
9 checks passed
@dy46 dy46 deleted the 4598-storing-git-secrets-in-aws-secrets-manager-instead-of-environment-variables branch March 8, 2024 20:11
@wangxiaoyou1993 wangxiaoyou1993 mentioned this pull request Mar 13, 2024
15 tasks
oonyoontong pushed a commit to bunker-tech/mage-ai that referenced this pull request May 2, 2024
…mage-ai#4674)

* [dy] Update settings

* [dy] Update

* [dy] Update again

* [dy] Update once more

* [dy] Fix test

* [dy] Fix session test

* [dy] Fix session test again

* [dy] Fix test

* [dy] Fix test 2

* [dy] Address comments

* [dy] Update

* [dy] Rebase

* [dy] Update comments

* [dy] Update docs

* [dy] Move all git settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Polish or UX improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storing git secrets in AWS secrets manager instead of environment variables
2 participants