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

secret management #104

Merged
merged 6 commits into from
Sep 9, 2024
Merged

secret management #104

merged 6 commits into from
Sep 9, 2024

Conversation

marjo-luc
Copy link
Member

@marjo-luc marjo-luc commented Aug 28, 2024

Added maap-py support for user secrets management. Users can now use the following four endpoints to get, add, and delete secrets:

maap.secrets.get_secrets()
maap.secrets.add_secret("my_secret_name", "my_secret_value")
maap.secrets.get_secret("my_secret_name")
maap.secrets.delete_secret("my_secret_name")

Closes #102 & 1048

@marjo-luc marjo-luc self-assigned this Aug 28, 2024
maap/Secrets.py Outdated
headers=self._api_header
)

return json.loads(response.text)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should just return a value and not a dict.
Returning a dict object can complicate users code using maag.py
For eg.

token = maap.Secrets().get_secret("name").get("name")

vs if we return just the value it could look like

token = maap.Secrets().get_secret("name")

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to support this.


def add_secret(self, secret_name=None, secret_value=None):
"""
Adds a secret. Secret name must be provided. Secret value may be null.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use-case of having a secret without a value ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly because an empty string is a valid value and I don't see a good reason placing additional constraints on this. I was also thinking of cases where users might need to have the secret parameter exist but not necessarily care about the value itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Saw this later, commented below.

@@ -81,6 +81,7 @@ def __init__(self, maap_host):
self.algorithm_build = self._get_api_endpoint("algorithm_build")
self.mas_algo = self._get_api_endpoint("mas_algo")
self.dps_job = self._get_api_endpoint("dps_job")
self.member_secrets = self._get_api_endpoint("member_secrets")
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this new config also been added to the maap_api_settings file as default config ? here https://github.com/MAAP-Project/maap-api-nasa/blob/main/api/settings.py#L119-L132

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with the existing member endpoint.

from maap.utils import requests_utils


class Secrets:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a section in the functional test to test adding, retrieving and deleting a secret?
https://github.com/MAAP-Project/maap-py/blob/master/test/functional_test.py

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is next on my to-do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented.

@marjo-luc marjo-luc requested a review from sujen1412 August 29, 2024 21:09
@marjo-luc marjo-luc marked this pull request as ready for review August 29, 2024 21:09
@marjo-luc marjo-luc requested a review from bsatoriu August 29, 2024 21:28
bsatoriu
bsatoriu previously approved these changes Aug 29, 2024
Copy link
Contributor

@bsatoriu bsatoriu left a comment

Choose a reason for hiding this comment

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

Looks good. Are we allowing empty secret values then? I'll need to update the API if so: https://github.com/MAAP-Project/maap-api-nasa/blob/develop/api/endpoints/members.py#L457-L459

@marjo-luc
Copy link
Member Author

I think we should allow empty strings for secret values, but not None. I just pushed a commit to ensure the secret_value is not None.

@sujen1412
Copy link
Contributor

sujen1412 commented Aug 29, 2024

I think we should allow empty strings for secret values, but not None. I just pushed a commit to ensure the secret_value is not None.

Can you provide an example where this would be used ? I dont think we should allow empty strings either, unless we have a good reason.

Edited
Saw your response above. Again, I dont think the usage of a presence of a secret without a value should be promoted. And why is it a secret in that case ? Since names of secrets are committed to public code anyway.
It could might as well be a boolean input parameter.

@marjo-luc
Copy link
Member Author

The good reason I see is that an empty string is a valid string so we shouldn't arbitrarily not allow that. But if that doesn't sway you, I'm fine updating the code to not allow empty strings as values.

@sujen1412
Copy link
Contributor

At present, since I do not see a convincing use for an empty string as a secret it does not sway me. Maybe in the future this need might arise.

I agree that an empty string is a valid string, but for secrets to me it implies an error on the user/systems part of not providing a valid (length > 0) value.

We do not want to promote our secrets database being used as a boolean/parameter flag store.

headers=self._api_header
)
logger.debug(response.text)
return json.loads(response.text)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be of type list or dict to match the doc string?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a list of dicts. I've updated the doc string to provide an example.

maap/Secrets.py Outdated
response = response.json()
return response["secret_value"]

logger.debug(response.text)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.debug(response.text)

We should not be logging secrets anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is logging the api response and not the secret value.

maap/Secrets.py Outdated
url = self._members_endpoint,
headers=self._api_header
)
logger.debug(response.text)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.debug(response.text)

Returns:
list: Secret names for a given user.
"""
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
try:
try:
logger.debug("Fetching all secrets")

