Skip to content

fix(bsl): require region when s3Url is set on AWS BackupStorageLocation#2175

Closed
SAY-5 wants to merge 1 commit intoopenshift:oadp-devfrom
SAY-5:fix/bsl-require-region-when-s3url-2108
Closed

fix(bsl): require region when s3Url is set on AWS BackupStorageLocation#2175
SAY-5 wants to merge 1 commit intoopenshift:oadp-devfrom
SAY-5:fix/bsl-require-region-when-s3url-2108

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 22, 2026

Closes #2108.

Problem

`validateAWSBackupStorageLocation` in `internal/controller/bsl.go` accepted BSLs where `provider: aws`, a custom `s3Url` and no `region` were all set together. The only region check was:

```go
if (config == nil || len(config[Region]) == 0) &&
(config[S3ForcePathStyle] == "true" || !aws.BucketRegionIsDiscoverable(bucket)) {
return ...
}
```

Once `s3ForcePathStyle` stopped being required (IBM COS no longer needs it), validation fell through to `BucketRegionIsDiscoverable`, which queries AWS's HeadBucket API against `s3.us-east-1.amazonaws.com`. That's meaningless for non-AWS S3-compatible endpoints (IBM COS, MinIO, NooBaa): either discovery fails and validation works by accident, or discovery succeeds against an unrelated like-named AWS bucket and validation passes — but Velero can't connect to the actual backend.

Fix

Short-circuit that path: if `s3Url` is set and `region` is not, reject the BSL before falling into the discovery branch, with the message the issue suggests:

region is required when s3Url is set for AWS backupstoragelocation; region cannot be auto-discovered for non-AWS S3-compatible endpoints

Scoped to exactly the configuration the issue calls out (`s3Url` present, `region` absent); everything else in `validateAWSBackupStorageLocation` stays unchanged.

Verification

  • `go build ./...` — clean.
  • `go vet ./internal/controller` — clean.
  • `go test -count=1 -run TestDPAReconciler_ValidateBackupStorageLocations ./internal/controller/...` — ok. The envtest-based suite (`TestAPIs`) fails locally without the kubebuilder test assets, unrelated to this change.

I considered adding a focused unit test next to `TestValidatePEMCertificate`, but `validateAWSBackupStorageLocation` dereferences a real `client.Client` via `validateProviderPluginAndSecret` before reaching the config check, so a standalone call panics without a fake client. The existing table-driven `TestDPAReconciler_ValidateBackupStorageLocations` is the right place to add coverage — I'd rather wire that up as a follow-up (it's a big table and I don't want to bury this change in scaffolding noise). Happy to push that if reviewers would prefer it bundled here.

Summary by CodeRabbit

  • Bug Fixes
    • Updated AWS Backup Storage Location validation to provide explicit error messages when S3 URL is configured without the required region setting.

`validateAWSBackupStorageLocation` let a BSL through when `provider:
aws`, a custom `s3Url` (IBM COS / MinIO / NooBaa / ...) and no `region`
were all set together. The only region check we had was

    (config == nil || len(config[Region]) == 0) &&
    (config[S3ForcePathStyle] == "true" || !BucketRegionIsDiscoverable(bucket))

