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

adds authentication for registering tasks, workflows, and launch plans #56

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 18 additions & 2 deletions flytekit/clients/raw.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import
from grpc import insecure_channel as _insecure_channel, secure_channel as _secure_channel, RpcError as _RpcError, \
StatusCode as _GrpcStatusCode, ssl_channel_credentials as _ssl_channel_credentials
StatusCode as _GrpcStatusCode, ssl_channel_credentials as _ssl_channel_credentials, access_token_call_credentials as _access_token_call_credentials, composite_channel_credentials as _composite_channel_credentials
from flyteidl.service import admin_pb2_grpc as _admin_service
from flytekit.common.exceptions import user as _user_exceptions
import six as _six
import requests
import getpass


def _handle_rpc_error(fn):
Expand All @@ -26,7 +28,7 @@ class RawSynchronousFlyteClient(object):
be explicit as opposed to inferred from the environment or a configuration file.
"""

def __init__(self, url, insecure=False, credentials=None, options=None):
def __init__(self, url, insecure=False, credentials=None, options=None, username=None, password=None):
"""
Initializes a gRPC channel to the given Flyte Admin service.

Expand All @@ -38,6 +40,20 @@ def __init__(self, url, insecure=False, credentials=None, options=None):
"""
self._channel = None

if username:
# do not allow sending credentials insecurely
insecure = False
if not password:
password = getpass.getpass()
login_endpoint = "https://{}/api/v1/login/{}".format(url, username)
response = requests.put(login_endpoint, json={'password': password})
if response.status_code != 200:
raise Exception("login failed: {}".format(response.text))
login = response.json()
access_token = login['token']
call_credentials = _access_token_call_credentials(access_token)
credentials = _composite_channel_credentials(_ssl_channel_credentials(), call_credentials)

# TODO: Revert all the for loops below
if insecure:
self._channel = _insecure_channel(url, options=list((options or {}).items()))
Expand Down
2 changes: 2 additions & 0 deletions flytekit/configuration/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

URL = _config_common.FlyteRequiredStringConfigurationEntry('platform', 'url')
INSECURE = _config_common.FlyteBoolConfigurationEntry('platform', 'insecure', default=False)
USERNAME = _config_common.FlyteStringConfigurationEntry('platform', 'username')
PASSWORD = _config_common.FlyteStringConfigurationEntry('platform', 'password')
CLOUD_PROVIDER = _config_common.FlyteStringConfigurationEntry(
'platform', 'cloud_provider', default=_constants.CloudProvider.AWS
)
18 changes: 15 additions & 3 deletions flytekit/engines/flyte/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ def fetch_workflow(self, workflow_id):
class FlyteLaunchPlan(_common_engine.BaseLaunchPlanExecutor):

def register(self, identifier):
client = _FlyteClientManager(_platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client
client = _FlyteClientManager(
_platform_config.URL.get(),
username=_platform_config.USERNAME.get(),
password=_platform_config.PASSWORD.get(),
insecure=_platform_config.INSECURE.get()).client
try:
client.create_launch_plan(
identifier,
Expand Down Expand Up @@ -214,7 +218,11 @@ def update(self, identifier, state):
class FlyteWorkflow(_common_engine.BaseWorkflowExecutor):

def register(self, identifier):
client = _FlyteClientManager(_platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client
client = _FlyteClientManager(
_platform_config.URL.get(),
username=_platform_config.USERNAME.get(),
password=_platform_config.PASSWORD.get(),
insecure=_platform_config.INSECURE.get()).client
try:
return client.create_workflow(
identifier,
Expand All @@ -227,7 +235,11 @@ def register(self, identifier):
class FlyteTask(_common_engine.BaseTaskExecutor):

def register(self, identifier):
client = _FlyteClientManager(_platform_config.URL.get(), insecure=_platform_config.INSECURE.get()).client
client = _FlyteClientManager(
_platform_config.URL.get(),
username=_platform_config.USERNAME.get(),
password=_platform_config.PASSWORD.get(),
insecure=_platform_config.INSECURE.get()).client
try:
client.create_task(
identifier,
Expand Down