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

Secrets Manager and secrets specification for tasks #406

Merged
merged 29 commits into from
Mar 23, 2021
Merged

Secrets Manager and secrets specification for tasks #406

merged 29 commits into from
Mar 23, 2021

Conversation

kumare3
Copy link
Contributor

@kumare3 kumare3 commented Mar 4, 2021

Signed-off-by: Ketan Umare [email protected]

TL;DR

[wip]Pending adding secrets to flyteidl tasktemplate
This enables every python task or a python plugin to request for secrets and the secrets are retrieved in a standardized way during the execution using the flytekit context's new SecretsManager.

SecretsManager will resolve the secrets by first looking at Env Var and then at the configured secrets directory.
Rules:

  • the env var should be uppercased and should be prefixed with the configured prefix. Default will be FSEC{secret_key}
  • If env var is not found, then Secretsmanager will look for a file under {default_dir}/{prefix}{secret_key}
    default_dir is set to /etc/secrets (can be overriden using an env var)
    prefix is set to ""

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

Tracking Issue

flyteorg/flyte#796
flyteorg/flyte#800

@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #406 (93afa0e) into master (c7ff1e8) will increase coverage by 0.09%.
The diff coverage is 94.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #406      +/-   ##
==========================================
+ Coverage   83.98%   84.07%   +0.09%     
==========================================
  Files         337      340       +3     
  Lines       24955    25166     +211     
  Branches     2028     2048      +20     
==========================================
+ Hits        20959    21159     +200     
- Misses       3441     3449       +8     
- Partials      555      558       +3     
Impacted Files Coverage Δ
flytekit/common/translator.py 90.08% <ø> (ø)
flytekit/models/security.py 86.84% <86.84%> (ø)
tests/flytekit/unit/core/test_type_hints.py 95.54% <93.75%> (-0.06%) ⬇️
flytekit/__init__.py 100.00% <100.00%> (ø)
flytekit/common/tasks/sdk_runnable.py 84.21% <100.00%> (+2.23%) ⬆️
flytekit/common/tasks/task.py 62.89% <100.00%> (ø)
flytekit/configuration/secrets.py 100.00% <100.00%> (ø)
flytekit/core/base_task.py 84.92% <100.00%> (+0.38%) ⬆️
flytekit/core/python_auto_container.py 82.14% <100.00%> (+1.19%) ⬆️
flytekit/core/task.py 87.80% <100.00%> (+0.30%) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7ff1e8...93afa0e. Read the comment docs.

kumare3 and others added 8 commits March 10, 2021 13:03
wild-endeavor
wild-endeavor previously approved these changes Mar 11, 2021
Copy link
Contributor

@wild-endeavor wild-endeavor left a comment

Choose a reason for hiding this comment

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

I feel like the user interface for secrets will evolve as people start using it (and maybe possibly as we add an authz layer). Not sure how exactly though.