so once `s3ForcePathStyle` stopped being required (IBM COS no longer
needs it), the validation fell through to `BucketRegionIsDiscoverable`
-- which queries AWS's HeadBucket API against `s3.us-east-1.amazonaws.com`
and is meaningless for non-AWS endpoints. It either fails (validation
works by accident) or returns a bogus region from an unrelated
like-named AWS bucket (validation passes but Velero can't connect).

Short-circuit that path: if `s3Url` is set and `region` is not,
reject the BSL with a clear error before falling into the discovery
branch.

Closes #2108.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d8391ec8-677e-4879-80d5-cf400c2c136a

📥 Commits

Reviewing files that changed from the base of the PR and between c927a46 and ab29796.

📒 Files selected for processing (1)
  • internal/controller/bsl.go

Walkthrough

Updated AWS Backup Storage Location validation to require an explicit region field when s3Url is set to a non-empty value, preventing reliance on AWS-specific auto-discovery logic for non-AWS S3-compatible endpoints.

Changes

Cohort / File(s) Summary
BSL Region Validation
internal/controller/bsl.go
Added early validation check requiring region to be set when s3Url is configured in BSL config. This prevents invalid auto-discovery attempts against AWS APIs when pointing to non-AWS S3-compatible endpoints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 12
✅ Passed checks (12 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main code change: requiring region when s3Url is set on AWS BackupStorageLocation.
Description check ✅ Passed The PR description thoroughly explains the problem, the fix, and verification steps, fully addressing the template sections.
Linked Issues check ✅ Passed The code change directly implements the fix suggested in issue #2108 by adding the required s3Url/region validation check.
Out of Scope Changes check ✅ Passed All changes are scoped to the specific validation requirement in #2108; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Stable And Deterministic Test Names ✅ Passed PR modifies only source code in internal/controller/bsl.go with no test file changes, making the stable test names requirement not applicable.
Test Structure And Quality ✅ Passed PR modifies only internal/controller/bsl.go with validation changes; no Ginkgo test modifications present, making this custom check not applicable.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests are added; the PR only modifies validation logic in internal/controller/bsl.go with standard Go unit tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR modifies validation logic in internal/controller/bsl.go without adding any new Ginkgo e2e tests.
Topology-Aware Scheduling Compatibility ✅ Passed PR adds validation logic for AWS BackupStorageLocation configuration without introducing scheduling constraints or topology assumptions.
Ote Binary Stdout Contract ✅ Passed The PR modifies internal/controller/bsl.go, a Kubernetes controller file, not an OTE test binary, so the OTE Binary Stdout Contract does not apply.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR does not add any new Ginkgo e2e tests. Changes are limited to updating AWS BackupStorageLocation validation logic in a non-test file.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 22, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 22, 2026

Hi @SAY-5. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mpryc
Copy link
Copy Markdown
Contributor

mpryc commented Apr 22, 2026

/lgtm

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 22, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mpryc, SAY-5

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 22, 2026
@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2026
@mpryc
Copy link
Copy Markdown
Contributor

mpryc commented Apr 22, 2026

/ok-to-test

@openshift-ci openshift-ci Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 22, 2026
@mpryc
Copy link
Copy Markdown
Contributor

mpryc commented Apr 22, 2026

/hold

I will allow others to review as well, just wondering if minimal unit test could be added here, something along the :

  {
      name: "test AWS BSL with s3Url but no region",
      dpa: &oadpv1alpha1.DataProtectionApplication{
          ObjectMeta: metav1.ObjectMeta{
              Name:      "foo",
              Namespace: "test-ns",
          },
          Spec: oadpv1alpha1.DataProtectionApplicationSpec{
              Configuration: &oadpv1alpha1.ApplicationConfig{
                  Velero: &oadpv1alpha1.VeleroConfig{},
              },
              BackupLocations: []oadpv1alpha1.BackupLocation{
                  {
                      Velero: &velerov1.BackupStorageLocationSpec{
                          Provider: "aws",
                          Config: map[string]string{
                              S3URL: "https://s3.example.com",
                          },
                          // ... ObjectStorage, Credential, etc.
                      },
                  },
              },
          },
      },
      want:    false,
      wantErr: true,
      secret:  &corev1.Secret{...},
  },

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 22, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 22, 2026

@SAY-5: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/4.23-e2e-test-aws ab29796 link false /test 4.23-e2e-test-aws

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kaovilai
Copy link
Copy Markdown
Member

kaovilai commented Apr 22, 2026

#2109 also implement this fyi. If we prefer this pr feel free to copy unit test over

@mpryc
Copy link
Copy Markdown
Contributor

mpryc commented Apr 22, 2026

@SAY-5 I think we need to give credit here to @kaovilai. Looking at the time when the #2109 was created. Could we close this one in favor of #2109 ?

@SAY-5 SAY-5 closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BSL validation should require region when s3Url is set to a non-AWS endpoint

3 participants