Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
fix(controlplane): fallback CAS downloads from invalid backends#3255
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -72,6 +72,62 @@ func (s *casBackendTestSuite) TestFindDefaultBackendFound() { | ||
| assert.Equal(backend, wantBackend) | ||
| } | ||
| func (s *casBackendTestSuite) TestFindDownloadBackend() { | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ctx := context.Background() | ||
| mapped := &biz.CASBackend{ID: uuid.New(), OrganizationID: s.validUUID, ValidationStatus: biz.CASBackendValidationOK} | ||
| got, err := s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Require().NoError(err) | ||
| s.Same(mapped, got) | ||
| s.resetMock() | ||
| mapped.ValidationStatus = biz.CASBackendValidationFailed | ||
| defaultBackend := &biz.CASBackend{ID: uuid.New(), ValidationStatus: biz.CASBackendValidationOK} | ||
| s.repo.On("FindDefaultBackend", mock.Anything, s.validUUID).Return(defaultBackend, nil).Once() | ||
| got, err = s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Require().NoError(err) | ||
| s.Same(defaultBackend, got) | ||
| s.resetMock() | ||
| defaultBackend.ValidationStatus = biz.CASBackendValidationFailed | ||
| fallbackBackend := &biz.CASBackend{ID: uuid.New(), ValidationStatus: biz.CASBackendValidationOK} | ||
| s.repo.On("FindDefaultBackend", mock.Anything, s.validUUID).Return(defaultBackend, nil).Once() | ||
| s.repo.On("FindFallbackBackend", mock.Anything, s.validUUID).Return(fallbackBackend, nil).Once() | ||
| got, err = s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Require().NoError(err) | ||
| s.Same(fallbackBackend, got) | ||
| got, err = s.useCase.FindDownloadBackend(ctx, nil) | ||
| s.Nil(got) | ||
| s.True(biz.IsNotFound(err)) | ||
| s.resetMock() | ||
| s.repo.On("FindDefaultBackend", mock.Anything, s.validUUID).Return(nil, nil).Once() | ||
| got, err = s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Nil(got) | ||
| s.True(biz.IsNotFound(err)) | ||
| s.resetMock() | ||
| s.repo.On("FindDefaultBackend", mock.Anything, s.validUUID).Return(defaultBackend, nil).Once() | ||
| s.repo.On("FindFallbackBackend", mock.Anything, s.validUUID).Return(nil, nil).Once() | ||
| got, err = s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Nil(got) | ||
| s.True(biz.IsNotFound(err)) | ||
| s.resetMock() | ||
| fallbackBackend.ValidationStatus = biz.CASBackendValidationFailed | ||
| s.repo.On("FindDefaultBackend", mock.Anything, s.validUUID).Return(defaultBackend, nil).Once() | ||
| s.repo.On("FindFallbackBackend", mock.Anything, s.validUUID).Return(fallbackBackend, nil).Once() | ||
| got, err = s.useCase.FindDownloadBackend(ctx, mapped) | ||
| s.Nil(got) | ||
| s.True(biz.IsErrValidation(err)) | ||
| } | ||
| func (s *casBackendTestSuite) TestSaveInvalidUUID() { | ||
| repo, err := s.useCase.CreateOrUpdate(context.Background(), s.invalidUUID, "", "", "", backendType, true) | ||
| assert.True(s.T(), biz.IsErrInvalidUUID(err)) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this meethod is correct since it checks default, not just fallback, do we want to also check default?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, default-first is intentional here.
CAS mappings are historical (
digest -> backend ID). The issue scenario is credential rotation by creating a new backend pointing at the same storage location and making it the org default, while old mappings still point at the backend with revoked credentials.So for downloads, when the mapped backend is invalid, we try the org's current default backend first, then the configured fallback. This is safe because the CAS download path verifies the content digest; if the default backend does not contain the exact artifact, the download fails.
I added a code comment to make this intent explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replacement backend is typically made the organization default, so we need to check it before the fallback.