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

feat(download-auth): use arborist for data download check #606

Merged
merged 35 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7fa5a3f
feat(sleek-jwts): remove policies
Apr 2, 2019
6fca959
feat(sleek-jwts): add migration to drop policies
Apr 2, 2019
45f9b95
feat(download-auth): use arborist for data download check
Apr 3, 2019
b3734dc
feat(download-auth): userdatamodel pin
Apr 3, 2019
bbbfdb1
feat(sleek-jwts): remove policy from models
Apr 3, 2019
d21254a
feat(sleek-jwts): remove unused policies endpoints
Apr 5, 2019
644910c
feat(download-auth): userdatamodel pin
Apr 3, 2019
542db3a
Merge branch 'feat/sleek-jwts' into feat/download-auth
Apr 5, 2019
c96f8e3
feat(download-auth): remove unused imports
Apr 5, 2019
aafa11a
feat(download-auth): fix drop commands
Apr 5, 2019
c7424ab
feat(download-auth): remove more policies references
Apr 5, 2019
8e656d6
feat(download-auth): add test for download endpoint using rbac
Apr 11, 2019
b26eb62
feat(download-auth): correct methods
Apr 12, 2019
3c5158c
feat(download-auth): run formatter
Apr 12, 2019
fe48f1c
feat(arborist-sync): update sync for new RBAC
Apr 9, 2019
5c431a0
feat(arborist-sync): CRFs, add group create
Apr 25, 2019
2830ca0
Update client.py
Avantol13 Apr 25, 2019
8e2ea49
feat(arborist-sync): add arborist client checks
Apr 25, 2019
129934b
feat(download-auth): add new userdatamodel pin
Apr 26, 2019
6dc8851
feat(download-auth): add migration
Apr 26, 2019
8223657
feat(download-auth): fix param in arborist request
Apr 26, 2019
3ff6fee
Merge branch 'feat/arborist' into feat/arborist-sync
Avantol13 May 6, 2019
b9ec596
feat(arborist-sync): fix user handling in sync
May 6, 2019
f6dcf97
feat(arborist-sync): fix user handling in sync
May 6, 2019
8fc3546
Merge branch 'feat/arborist' into feat/arborist-sync
Avantol13 May 6, 2019
43dc1d4
Merge branch 'feat/arborist-sync' of github.com:uc-cdis/fence into fe…
Avantol13 May 6, 2019
ecf0075
feat(download-auth): add migration
Apr 26, 2019
d294f60
fix(imports): add missing import for syncing
Avantol13 May 6, 2019
c7244de
fix(fence-create): correctly pass in ArboristClient
Avantol13 May 6, 2019
59396f0
feat(arborist-sync): overwrite policy if necessary
May 6, 2019
cce4ea9
feat(arborist-sync): clean up logging
May 6, 2019
35bc481
Merge branch 'feat/arborist-sync' into feat/download-auth
May 7, 2019
135c17c
feat(download-auth): tmp userdatamodel pin
May 7, 2019
fafe1e2
feat(arborist-sync): change to * permission
May 7, 2019
3ecb1ee
feat(arborist-sync): support user policy list
May 7, 2019
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
13 changes: 8 additions & 5 deletions bin/fence-create
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import os
import sys
import logging

from cdislogging import get_logger

from fence.jwt import keys
from fence.config import config
from fence.scripting.fence_create import (
Expand Down Expand Up @@ -95,9 +97,7 @@ def parse_arguments():
default=False,
)
client_create.add_argument(
"--policies",
help="which RBAC policies are granted to this client",
nargs="*",
"--policies", help="which RBAC policies are granted to this client", nargs="*"
)

client_modify = subparsers.add_parser("client-modify")
Expand All @@ -123,7 +123,7 @@ def parse_arguments():
client_modify.add_argument(
"--policies",
help="which RBAC policies are granted to this client; if given, "
"previous policies will be revoked",
"previous policies will be revoked",
nargs="*",
)

Expand Down Expand Up @@ -354,7 +354,10 @@ def main():
)
arborist = None
if args.arborist:
arborist = ArboristClient(arborist_base_url=args.arborist)
arborist = ArboristClient(
arborist_base_url=args.arborist,
logger=get_logger("user_syncer.arborist_client"),
)

if args.action == "create":
yaml_input = args.__dict__["yaml-input"]
Expand Down
8 changes: 3 additions & 5 deletions fence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from fence.rbac.client import ArboristClient
from fence.resources.aws.boto_manager import BotoManager
from fence.resources.openid.google_oauth2 import GoogleOauth2Client as GoogleClient
from fence.resources.openid.microsoft_oauth2 import MicrosoftOauth2Client as MicrosoftClient
from fence.resources.openid.microsoft_oauth2 import (
MicrosoftOauth2Client as MicrosoftClient
)
from fence.resources.openid.orcid_oauth2 import OrcidOauth2Client as ORCIDClient
from fence.resources.storage import StorageManager
from fence.resources.user.user_session import UserSessionInterface
Expand All @@ -27,7 +29,6 @@
import fence.blueprints.data
import fence.blueprints.login
import fence.blueprints.oauth2
import fence.blueprints.rbac
import fence.blueprints.misc
import fence.blueprints.storage_creds
import fence.blueprints.user
Expand Down Expand Up @@ -102,9 +103,6 @@ def app_register_blueprints(app):
google_blueprint = fence.blueprints.google.make_google_blueprint()
app.register_blueprint(google_blueprint, url_prefix="/google")

if config.get("ARBORIST"):
app.register_blueprint(fence.blueprints.rbac.blueprint, url_prefix="/rbac")

fence.blueprints.misc.register_misc(app)

@app.route("/")
Expand Down
19 changes: 19 additions & 0 deletions fence/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@
logger = get_logger(__name__)


def get_jwt():
"""
Return the user's JWT from authorization header. Requires flask application context.

Raises:
- Unauthorized, if header is missing or not in the correct format
"""
header = flask.request.headers.get("Authorization")
if not header:
raise Unauthorized("missing authorization header")
try:
bearer, token = header.split(" ")
except ValueError:
raise Unauthorized("authorization header not in expected format")
if bearer.lower() != "bearer":
raise Unauthorized("expected bearer token in auth header")
return token


def build_redirect_url(hostname, path):
"""
Compute a redirect given a hostname and next path where
Expand Down
25 changes: 25 additions & 0 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import requests

from fence.auth import (
get_jwt,
has_oauth,
current_token,
login_required,
set_current_token,
Expand Down Expand Up @@ -343,6 +345,18 @@ def set_acls(self):
else:
raise Unauthorized("This file is not accessible")

def check_rbac(self, action):
if not self.index_document.get("rbac"):
raise ValueError("index record missing `rbac`")
request = {
"user": {"token": get_jwt()},
"request": {
"resource": self.index_document["rbac"],
"action": {"service": "fence", "method": action},
},
}
return flask.current_app.arborist.auth_request(request)

@cached_property
def metadata(self):
return self.index_document.get("metadata", {})
Expand All @@ -364,6 +378,17 @@ def check_authorization(self, action):
username = flask.g.user.username
return self.index_document.get("uploader") == username

try:
action_to_method = {"upload": "write-storage", "download": "read-storage"}
method = action_to_method[action]
# action should be upload or download
# return bool for authorization
return self.check_rbac(method)
except ValueError:
# this is ok; we'll default to ACL field (previous behavior)
# may want to deprecate in future
pass

if flask.g.token is None:
given_acls = set(filter_auth_ids(action, flask.g.user.project_access))
else:
Expand Down
239 changes: 0 additions & 239 deletions fence/blueprints/rbac.py

This file was deleted.

Loading