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: Improve logging on failures to fetch secret #184

Merged
merged 1 commit into from
Mar 21, 2024
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
12 changes: 8 additions & 4 deletions src/deadline_worker_agent/windows/win_credentials_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _fetch_secret_from_secrets_manager(self, secretArn: str) -> dict:
break
# Possible client error exceptions that could happen here are
# Can be retried: InternalServiceError, ThrottlingException
# Can't be retired: ResourceNotFoundException, InvalidRequestException, DecryptionFailure
# Can't be retried: ResourceNotFoundException, InvalidRequestException, DecryptionFailure, AccessDeniedException
except ClientError as e:
delay = backoff.delay_amount(RetryContext(retry))
code = e.response.get("Error", {}).get("Code", None)
Expand All @@ -101,7 +101,11 @@ def _fetch_secret_from_secrets_manager(self, secretArn: str) -> dict:
f"GetSecretValue received {code} ({str(e)}). Retrying in {delay} seconds..."
)
else:
raise RuntimeError(e) from None
if code in ["AccessDeniedException"]:
logger.error(
f"Access to secret was denied. Please ensure the resource policy for {secretArn} allows access to the fleet role, and the fleet role is correctly configured"
)
raise RuntimeError(e)
retry += 1
except Exception as e:
# General catch-all for the unexpected, so that the agent can try to handle it gracefully.
Expand Down Expand Up @@ -198,9 +202,9 @@ def get_windows_session_user(self, user: str, passwordArn: str) -> WindowsSessio
# Fetch the secret from Secrets Manager
try:
secret = self._fetch_secret_from_secrets_manager(passwordArn)
except Exception:
except Exception as e:
logger.error(
f"Contents of secret {passwordArn} could not be fetched or were not valid"
f"Contents of secret {passwordArn} could not be fetched or were not valid: {str(e)}"
)
else:
password = secret.get("password")
Expand Down
1 change: 1 addition & 0 deletions test/unit/windows/test_win_credentials_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_get_windows_session_user_invalid_credentials(
"ResourceNotFoundException",
"InvalidRequestException",
"DecryptionFailure",
"AccessDeniedException",
],
)
@patch(
Expand Down