Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: third_party/gsutil/plugins/sso_auth.py

Issue 86123002: Adds SSO auth to gsutil (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Added bypass support Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« third_party/gsutil/gslib/util.py ('K') | « third_party/gsutil/plugins/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/gsutil/plugins/sso_auth.py
diff --git a/third_party/gsutil/plugins/sso_auth.py b/third_party/gsutil/plugins/sso_auth.py
new file mode 100644
index 0000000000000000000000000000000000000000..614cc1877fef1a3fa15e877ee02ae5a2e66d847a
--- /dev/null
+++ b/third_party/gsutil/plugins/sso_auth.py
@@ -0,0 +1,54 @@
+import json
+import getpass
+import os
+import re
+import urllib2
+import subprocess
+
+from boto.auth_handler import AuthHandler
+from boto.auth_handler import NotReadyToAuthenticate
+
+CMD = ['stubby', '--proto2', 'call', 'blade:sso', 'CorpLogin.Exchange']
+STUBBY_CMD = """target: {
+ scope: GAIA_USER
+ name: "%s"
+}
+target_credential: {
+ type: OAUTH2_TOKEN
+ oauth2_attributes: {
+ scope: 'https://www.googleapis.com/auth/devstorage.read_only'
+ }
+}"""
+
+
+class SSOAuth(AuthHandler):
+ """SSO based auth handler."""
+
+ capability = ['google-oauth2', 's3']
+
+ def __init__(self, path, config, provider):
+ if provider.name == 'google' and self.has_prodaccess():
+ pass
+ else:
+ raise NotReadyToAuthenticate()
+
+ def GetAccessToken(self):
+ username = '%s@google.com' % getpass.getuser()
+ proc = subprocess.Popen(CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ out, err = proc.communicate(STUBBY_CMD % username)
+ token_match = re.search(r'oauth2_token: "(.*)"$', out)
+ if token_match:
+ return token_match.group(1)
+ return None
+
+ def add_auth(self, http_request):
+ http_request.headers['Authorization'] = (
+ 'OAuth %s' % self.GetAccessToken())
+
+ @staticmethod
+ def has_prodaccess():
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, 'prodaccess')
+ if os.path.exists(exe_file) and os.access(exe_file, os.X_OK):
+ return True
+ return False
« third_party/gsutil/gslib/util.py ('K') | « third_party/gsutil/plugins/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698