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

fix: migrate signBlob to iamcredentials.googleapis.com #553

Merged
merged 3 commits into from
Jun 30, 2020
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ pylintrc.test
pytype_output/

.python-version
.DS_Store
cert_path
key_path
6 changes: 3 additions & 3 deletions google/auth/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from google.auth import crypt
from google.auth import exceptions

_IAM_API_ROOT_URI = "https://iam.googleapis.com/v1"
_IAM_API_ROOT_URI = "https://iamcredentials.googleapis.com/v1"
_SIGN_BLOB_URI = _IAM_API_ROOT_URI + "/projects/-/serviceAccounts/{}:signBlob?alt=json"


Expand Down Expand Up @@ -71,7 +71,7 @@ def _make_signing_request(self, message):
url = _SIGN_BLOB_URI.format(self._service_account_email)
headers = {}
body = json.dumps(
{"bytesToSign": base64.b64encode(message).decode("utf-8")}
{"payload": base64.b64encode(message).decode("utf-8")}
).encode("utf-8")

self._credentials.before_request(self._request, method, url, headers)
Expand All @@ -97,4 +97,4 @@ def key_id(self):
@_helpers.copy_docstring(crypt.Signer)
def sign(self, message):
response = self._make_signing_request(message)
return base64.b64decode(response["signature"])
return base64.b64decode(response["signedBlob"])
17 changes: 17 additions & 0 deletions system_tests/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from google.auth import _helpers
from google.auth import exceptions
from google.auth import iam
from google.oauth2 import service_account


Expand Down Expand Up @@ -46,3 +47,19 @@ def test_refresh_success(http_request, credentials, token_info):
"https://www.googleapis.com/auth/userinfo.profile",
]
)

def test_iam_signer(http_request, credentials):
credentials = credentials.with_scopes(
["https://www.googleapis.com/auth/iam"]
)

# Verify iamcredentials signer.
signer = iam.Signer(
http_request,
credentials,
credentials.service_account_email
)

signed_blob = signer.sign("message")

assert isinstance(signed_blob, bytes)
6 changes: 3 additions & 3 deletions tests/compute_engine/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ def test_with_target_audience_integration(self):
signature = base64.b64encode(b"some-signature").decode("utf-8")
responses.add(
responses.POST,
"https://iam.googleapis.com/v1/projects/-/serviceAccounts/"
"service-account@example.com:signBlob?alt=json",
"https://iamcredentials.googleapis.com/v1/projects/-/"
"serviceAccounts/service-account@example.com:signBlob?alt=json",
status=200,
content_type="application/json",
json={"keyId": "some-key-id", "signature": signature},
json={"keyId": "some-key-id", "signedBlob": signature},
)

id_token = "{}.{}.{}".format(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_key_id(self):
def test_sign_bytes(self):
signature = b"DEADBEEF"
encoded_signature = base64.b64encode(signature).decode("utf-8")
request = make_request(http_client.OK, data={"signature": encoded_signature})
request = make_request(http_client.OK, data={"signedBlob": encoded_signature})
credentials = make_credentials()

signer = iam.Signer(request, credentials, mock.sentinel.service_account_email)
Expand Down