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

Add url signing as an alternative to forbid direct access #524

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/catalog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ Whether a particular catalog entry supports direct or proxied access is determin
- ``force``: Force all clients to access the data directly. If they do not have the required driver, an exception will
be raised.

- ``signed``: Clients access the data directly, but are provided with a temporary URLs. This enables authentication
systems to still be effective without requiring the server to load all the data itself. Similar to ``force`` this
will raise an error if the client doesn't have the needed driver.

Note that when the client is loading a data source via direct access, the catalog server will need to send the driver
arguments to the client. Do not include sensitive credentials in a data source that allows direct access.

Expand Down
25 changes: 23 additions & 2 deletions intake/cli/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tornado.gen
import tornado.ioloop
import tornado.web
from fsspec import get_fs_token_paths

from intake.config import conf
from intake.container import serializer
Expand Down Expand Up @@ -239,7 +240,7 @@ def post(self):
action = request['action']
head = self.request.headers
logger.debug('Source POST: %s' % request)

if action == 'search':
if 'source-id' in head:
cat = self._cache.get(head['source-id'])
Expand Down Expand Up @@ -319,7 +320,27 @@ def post(self):
metadata=source.metadata))
self.write(msgpack.packb(response, **pack_kwargs))
self.finish()
elif direct_access == 'force' and not client_has_plugin:
elif direct_access == 'signed' and client_has_plugin:
response = open_desc
user_parameters['plugin'] = plugin_name
response['args'] = entry._entry._create_open_args(user_parameters)[1]
response_args = response['args']
fs, *_ = get_fs_token_paths(response_args['urlpath'],
storage_options=response_args.get('storage_options', {}))
Copy link
Member

Choose a reason for hiding this comment

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

The source storage options should be rewritten to whatever it takes to be able to read the HTTP URL, perhaps just {}

try:
response_args['urlpath'] = fs.sign(response_args['urlpath'],
Copy link
Member

Choose a reason for hiding this comment

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

Should use the output paths from above, since this might have expanded globs into multiple concrete files

Copy link
Member

Choose a reason for hiding this comment

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

i.e., this can be a list of signed URLs

expiration=response_args.get('expiration', 100))
except NotImplementedError:
msg = 'signed urls not supported for the filesystem associated with "%s"' % entry_name
raise tornado.web.HTTPError(status_code=400, log_message=msg,
reason=msg)
except Exception as e:
msg = 'server could not create signed url for "%s"' % entry_name
raise tornado.web.HTTPError(status_code=400, log_message=msg,
reason=msg)
self.write(msgpack.packb(response, **pack_kwargs))
self.finish()
elif (direct_access in {'signed', 'force'}) and not client_has_plugin:
msg = 'client must have plugin "%s" to access source "%s"' \
'' % (plugin_name, entry_name)
raise tornado.web.HTTPError(status_code=400, log_message=msg,
Expand Down