SageMakerClient CustomSession uses default values instead of passed user session
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 68/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- aws, python
- Bereich
- cloud, machine-learning
Rechercherichtung
Beginne in sagemaker-core/src/sagemaker/core/utils/utils.py bei SageMakerClient.init (ungefähr in den Zeilen 395–406), und vergleiche anschließend, wie die Clients für sagemaker-runtime, featurestore und metrics die bereitgestellte Session verwenden. Führe die bereitgestellte Reproduktion mit mehreren Profilen aus und überprüfe, dass CreateTrainingJob das angegebene Konto und die angegebene Region anstelle des Standardprofils verwendet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
PySDK Version
- PySDK V2 (2.x)
- PySDK V3 (3.x)
Describe the bug
SageMakerClient builds the sagemaker client from botocore.session.get_session(), ignoring the provided user session resulting in cross-account CreateTrainingJob failures.
In sagemaker-core 2.16.0, SageMakerClient.init (sagemaker/core/utils/utils.py, ~L395–406) creates self.sagemaker_client from a fresh default botocore session (botocore.session.get_session() → custom_session) rather than the session argument, under a # TODO: Remove post-launch custom service-model loader. The sagemaker-runtime/featurestore/metrics clients correctly use session. Because the class is a SingletonMeta singleton, the first (default-credential) client is reused process-wide ignoring passed in user sessions.
Impact: callers that pass an explicit boto3 session (e.g. ModelTrainer(sagemaker_session=…) → TrainingJob.create(session=…)) have the control-plane call issued under the ambient default AWS profile instead. When the execution role is in a different account than the default profile, CreateTrainingJob fails with ValidationException: RoleArn: Cross-account pass role is not allowed.
To reproduce
If a user has multiple AWS profiles (all for different accounts) set up in ~/.aws/config and the default in ~/.aws/credentials is NOT the same account as the intended profile that is used to create the SageMaker Session then CreateTrainingJob will fail with ValidationException: RoleArn: Cross-account pass role is not allowed.
from sagemaker.core.helper.session_helper import Session
from sagemaker.train import ModelTrainer
from sagemaker.train.configs import SourceCode, Compute, InputData
import boto3
sess = Session(boto_session=boto3.Session(profile_name="acct-A", region_name="us-east-2"))
ModelTrainer(
sagemaker_session=sess, # account A
role="arn:aws:iam::<ACCOUNT_A>:role/<your-exec-role>", # account A
training_image="<ACCOUNT_A>.dkr.ecr.us-east-2.amazonaws.com/img:latest",
compute=Compute(instance_type="ml.m5.xlarge", instance_count=1),
source_code=SourceCode(source_dir="src", entry_script="train.py"),
).train(input_data_config=[InputData(channel_name="train", data_source="s3://bucket/train/")])
# -> ValidationException: RoleArn: Cross-account pass role is not allowed
# (only when your *default* AWS profile is a different account than A)
Expected behavior
A training job to be created and executed in the specified account. This is a migration from v2 to v3 and the v2 implementation of this works without issue creating training jobs in the targeted accounts based on the profile passed to the Session.
Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide:
- SageMaker Python SDK version: 3.15.1
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): SKLearn
- Framework version: 1.4-2
- Python version: py3
- CPU or GPU: CPU
- Custom Docker image (Y/N): N
Additional context
This issue also seems to persist to the latest version of 3.16 since the same custom_session is also used to initiate the sagemaker_client.
- Vorherrschende Sprache
- Python
- Sterne
- 2.3k
- Forks
- 1.3k
- Ø Merge
- 3 T. 10 Std.
- Gemergte PRs (30 T.)
- 88
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aws/sagemaker-python-sdk
-
Cannot use spark_event_logs_s3_uri in PySparkProcessor jobEvtl. vergeben @rsareddy0329 hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
aws/sagemaker-python-sdk#6253 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug] V3 Hyperparameter Tuning Pipeline page labelled "Download Data" in navigation due to missing title cellEvtl. vergeben @admivsn hat das vor 38 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 93/100
aws/sagemaker-python-sdk#6232 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug] ModelTrainer with no input channels emits InputDataConfig: [], which CreatePipeline rejects (min=1) — v2 omitted the keyEvtl. vergeben @sagemaker-bot hat das vor 9 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
aws/sagemaker-python-sdk#6156 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
sagemaker-train should depend on mlflow-skinny, following sagemaker-mlflow 0.5.0Evtl. vergeben @mohamedzeidan2021 hat das vor 10 Tagen übernommen. Offen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 72/100
aws/sagemaker-python-sdk#6152 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ModelTrainer generates sm_train.sh with CRLF line endings on Windows causing training job failureEvtl. vergeben @MohammedAlkindi hat das vor 29 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
aws/sagemaker-python-sdk#5904 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in aws/sagemaker-python-sdk
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
MystenLabs/MemWal#1163 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced onesEvtl. vergeben @moneebullah25 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
FinanceFlash/unvibecode#218 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
NVIDIA/earth2studio#1241 ·
Maintainer antworten meist innerhalb von 3 Tagen