-
Notifications
You must be signed in to change notification settings - Fork 602
Swarming: Fetches Credentials with scope & other Minor fixes #5222
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| from clusterfuzz._internal.config import local_config | ||
| from clusterfuzz._internal.datastore import data_types | ||
| from clusterfuzz._internal.google_cloud_utils import credentials | ||
| from clusterfuzz._internal.metrics import logs | ||
| from clusterfuzz._internal.protos import swarming_pb2 | ||
| from clusterfuzz._internal.system import environment | ||
|
|
||
|
|
@@ -67,7 +68,7 @@ def _get_task_dimensions(job: data_types.Job, platform_specific_dimensions: list | |
| """ Gets all swarming dimensions for a task. | ||
| Job dimensions have more precedence than static dimensions""" | ||
| unique_dimensions = {} | ||
| unique_dimensions['os'] = job.platform | ||
| unique_dimensions['os'] = str(job.platform).capitalize() | ||
| unique_dimensions['pool'] = _get_swarming_config().get('swarming_pool') | ||
|
|
||
| for dimension in platform_specific_dimensions: | ||
|
|
@@ -133,6 +134,7 @@ def _get_new_task_spec(command: str, job_name: str, | |
| swarming_pb2.StringPair(key='UWORKER', value='True'), # pylint: disable=no-member | ||
| swarming_pb2.StringPair(key='SWARMING_BOT', value='True'), # pylint: disable=no-member | ||
| swarming_pb2.StringPair(key='LOG_TO_GCP', value='True'), # pylint: disable=no-member | ||
| swarming_pb2.StringPair(key='IS_K8S_ENV', value='True'), # pylint: disable=no-member | ||
| swarming_pb2.StringPair( # pylint: disable=no-member | ||
| key='LOGGING_CLOUD_PROJECT_ID', | ||
| value=logs_project_id), | ||
|
|
@@ -181,7 +183,11 @@ def push_swarming_task(command, download_url, job_type): | |
| raise ValueError('invalid job_name') | ||
|
|
||
| task_spec = _get_new_task_spec(command, job_type, download_url) | ||
| creds, _ = credentials.get_default(_SWARMING_SCOPES) | ||
| creds = credentials.get_scoped_service_account_credentials(_SWARMING_SCOPES) | ||
| if not creds: | ||
| logs.error( | ||
| '[Swarming] Failed to push task into swarming. Reason: No credentials.') | ||
| return | ||
|
|
||
| if not creds.token: | ||
| creds.refresh(requests.Request()) | ||
|
|
@@ -193,5 +199,8 @@ def push_swarming_task(command, download_url, job_type): | |
| } | ||
| swarming_server = _get_swarming_config().get('swarming_server') | ||
| url = f'https://{swarming_server}/prpc/swarming.v2.Tasks/NewTask' | ||
| utils.post_url( | ||
| url=url, data=json_format.MessageToJson(task_spec), headers=headers) | ||
| message_body = json_format.MessageToJson(task_spec) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a security concern to log the whole body to the console?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess not since logs are only readable trough the GCP project, but im not 100% sure of this affirmation, since im not fully aware of who has access to this projects. @javanlacerda wdyt? |
||
| logs.info(f"""[Swarming] Pushing task to {url} | ||
| as {creds.service_account_email} with {message_body}""") | ||
| response = utils.post_url(url=url, data=message_body, headers=headers) | ||
| logs.info(f'[Swarming] Response: {response}') | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the call to
str()actually needed? Isn'tjob.platformalready a string? I suppose we need to capitalize it since Swarming is not accepting the string as is, correct? Is it because it's not a string or because it's not capitalized?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the str() casting is not necessary, but i just add it to avoid one more error from displaying in the screen:

Worth noting that platform is never empty because is a requirement to add it to the data store