Just more informative to log what function is being called than just logging response.text.

@marjo-luc marjo-luc requested a review from sujen1412 September 4, 2024 21:28
@marjo-luc marjo-luc merged commit 46754f6 into develop Sep 9, 2024
2 of 3 checks passed
@marjo-luc marjo-luc deleted the feature/secrets branch September 9, 2024 18:22
marjo-luc added a commit that referenced this pull request Sep 12, 2024
* Remove the need to track maap.cfg file (#93)

* Remove the need to track maap.cfg

* Fix merge issues

* Allow overriding of MAAP_API_HOST

* Split config url construction into functions

* Add test for config reader

* Add script to perform functional test of maap-py

* Construct api root url from provided maap host

* Apply suggestions from code review

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Apply suggestions from code review to update url handling

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Remove unused code and memoize get config function

* Update request utils to drop class and use methods

* Use new request utils and pass maap config object

* Update imports and url handling

* Simplify boolean self-signed for request utils

* Remove usage of os.path.join for constructing urls

* Fix variable name in exception message

* Remove incorrect import

* Update functional tests

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added pagination to listJobs endpoint

* change request

* Issues/95: Add CICD pipeline (#101)

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Fetch full repo in checkout for sonar analysis

* tweak pr template wording

* /version 4.0.1a0

* /version 4.1.0a1

* added more query params (#98)

* added more query params

* added get_job_details flag

* cleanup

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added docstring | updated param handling

* review updates

* review updates

* renamed file

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* /version 4.1.0a2

* secret management (#104)

* wip

* cleanup

* updated get_secret endpoint to return value

* added tests for secrets management

* updated error handling | added logging

* review comments

* /version 4.1.0a3

* /version 4.2.0a0

* added changelog entry

* /version 4.1.0rc1

---------

Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>
grallewellyn added a commit that referenced this pull request Feb 26, 2025
* Release/4.1.0 (#106)

* Remove the need to track maap.cfg file (#93)

* Remove the need to track maap.cfg

* Fix merge issues

* Allow overriding of MAAP_API_HOST

* Split config url construction into functions

* Add test for config reader

* Add script to perform functional test of maap-py

* Construct api root url from provided maap host

* Apply suggestions from code review

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Apply suggestions from code review to update url handling

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Remove unused code and memoize get config function

* Update request utils to drop class and use methods

* Use new request utils and pass maap config object

* Update imports and url handling

* Simplify boolean self-signed for request utils

* Remove usage of os.path.join for constructing urls

* Fix variable name in exception message

* Remove incorrect import

* Update functional tests

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added pagination to listJobs endpoint

* change request

* Issues/95: Add CICD pipeline (#101)

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Fetch full repo in checkout for sonar analysis

* tweak pr template wording

* /version 4.0.1a0

* /version 4.1.0a1

* added more query params (#98)

* added more query params

* added get_job_details flag

* cleanup

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added docstring | updated param handling

* review updates

* review updates

* renamed file

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* /version 4.1.0a2

* secret management (#104)

* wip

* cleanup

* updated get_secret endpoint to return value

* added tests for secrets management

* updated error handling | added logging

* review comments

* /version 4.1.0a3

* /version 4.2.0a0

* added changelog entry

* /version 4.1.0rc1

---------

Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>

* /version 4.1.0

---------

Co-authored-by: Marjorie Lucas <47004511+marjo-luc@users.noreply.github.com>
Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>
grallewellyn added a commit that referenced this pull request Feb 26, 2025
* Release/4.1.0 (#106)

* Remove the need to track maap.cfg file (#93)

* Remove the need to track maap.cfg

* Fix merge issues

* Allow overriding of MAAP_API_HOST

* Split config url construction into functions

* Add test for config reader

* Add script to perform functional test of maap-py

* Construct api root url from provided maap host

* Apply suggestions from code review

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Apply suggestions from code review to update url handling

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Remove unused code and memoize get config function

* Update request utils to drop class and use methods

* Use new request utils and pass maap config object

* Update imports and url handling

* Simplify boolean self-signed for request utils

* Remove usage of os.path.join for constructing urls

* Fix variable name in exception message

* Remove incorrect import

* Update functional tests

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added pagination to listJobs endpoint

* change request

* Issues/95: Add CICD pipeline (#101)

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Fetch full repo in checkout for sonar analysis

* tweak pr template wording

* /version 4.0.1a0

* /version 4.1.0a1

* added more query params (#98)

* added more query params

* added get_job_details flag

* cleanup

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added docstring | updated param handling

* review updates

* review updates

* renamed file

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* /version 4.1.0a2

* secret management (#104)

* wip

* cleanup

* updated get_secret endpoint to return value

* added tests for secrets management

* updated error handling | added logging

* review comments

* /version 4.1.0a3

* /version 4.2.0a0

* added changelog entry

* /version 4.1.0rc1

---------

Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>

* /version 4.1.0

---------

Co-authored-by: Marjorie Lucas <47004511+marjo-luc@users.noreply.github.com>
Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>
frankinspace added a commit that referenced this pull request Feb 26, 2025
rebased develop onto master and tweaked versions

rebased develop onto master and tweaked versions

Resolve conflicts (#112)

* Release/4.1.0 (#106)

* Remove the need to track maap.cfg file (#93)

* Remove the need to track maap.cfg

* Fix merge issues

* Allow overriding of MAAP_API_HOST

* Split config url construction into functions

* Add test for config reader

* Add script to perform functional test of maap-py

* Construct api root url from provided maap host

* Apply suggestions from code review

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Apply suggestions from code review to update url handling

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Remove unused code and memoize get config function

* Update request utils to drop class and use methods

* Use new request utils and pass maap config object

* Update imports and url handling

* Simplify boolean self-signed for request utils

* Remove usage of os.path.join for constructing urls

* Fix variable name in exception message

* Remove incorrect import

* Update functional tests

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added pagination to listJobs endpoint

* change request

* Issues/95: Add CICD pipeline (#101)

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Fetch full repo in checkout for sonar analysis

* tweak pr template wording

* /version 4.0.1a0

* /version 4.1.0a1

* added more query params (#98)

* added more query params

* added get_job_details flag

* cleanup

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added docstring | updated param handling

* review updates

* review updates

* renamed file

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* /version 4.1.0a2

* secret management (#104)

* wip

* cleanup

* updated get_secret endpoint to return value

* added tests for secrets management

* updated error handling | added logging

* review comments

* /version 4.1.0a3

* /version 4.2.0a0

* added changelog entry

* /version 4.1.0rc1

---------

Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>

* /version 4.1.0

---------

Co-authored-by: Marjorie Lucas <47004511+marjo-luc@users.noreply.github.com>
Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>

Resolve conflicts (#111)

* Release/4.1.0 (#106)

* Remove the need to track maap.cfg file (#93)

* Remove the need to track maap.cfg

* Fix merge issues

* Allow overriding of MAAP_API_HOST

* Split config url construction into functions

* Add test for config reader

* Add script to perform functional test of maap-py

* Construct api root url from provided maap host

* Apply suggestions from code review

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Apply suggestions from code review to update url handling

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Remove unused code and memoize get config function

* Update request utils to drop class and use methods

* Use new request utils and pass maap config object

* Update imports and url handling

* Simplify boolean self-signed for request utils

* Remove usage of os.path.join for constructing urls

* Fix variable name in exception message

* Remove incorrect import

* Update functional tests

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added pagination to listJobs endpoint

* change request

* Issues/95: Add CICD pipeline (#101)

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Setup CICD

* Fetch full repo in checkout for sonar analysis

* tweak pr template wording

* /version 4.0.1a0

* /version 4.1.0a1

* added more query params (#98)

* added more query params

* added get_job_details flag

* cleanup

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* Update maap/maap.py

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* added docstring | updated param handling

* review updates

* review updates

* renamed file

---------

Co-authored-by: Chuck Daniels <chuck@developmentseed.org>

* /version 4.1.0a2

* secret management (#104)

* wip

* cleanup

* updated get_secret endpoint to return value

* added tests for secrets management

* updated error handling | added logging

* review comments

* /version 4.1.0a3

* /version 4.2.0a0

* added changelog entry

* /version 4.1.0rc1

---------

Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>

* /version 4.1.0

---------

Co-authored-by: Marjorie Lucas <47004511+marjo-luc@users.noreply.github.com>
Co-authored-by: Sujen Shah <sujen1412@users.noreply.github.com>
Co-authored-by: Chuck Daniels <chuck@developmentseed.org>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
Co-authored-by: frankinspace <frankinspace@users.noreply.github.com>
Co-authored-by: marjo-luc <marjo-luc@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants