-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[ci] refactor auth out of copy_files #60614
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
Draft
andrew-anyscale
wants to merge
1
commit into
master
Choose a base branch
from
andrew/revup/master/auth-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+134
−50
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """ | ||
| Authentication library for RayCI API endpoints. | ||
|
|
||
| Provides authenticated access to the RayCI credentials API for Docker Hub | ||
| login and S3 presigned URLs. | ||
| """ | ||
|
|
||
| import os | ||
| import subprocess | ||
| import time | ||
|
|
||
| import requests | ||
| from aws_requests_auth.boto_utils import BotoAWSRequestsAuth | ||
|
|
||
| RAYCI_API_HOST = "vop4ss7n22.execute-api.us-west-2.amazonaws.com" | ||
| RAYCI_API_URL = f"https://{RAYCI_API_HOST}/endpoint/" | ||
| RAYCI_API_REGION = "us-west-2" | ||
| RAYCI_API_SERVICE = "execute-api" | ||
| DOCKER_HUB_USERNAME = "raydockerreleaser" | ||
|
|
||
|
|
||
| class RayCIAuthError(Exception): | ||
| """Error raised when RayCI API authentication fails.""" | ||
|
|
||
|
|
||
| def _retry(f): | ||
| """Retry decorator for API calls with fixed-interval retry on 5xx errors.""" | ||
|
|
||
| def inner(): | ||
| resp = None | ||
| for _ in range(5): | ||
| resp = f() | ||
| print("Getting Presigned URL, status_code", resp.status_code) | ||
| if resp.status_code >= 500: | ||
| print("errored, retrying...") | ||
| print(resp.text) | ||
| time.sleep(5) | ||
| else: | ||
| return resp | ||
| if resp is None or resp.status_code >= 500: | ||
| raise RayCIAuthError( | ||
| "Failed to get a valid response from RayCI API after multiple retries." | ||
| ) | ||
|
|
||
| return inner | ||
|
|
||
|
|
||
| @_retry | ||
| def get_rayci_api_response(): | ||
| """ | ||
| Fetch credentials from the RayCI API endpoint. | ||
|
|
||
| Uses AWS SigV4 authentication via the instance's IAM role. | ||
| Requires BUILDKITE_JOB_ID environment variable. | ||
|
|
||
| Returns: | ||
| requests.Response containing credentials for Docker Hub and S3. | ||
| """ | ||
| job_id = os.environ.get("BUILDKITE_JOB_ID") | ||
| if not job_id: | ||
| raise ValueError("BUILDKITE_JOB_ID environment variable must be set.") | ||
|
|
||
| auth = BotoAWSRequestsAuth( | ||
| aws_host=RAYCI_API_HOST, | ||
| aws_region=RAYCI_API_REGION, | ||
| aws_service=RAYCI_API_SERVICE, | ||
| ) | ||
| resp = requests.get( | ||
| RAYCI_API_URL, | ||
| auth=auth, | ||
| params={"job_id": job_id}, | ||
| ) | ||
| return resp | ||
|
|
||
|
|
||
| def docker_hub_login() -> None: | ||
| """ | ||
| Login to Docker Hub using credentials from RayCI API. | ||
|
|
||
| Fetches credentials and runs `docker login` for the rayproject account. | ||
| """ | ||
| resp = get_rayci_api_response() | ||
| try: | ||
| pwd = resp.json()["docker_password"] | ||
| except (requests.exceptions.JSONDecodeError, KeyError) as e: | ||
| raise RayCIAuthError( | ||
| f"Could not get docker_password from API response: {resp.text}" | ||
| ) from e | ||
| subprocess.run( | ||
| ["docker", "login", "--username", DOCKER_HUB_USERNAME, "--password-stdin"], | ||
| input=pwd.encode(), | ||
| check=True, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.