lab7: при отказе S3 в credentials — внеочередное чтение секрета и повтор; Redis ACL api +decr (возврат слота лимита)

This commit is contained in:
2026-11-12 19:59:49 +03:00
parent 8041d5c02a
commit b862899b97
5 changed files with 140 additions and 4 deletions
+26
View File
@@ -0,0 +1,26 @@
package storage
import (
"errors"
"fmt"
"testing"
"github.com/minio/minio-go/v7"
)
func TestIsAuthError(t *testing.T) {
wrap := func(code string) error { return fmt.Errorf("s3 put: %w", minio.ErrorResponse{Code: code}) }
for code, want := range map[string]bool{
"InvalidAccessKeyId": true, // ключ удалён (отзыв)
"SignatureDoesNotMatch": true, // secret key сменён (ротация)
"AccessDenied": false, // отказ политики по префиксу — повтор не поможет
"NoSuchKey": false,
} {
if got := IsAuthError(wrap(code)); got != want {
t.Errorf("%s: got %v, want %v", code, got, want)
}
}
if IsAuthError(errors.New("dial tcp: connection refused")) || IsAuthError(nil) {
t.Error("non-S3 error classified as auth error")
}
}
+10
View File
@@ -74,6 +74,16 @@ func NewS3WithCreds(endpoint, region, bucket string, creds *credentials.Credenti
return &S3{client: c, bucket: bucket}, nil
}
// IsAuthError — S3 отверг credentials (ключ сменён или удалён). AccessDenied сюда не
// входит: это отказ политики по префиксу, повтор с тем же ключом его не исправит.
func IsAuthError(err error) bool {
var er minio.ErrorResponse
if !errors.As(err, &er) {
return false
}
return er.Code == "InvalidAccessKeyId" || er.Code == "SignatureDoesNotMatch"
}
func isNotFound(err error) bool {
code := minio.ToErrorResponse(err).Code
return code == "NoSuchKey" || code == "NotFound"