def test_secrets():
@task(secret_requests=["my_secret"])
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 Secret("my_secret")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aah yes it should be, and thus in this case maybe i should do a check on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@kumare3 kumare3 changed the title [wip] Secrets Manager and secrets specification for tasks Secrets Manager and secrets specification for tasks Mar 11, 2021
@@ -304,16 +311,21 @@ def __init__(
name: str,
task_config: T,
interface: Optional[Interface] = None,
environment=None,
task_type_version=0,
environment: Optional[Dict[str, str]] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we removing task_type_version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not removing, i am keeping it so that, if something is declared in the base, it does not need to repeated at every class layer - **kwargs should take care of it?

return v
if os.path.exists(fpath):
with open(fpath, "r") as f:
return f.read()
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a strip() here in case of newlines??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

class MountType(Enum):
ENV_VAR = _sec.Secret.MountType.ENV_VAR
"""
Use this if the secret can be injected as an environment variable. Usually works for symmetric keys, passwords etc
Copy link
Contributor

Choose a reason for hiding this comment

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

just a question: is this way of using multi-line strings as in-line comments a convention, or important for sphinx docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats what I understand, that sphinx will convert this to a doc-string on the constant

EngHabu
EngHabu previously approved these changes Mar 22, 2021
The resolution order is
- Try env var first. The env var should have the configuration.SECRETS_ENV_PREFIX. The env var will be all upper
cased
- If not then try the file where the name matches the key as lower case in configuration.SECRETS_DEFAULT_DIR
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be updated right? it will be <DEFAULT_DIR>/Group/<PREFIX>Key

FLYTE_SECRETS_ENV_PREFIX variable
"""

SECRETS_DEFAULT_DIR = _common_config.FlyteStringConfigurationEntry("secrets", "default_dir", default="/etc/secrets")
Copy link
Collaborator

Choose a reason for hiding this comment

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

path.join?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for /etc/secrets you mean?

group: str
key: str
group_version: Optional[str] = None
mount_requirement: MountType = MountType.ENV_VAR
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be ANY?

Copy link
Contributor Author

@kumare3 kumare3 Mar 22, 2021

Choose a reason for hiding this comment

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

ANY what? - for MountType?

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
wild-endeavor
wild-endeavor previously approved these changes Mar 22, 2021
wild-endeavor
wild-endeavor previously approved these changes Mar 22, 2021
"""

SECRETS_DEFAULT_DIR = _common_config.FlyteStringConfigurationEntry(
"secrets", "default_dir", default=os.path.join("etc", "secrets")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"secrets", "default_dir", default=os.path.join("etc", "secrets")
"secrets", "default_dir", default=os.path.join(os.path.sep, "etc", "secrets")

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
@kumare3 kumare3 merged commit 74fdf44 into master Mar 23, 2021
max-hoffman pushed a commit to dolthub/flytekit that referenced this pull request May 11, 2021
* Secrets Manager and secrets specification for tasks

Signed-off-by: Ketan Umare <[email protected]>

* Updated setup.py

Signed-off-by: Ketan Umare <[email protected]>

* requirements updated

Signed-off-by: Ketan Umare <[email protected]>

* Unit tests and models for security context

Signed-off-by: Ketan Umare <[email protected]>

* Updated test

Signed-off-by: Ketan Umare <[email protected]>

* Tests and exposed methods

Signed-off-by: Ketan Umare <[email protected]>

* SecretManager available in testing

Signed-off-by: Ketan Umare <[email protected]>

* requirements updated

Signed-off-by: Ketan Umare <[email protected]>

* ran make requirements

Signed-off-by: wild-endeavor <[email protected]>

* Fixed test

Signed-off-by: Ketan Umare <[email protected]>

* Fixed test and check that secrets are not bare strings

Signed-off-by: Ketan Umare <[email protected]>

* Updated to use new FlyteIDL

Signed-off-by: Ketan Umare <[email protected]>

* Updated group secrets

Signed-off-by: Ketan Umare <[email protected]>

* Updated secrets with group concat logic

Signed-off-by: Ketan Umare <[email protected]>

* wip

Signed-off-by: Ketan Umare <[email protected]>

* Updated to flyteidl 0.18.24. Secrets with version

Signed-off-by: Ketan Umare <[email protected]>

* Updated secrets, to always require group

Signed-off-by: Ketan Umare <[email protected]>

* addressed comments

Signed-off-by: Ketan Umare <[email protected]>

* updated to address comments

Signed-off-by: Ketan Umare <[email protected]>

* updated linter fix

Signed-off-by: Ketan Umare <[email protected]>

* Updated to address more comments

Signed-off-by: Ketan Umare <[email protected]>

* remove faulty test

Signed-off-by: Ketan Umare <[email protected]>

* update os.sep

Signed-off-by: Ketan Umare <[email protected]>

Co-authored-by: wild-endeavor <[email protected]>
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.

4 participants