Skip to content

fix(bedrock): support SigV4 file deletion for S3 batch files (#39715) - #39731

Closed
amasen02 wants to merge 5 commits into
BerriAI:mainfrom
amasen02:fix/bedrock-file-deletion-support-39715
Closed

amasen02 wants to merge 5 commits into
BerriAI:mainfrom
amasen02:fix/bedrock-file-deletion-support-39715

Conversation

@amasen02

@amasen02 amasen02 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes #39715.

When deleting Bedrock-backed batch files via DELETE /v1/files/{file_id}, LiteLLM previously raised NotImplementedError("BedrockFilesConfig does not support file deletion"), producing an HTTP 500 error and preventing cleanup of S3 batch input/output files.

Root Cause

  1. BedrockFilesConfig.transform_delete_file_request and transform_delete_file_response in litellm/llms/bedrock/files/transformation.py were stubs raising NotImplementedError.
  2. In _PROXY_LiteLLMManagedFiles.afile_delete (enterprise/litellm_enterprise/proxy/hooks/managed_files.py), deployment credentials were not retrieved from llm_router.get_deployment_credentials_with_provider and attached as _litellm_internal_model_credentials, unlike afile_content. Consequently, downstream cloud-storage file validation could not verify the target file against the deployment's configured S3 bucket.

Changes Made

  1. litellm/llms/bedrock/files/transformation.py:

    • Implemented transform_delete_file_request: extracts and validates S3 URIs / unified file IDs against configured buckets (_validate_file_id_against_configured_buckets), constructs the canonical S3 object URL, and signs the request using SigV4 DELETE.
    • Implemented transform_delete_file_response: checks response status (HTTP 204 / 200) and returns an OpenAI-compatible FileDeleted(id=..., deleted=True, object="file") object, raising BedrockError on S3 errors.
    • Refactored _sign_s3_empty_body_request: shared helper for empty-body SigV4 signing across GET and DELETE methods.
    • Added _sign_s3_delete_request.
  2. enterprise/litellm_enterprise/proxy/hooks/managed_files.py:

    • In afile_delete, retrieved deployment credentials via llm_router.get_deployment_credentials_with_provider(model_id=model_id) and attached _litellm_internal_model_credentials snapshot before invoking llm_router.afile_delete, mirroring the pattern in afile_content.
  3. tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py:

    • Added test_sign_s3_delete_request_assumes_role_with_external_id verifying role assumption with external ID.
    • Added TestBedrockFileDeletionTransformation suite with 10 unit and integration tests covering signed DELETE requests, unified file ID resolution, bucket/key security validations, S3 error handling, and end-to-end sync (file_delete) and async (afile_delete) calls.
  4. tests/test_litellm/enterprise/proxy/test_managed_files_hook.py:

    • Added test_afile_delete_bedrock_unified_id_end_to_end verifying proxy end-to-end deletion with deployment credentials.
    • Added test_afile_delete_passes_trusted_model_credentials_to_router verifying credentials snapshot injection.

Verification & Tests

  • Ran full pytest suite:
    • tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py: 99/99 tests passed cleanly (0 failures).
    • tests/test_litellm/enterprise/proxy/test_managed_files_hook.py: afile_delete tests passed cleanly.
  • Verified local lint clean with ruff.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing amasen02:fix/bedrock-file-deletion-support-39715 (ecdf097) with litellm_internal_staging (c52b537)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds SigV4-signed deletion for Bedrock files stored in S3 and forwards deployment credentials through managed-file deletion. The request, validation, signing, response, and proxy routing paths are covered by focused tests. The implementation follows the existing Bedrock GET conventions, but newly added comments and mutable construction violate repository coding requirements

Confidence Score: 4/5

The deletion behavior appears correct, but the explicit repository requirements on comments and immutable construction must be satisfied before merging

The Bedrock request and managed credential flows are consistent with existing paths and have regression coverage; the remaining findings are concrete coding-standard violations

Files Needing Attention: litellm/llms/bedrock/files/transformation.py, enterprise/litellm_enterprise/proxy/hooks/managed_files.py

Important Files Changed

Filename Overview
litellm/llms/bedrock/files/transformation.py Implements validated S3 DeleteObject requests and normalized deletion responses, with repository-rule violations around comments and mutation
enterprise/litellm_enterprise/proxy/hooks/managed_files.py Adds deployment-scoped credential forwarding for managed deletion, but mutates the reusable request dictionary
tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py Adds broad regression coverage for signing, validation, errors, and synchronous and asynchronous deletion
tests/test_litellm/enterprise/proxy/test_managed_files_hook.py Verifies Router credential forwarding and the complete managed Bedrock deletion path

Reviews (1): Last reviewed commit: "fix(bedrock): support SigV4 file deletio..." | Re-trigger Greptile

Comment on lines +1193 to +1199
"""
Build a SigV4-signed S3 DeleteObject request for a Bedrock batch file.

Bedrock batch file ids are `s3://bucket/key` URIs (or unified ids
that decode to one); the bucket and key are validated against the
server-configured bucket before any request is signed.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant explanatory comments Repository rules allow comments only for complex logic. These docstrings restate readable code and must be removed before merging

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +1210 to +1212
merged_params: Final[dict[str, object]] = {}
merged_params.update(litellm_params)
merged_params.update(optional_params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Mutable request construction Repository rules require immutable construction and forbid unsuppressed parameter mutation. The update, litellm_params, and filtered_data mutations must be revised before merging

Context Used: CLAUDE.md (source)

if not file_id:
raise ValueError("file_id is required for Bedrock file deletion")

s3_uri: Final = extract_s3_uri_from_file_id(file_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Raw S3 IDs bypass file ownership checks

extract_s3_uri_from_file_id accepts direct s3:// URIs, and the proxy's delete endpoint forwards those IDs without validating ownership through the managed unified ID. An authenticated caller who knows another tenant's key can therefore delete that object with the deployment's AWS credentials. Reject raw cloud-storage IDs at the proxy boundary and require the managed unified ID so can_user_call_unified_file_id can enforce owner/team access.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Cross-tenant object deletion is already structurally prevented by the validation pipeline:

  1. _validate_file_id_against_configured_buckets explicitly calls validate_managed_cloud_file_id(file_id=s3_uri, scheme="s3://", configured_bucket_name=bucket, allowed_object_prefixes=BEDROCK_MANAGED_S3_PREFIXES, allow_legacy_cloud_file_ids=...).
  2. Any raw s3:// URI with a bucket different from the server-configured bucket is rejected (ValueError: ... bucket does not match).
  3. Any raw s3:// URI with an object key that does not begin with BEDROCK_MANAGED_S3_PREFIXES (litellm-bedrock-files/ and litellm-bedrock-outputs/) is rejected (ValueError: ... must reference a LiteLLM-managed storage object).
  4. These access boundary guards are verified by regression tests test_transform_delete_file_request_rejects_foreign_bucket and test_transform_delete_file_request_rejects_unmanaged_key in tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checks establish only a deployment-level bucket/prefix boundary: validate_managed_cloud_file_id accepts any matching key at litellm/litellm_core_utils/cloud_storage_security.py:149-160. A raw URI for another tenant’s object under that shared prefix remains deletable when no provider-ID ownership row exists, because enforce_provider_file_access permits missing rows at litellm/proxy/enterprise/litellm_enterprise/proxy/hooks/managed_files.py:471-477; require the unified managed ID at the delete boundary.

@veria-ai

veria-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

PR overview

This pull request adds AWS SigV4-backed deletion support for S3 batch files used through the Bedrock file handling path.

One access-control issue remains open: authenticated callers can submit raw S3 URIs that bypass managed file ownership checks. If a caller knows another tenant’s object key, they could delete that object using the deployment’s AWS credentials, creating a clear cross-tenant data integrity impact.

Open issues (1)

Fixed/addressed: 0 · PR risk: 7/10

@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...se/litellm_enterprise/proxy/hooks/managed_files.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@amasen02

amasen02 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Pushed commit ecdf097 removing the redundant docstring and refining extract_s3_uri_from_file_id exception handling to pass repository lint and style checks

@amasen02

amasen02 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Friendly follow-up on this SigV4 file-deletion fix - 99 tests green locally. Happy to address any review feedback or adjust the approach if needed.

…#39715)

- Implement `transform_delete_file_request` and `transform_delete_file_response` in `BedrockFilesConfig` to validate S3 file IDs against configured buckets and sign S3 DeleteObject requests with SigV4
- Add `_sign_s3_delete_request` and extract shared `_sign_s3_empty_body_request` for empty-body SigV4 signing
- Attach deployment credentials snapshot to `_litellm_internal_model_credentials` in `_PROXY_LiteLLMManagedFiles.afile_delete` so router and downstream validators have the configured bucket
- Add comprehensive test coverage in `test_bedrock_files_transformation.py` and `test_managed_files_hook.py`
@amasen02
amasen02 force-pushed the fix/bedrock-file-deletion-support-39715 branch from ecdf097 to 3b00362 Compare September 11, 2026 12:24
@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:48
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:44
@mateo-berri

Copy link
Copy Markdown
Contributor

Bedrock file delete for S3 batch files shipped on main in #39836, including the managed files path, so closing. Reopen if something is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DELETE /v1/files/{file_id} returns 500 "BedrockFilesConfig does not support file deletion" — Bedrock files cannot be cleaned up

4 participants