lab7: при отказе S3 в credentials — внеочередное чтение секрета и повтор; Redis ACL api +decr (возврат слота лимита)
This commit is contained in:
@@ -17,6 +17,8 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -116,7 +118,7 @@ func (p *Platform) Redis(ctx context.Context) (*redis.Client, error) {
|
||||
}
|
||||
|
||||
// S3 — TLS к MinIO, ключ сервиса из OpenBao.
|
||||
func (p *Platform) S3() (*storage.S3, error) {
|
||||
func (p *Platform) S3() (storage.Store, error) {
|
||||
if p.Secrets == nil {
|
||||
return storage.NewS3(p.Cfg.S3Endpoint, p.Cfg.S3Region, p.Cfg.S3Bucket, p.Cfg.S3AccessKey, p.Cfg.S3SecretKey)
|
||||
}
|
||||
@@ -124,8 +126,12 @@ func (p *Platform) S3() (*storage.S3, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storage.NewS3WithCreds(p.Cfg.S3Endpoint, p.Cfg.S3Region, p.Cfg.S3Bucket,
|
||||
st, err := storage.NewS3WithCreds(p.Cfg.S3Endpoint, p.Cfg.S3Region, p.Cfg.S3Bucket,
|
||||
credentials.New(&s3Provider{m: p.Secrets}), pool)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return authRetryStore{Store: st, m: p.Secrets}, nil
|
||||
}
|
||||
|
||||
// BrokerTLS — mTLS к RabbitMQ (пользователь = CN сертификата, SASL EXTERNAL).
|
||||
@@ -163,3 +169,73 @@ func (s *s3Provider) IsExpired() bool {
|
||||
defer s.mu.Unlock()
|
||||
return s.m.Version() != s.ver
|
||||
}
|
||||
|
||||
// authRetryStore: S3 отверг ключ (InvalidAccessKeyId/SignatureDoesNotMatch) →
|
||||
// внеочередное чтение секрета из OpenBao и один повтор, если версия сменилась.
|
||||
// Так ротация/отзыв ключа S3 (сначала MinIO, затем KV) не сжигает попытки работ
|
||||
// в окне до планового обновления секретов (SECRETS_REFRESH).
|
||||
type authRetryStore struct {
|
||||
storage.Store
|
||||
m *secrets.Manager
|
||||
}
|
||||
|
||||
func (s authRetryStore) retry(ctx context.Context, err error) bool {
|
||||
if err == nil || !storage.IsAuthError(err) {
|
||||
return false
|
||||
}
|
||||
changed := s.m.SyncNow(ctx)
|
||||
if changed {
|
||||
slog.Info("s3 credentials refreshed after auth error", "event", "secrets.s3_auth_retry", "version", s.m.Version())
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
func (s authRetryStore) Put(ctx context.Context, key string, r io.Reader, size int64, ct string) error {
|
||||
err := s.Store.Put(ctx, key, r, size, ct)
|
||||
if sk, ok := r.(io.Seeker); ok && s.retry(ctx, err) {
|
||||
if _, serr := sk.Seek(0, io.SeekStart); serr == nil {
|
||||
return s.Store.Put(ctx, key, r, size, ct)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s authRetryStore) Get(ctx context.Context, key string) (io.ReadCloser, int64, error) {
|
||||
rc, n, err := s.Store.Get(ctx, key)
|
||||
if s.retry(ctx, err) {
|
||||
return s.Store.Get(ctx, key)
|
||||
}
|
||||
return rc, n, err
|
||||
}
|
||||
|
||||
func (s authRetryStore) Stat(ctx context.Context, key string) (storage.Object, error) {
|
||||
o, err := s.Store.Stat(ctx, key)
|
||||
if s.retry(ctx, err) {
|
||||
return s.Store.Stat(ctx, key)
|
||||
}
|
||||
return o, err
|
||||
}
|
||||
|
||||
func (s authRetryStore) Delete(ctx context.Context, key string) error {
|
||||
err := s.Store.Delete(ctx, key)
|
||||
if s.retry(ctx, err) {
|
||||
return s.Store.Delete(ctx, key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s authRetryStore) Copy(ctx context.Context, src, dst string) error {
|
||||
err := s.Store.Copy(ctx, src, dst)
|
||||
if s.retry(ctx, err) {
|
||||
return s.Store.Copy(ctx, src, dst)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s authRetryStore) List(ctx context.Context, prefix string, fn func(storage.Object) error) error {
|
||||
err := s.Store.List(ctx, prefix, fn)
|
||||
if s.retry(ctx, err) {
|
||||
return s.Store.List(ctx, prefix, fn)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user