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

Add user identity to cluster status to avoid leakage when switching account #1513

Merged
merged 87 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
028340b
add user identity check
Michaelvll Dec 12, 2022
f3a5488
fix
Michaelvll Dec 12, 2022
b164b73
fix
Michaelvll Dec 12, 2022
a393f54
continue when error happens in status refresh
Michaelvll Dec 12, 2022
aff8e61
format
Michaelvll Dec 12, 2022
cfd8ff3
fix
Michaelvll Dec 12, 2022
e6c7b0c
fix
Michaelvll Dec 12, 2022
4235517
fix table output
Michaelvll Dec 12, 2022
3f75d73
check the identity earlier
Michaelvll Dec 12, 2022
f006c81
fix
Michaelvll Dec 12, 2022
5446452
fix
Michaelvll Dec 12, 2022
b719495
supress exception
Michaelvll Dec 12, 2022
aa59b5a
update message
Michaelvll Dec 12, 2022
f07629a
show old status in the table
Michaelvll Dec 12, 2022
978ebd4
fix message
Michaelvll Dec 12, 2022
c2a42ce
fix refresh
Michaelvll Dec 12, 2022
cf6df3c
Fix test smoke
Michaelvll Dec 12, 2022
20a5f4e
Avoid thread-safety issue for creating aws client
Michaelvll Dec 12, 2022
a49254c
rename
Michaelvll Dec 12, 2022
b17f5b3
Handle unknown exceptions
Michaelvll Dec 13, 2022
4586039
Reuse the aws utils
Michaelvll Dec 13, 2022
ce86160
update message
Michaelvll Dec 13, 2022
7acf924
Error handling
Michaelvll Dec 13, 2022
739d216
skip identity check for spot controller
Michaelvll Dec 13, 2022
9f8517f
fix
Michaelvll Dec 13, 2022
4df9d9e
Use direct client cache instead
Michaelvll Dec 13, 2022
8f2d543
Make client creation thread-safe
Michaelvll Dec 13, 2022
e734563
yapf
Michaelvll Dec 13, 2022
6ad60e4
Resource thread-safe
Michaelvll Dec 13, 2022
c4d679e
remove retry loop
Michaelvll Dec 13, 2022
f7980fd
Do not fail if the identity fetching errors out
Michaelvll Dec 13, 2022
97f972a
add back exception
Michaelvll Dec 13, 2022
2fb23e6
fix exceptions for GCP
Michaelvll Dec 13, 2022
41c4325
fix
Michaelvll Dec 13, 2022
55468c7
fix backward compat check
Michaelvll Dec 13, 2022
9e46673
Address comments
Michaelvll Dec 14, 2022
3368562
rename function
Michaelvll Dec 14, 2022
b9f23a1
Update sky/utils/env_options.py
Michaelvll Dec 14, 2022
548d32e
fix
Michaelvll Dec 14, 2022
3e8c046
Merge branch 'add-user-identity-to-cluster' of github.com:concretevit…
Michaelvll Dec 14, 2022
8cbdfcb
Fix the `sky check`
Michaelvll Dec 15, 2022
2e58894
fix
Michaelvll Dec 15, 2022
c69082d
Fix check public cloud
Michaelvll Dec 15, 2022
714d5a8
Make check identity more fine-grained
Michaelvll Dec 15, 2022
10acb75
Merge branch 'master' of github.com:concretevitamin/sky-experiments i…
Michaelvll Dec 15, 2022
b461c93
locking issue
Michaelvll Dec 15, 2022
09af9c7
backward compat test fix
Michaelvll Dec 15, 2022
10e8651
Merge branch 'master' of github.com:concretevitamin/sky-experiments i…
Michaelvll Dec 16, 2022
e158e96
address comments
Michaelvll Dec 16, 2022
eec7ee7
gcp project_id
Michaelvll Dec 16, 2022
405cded
rename a func
Michaelvll Dec 16, 2022
a664be7
skip identity check for dryruns
Michaelvll Dec 16, 2022
dc2a425
fix
Michaelvll Dec 16, 2022
d3f8731
Keep old owner value
Michaelvll Dec 17, 2022
287788a
Merge branch 'add-user-identity-to-cluster' of github.com:concretevit…
Michaelvll Dec 17, 2022
0cb6a45
fix
Michaelvll Dec 17, 2022
1276bbf
Add comments
Michaelvll Dec 17, 2022
47c529c
fix comment
Michaelvll Dec 17, 2022
46ab156
Merge branch 'master' of github.com:concretevitamin/sky-experiments i…
Michaelvll Dec 17, 2022
e6107d2
Fix comments
Michaelvll Dec 17, 2022
cb40ca6
remove the "|| true"
Michaelvll Dec 17, 2022
fd2e552
address comments
Michaelvll Dec 18, 2022
09f9edc
Warn the identity mismatch
Michaelvll Dec 18, 2022
82f1fff
Not fail for identity when ssh can be used
Michaelvll Dec 18, 2022
43a2c92
suppress stack trace
Michaelvll Dec 18, 2022
e8b376e
fix message
Michaelvll Dec 18, 2022
42abdd9
Merge branch 'master' of github.com:concretevitamin/sky-experiments i…
Michaelvll Dec 18, 2022
77a8783
Fix UX
Michaelvll Dec 18, 2022
5f06131
Fix spot
Michaelvll Dec 18, 2022
3dacf29
fix exec
Michaelvll Dec 18, 2022
45aeb42
format
Michaelvll Dec 18, 2022
d0f1888
fix ux
Michaelvll Dec 18, 2022
718802a
Fix UX
Michaelvll Dec 18, 2022
82c8e35
Address comments
Michaelvll Dec 18, 2022
53c755d
fix
Michaelvll Dec 19, 2022
c589ab6
Fix aws v2
Michaelvll Dec 19, 2022
577a38f
Change logs
Michaelvll Dec 19, 2022
c9899e4
Disallow all operations with different user identity
Michaelvll Dec 19, 2022
e451078
Better logging
Michaelvll Dec 19, 2022
ddb401d
fix comment
Michaelvll Dec 19, 2022
3645923
better logging
Michaelvll Dec 19, 2022
a1b9c7f
Update sky/backends/backend_utils.py
Michaelvll Dec 19, 2022
9b89b0a
address comments
Michaelvll Dec 19, 2022
aa61492
Merge branch 'add-user-identity-to-cluster' of github.com:concretevit…
Michaelvll Dec 19, 2022
5f54855
lint
Michaelvll Dec 19, 2022
7ed02d3
Merge branch 'master' of github.com:concretevitamin/sky-experiments i…
Michaelvll Dec 20, 2022
7874618
solve error
Michaelvll Dec 20, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
pip install pytest pytest-xdist pytest-env>=0.6

