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

Strip newline from client secret #1163

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion flytekit/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
from flytekit.configuration import internal as _internal
from flytekit.configuration.default_images import DefaultImages
from flytekit.configuration.file import ConfigEntry, ConfigFile, get_config_file, read_file_if_exists, set_if_exists
from flytekit.loggers import logger

PROJECT_PLACEHOLDER = "{{ registration.project }}"
DOMAIN_PLACEHOLDER = "{{ registration.domain }}"
Expand Down Expand Up @@ -336,10 +337,16 @@ def auto(cls, config_file: typing.Optional[typing.Union[str, ConfigFile]] = None
kwargs, "client_credentials_secret", _internal.Credentials.CLIENT_CREDENTIALS_SECRET.read(config_file)
)

client_credentials_secret = read_file_if_exists(
_internal.Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(config_file)
)
if client_credentials_secret and client_credentials_secret.endswith("\n"):
logger.info("Newline stripped from client secret")
client_credentials_secret = client_credentials_secret.strip()
kwargs = set_if_exists(
kwargs,
"client_credentials_secret",
read_file_if_exists(_internal.Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(config_file)),
client_credentials_secret,
)
kwargs = set_if_exists(kwargs, "scopes", _internal.Credentials.SCOPES.read(config_file))
kwargs = set_if_exists(kwargs, "auth_mode", _internal.Credentials.AUTH_MODE.read(config_file))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
admin:
# For GRPC endpoints you might want to use dns:///flyte.myexample.com
endpoint: dns:///flyte.mycorp.io
clientSecretLocation: ../tests/flytekit/unit/configuration/configs/fake_secret
clientSecretLocation: configs/fake_secret
authType: Pkce
insecure: true
clientId: propeller
Expand Down
17 changes: 15 additions & 2 deletions tests/flytekit/unit/configuration/test_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mock

from flytekit.configuration import get_config_file, read_file_if_exists
from flytekit.configuration import PlatformConfig, get_config_file, read_file_if_exists
from flytekit.configuration.internal import AWS, Credentials, Images


Expand Down Expand Up @@ -31,7 +31,20 @@ def test_client_secret_location():
os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs/creds_secret_location.yaml")
)
secret_location = Credentials.CLIENT_CREDENTIALS_SECRET_LOCATION.read(cfg)
assert secret_location == "../tests/flytekit/unit/configuration/configs/fake_secret"
assert secret_location == "configs/fake_secret"

# Modify the path to the secret inline
cfg._yaml_config["admin"]["clientSecretLocation"] = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "configs/fake_secret"
)

# Assert secret contains a newline
with open(cfg._yaml_config["admin"]["clientSecretLocation"], "rb") as f:
assert f.read().decode().endswith("\n") is True

# Assert that secret in platform config does not contain a newline
platform_cfg = PlatformConfig.auto(cfg)
assert platform_cfg.client_credentials_secret == "hello"


def test_read_file_if_exists():
Expand Down