- name: Run tests with pytest
run: SKYPILOT_DISABLE_USAGE_COLLECTION=1 pytest ${{ matrix.test-path }}
run: SKYPILOT_DISABLE_USAGE_COLLECTION=1 SKYPILOT_SKIP_CLOUD_IDENTITY_CHECK=1 pytest ${{ matrix.test-path }}
42 changes: 27 additions & 15 deletions sky/adaptors/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

# pylint: disable=import-outside-toplevel

from functools import wraps
import functools

boto3 = None
botocore = None


def import_package(func):

@wraps(func)
@functools.wraps(func)
def wrapper(*args, **kwargs):
global boto3, botocore
if boto3 is None or botocore is None:
Expand All @@ -27,17 +27,16 @@ def wrapper(*args, **kwargs):
return wrapper


@functools.lru_cache()
@import_package
def client(service_name: str, **kwargs):
"""Create an AWS client of a certain service.

Args:
service_name: AWS service name (e.g., 's3', 'ec2').
kwargs: Other options.
"""
return boto3.client(service_name, **kwargs)
def session():
"""Create an AWS session."""
# functools.lru_cache() is used to cache the session object
# for each thread.
return boto3.session.Session()


@functools.lru_cache()
@import_package
def resource(resource_name: str, **kwargs):
"""Create an AWS resource.
Expand All @@ -46,13 +45,26 @@ def resource(resource_name: str, **kwargs):
resource_name: AWS resource name (e.g., 's3').
kwargs: Other options.
"""
return boto3.resource(resource_name, **kwargs)
# Need to use the resource retrieved from the per-thread session
# to avoid thread-safety issues (Directly creating the client
# with boto3.resource() is not thread-safe).
# Reference: https://stackoverflow.com/a/59635814
return session().resource(resource_name, **kwargs)


@import_package
def session():
"""Create an AWS session."""
return boto3.Session()
@functools.lru_cache()
def client(service_name: str, **kwargs):
"""Create an AWS client of a certain service.

Args:
service_name: AWS service name (e.g., 's3', 'ec2').
kwargs: Other options.
"""
# Need to use the client retrieved from the per-thread session
# to avoid thread-safety issues (Directly creating the client
# with boto3.client() is not thread-safe).
# Reference: https://stackoverflow.com/a/59635814
return session().client(service_name, **kwargs)


@import_package
Expand Down
7 changes: 7 additions & 0 deletions sky/adaptors/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ def get_subscription_id() -> str:
"""Get the default subscription id."""
from azure.common import credentials
return credentials.get_cli_profile().get_subscription_id()


@import_package
def get_current_account_user() -> str:
"""Get the default account user."""
from azure.common import credentials
return credentials.get_cli_profile().get_current_account_user()
Loading