chore: finalize lab7 security verification
CI / verify (pull_request) Successful in 14m53s

This commit is contained in:
2026-11-06 22:00:42 +03:00
parent 5ac64f51fa
commit a8edaf058d
53 changed files with 1130 additions and 224 deletions
+54 -48
View File
@@ -12,53 +12,54 @@ import (
)
type ServerConfig struct {
Address string
HealthAddress string
MetricsAddress string
TLSCAPath string
TLSCertificatePath string
TLSPrivateKeyPath string
TLSAllowedClientURI string
TLSAllowedMetricsClientURI string
DatabaseURL string
CacheURL string
CacheTLS ClientTLSConfig
SessionTTL time.Duration
IdempotencyTTL time.Duration
LoginRateLimitAccountAttempts int
LoginRateLimitSourceAttempts int
LoginRateLimitWindow time.Duration
DBMaxConns int32
DBMinConns int32
DBMaxConnectionAge time.Duration
DBMaxConnectionIdle time.Duration
DBHealthCheckPeriod time.Duration
DependencyTimeout time.Duration
RequestTimeout time.Duration
HTTPReadHeaderTimeout time.Duration
HTTPReadTimeout time.Duration
HTTPWriteTimeout time.Duration
HTTPIdleTimeout time.Duration
HTTPShutdownTimeout time.Duration
PasswordMemoryKiB uint32
PasswordIterations uint32
PasswordParallelism uint8
PasswordSaltLength uint32
PasswordKeyLength uint32
SwaggerPort string
S3Endpoint string
S3Region string
S3Bucket string
S3AccessKey string
S3SecretKey string
S3UseTLS bool
S3CAPath string
S3Timeout time.Duration
AttachmentMaxBytes int64
AttachmentMaxPixels int64
AttachmentBodyMemory int64
AttachmentDecodeMemory int64
PipelineVersion int
Address string
HealthAddress string
MetricsAddress string
TLSCAPath string
TLSCertificatePath string
TLSPrivateKeyPath string
TLSAllowedClientURI string
TLSAllowedMetricsClientURI string
DatabaseURL string
CacheURL string
CacheTLS ClientTLSConfig
SessionTTL time.Duration
IdempotencyTTL time.Duration
LoginRateLimitAccountAttempts int
LoginRateLimitSourceAttempts int
LoginRateLimitWindow time.Duration
DBMaxConns int32
DBMinConns int32
DBMaxConnectionAge time.Duration
DBMaxConnectionIdle time.Duration
DBHealthCheckPeriod time.Duration
DependencyTimeout time.Duration
RequestTimeout time.Duration
HTTPReadHeaderTimeout time.Duration
HTTPReadTimeout time.Duration
HTTPWriteTimeout time.Duration
HTTPIdleTimeout time.Duration
HTTPShutdownTimeout time.Duration
PasswordMemoryKiB uint32
PasswordIterations uint32
PasswordParallelism uint8
PasswordSaltLength uint32
PasswordKeyLength uint32
PasswordMaxConcurrentOperations int
SwaggerPort string
S3Endpoint string
S3Region string
S3Bucket string
S3AccessKey string
S3SecretKey string
S3UseTLS bool
S3CAPath string
S3Timeout time.Duration
AttachmentMaxBytes int64
AttachmentMaxPixels int64
AttachmentBodyMemory int64
AttachmentDecodeMemory int64
PipelineVersion int
}
type MigrationConfig struct {
@@ -251,6 +252,10 @@ func LoadServer() (ServerConfig, error) {
if err != nil {
return ServerConfig{}, err
}
passwordMaxConcurrentOperations, err := integer(values, "server.password.max_concurrent_operations", 1, 64)
if err != nil {
return ServerConfig{}, err
}
swaggerPort, err := requiredPort(values, "server.swagger_port")
if err != nil {
return ServerConfig{}, err
@@ -306,7 +311,8 @@ func LoadServer() (ServerConfig, error) {
HTTPShutdownTimeout: shutdownTimeout, PasswordMemoryKiB: uint32(passwordMemory),
PasswordIterations: uint32(passwordIterations), PasswordParallelism: uint8(passwordParallelism),
PasswordSaltLength: uint32(passwordSaltLength), PasswordKeyLength: uint32(passwordKeyLength),
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
PasswordMaxConcurrentOperations: passwordMaxConcurrentOperations,
SwaggerPort: swaggerPort, S3Endpoint: storage.endpoint, S3Region: storage.region, S3Bucket: storage.bucket,
S3AccessKey: storage.accessKey, S3SecretKey: storage.secretKey,
S3UseTLS: storage.useTLS, S3CAPath: storage.caPath, S3Timeout: storage.timeout,
AttachmentMaxBytes: int64(attachmentMaxBytes), AttachmentMaxPixels: int64(attachmentMaxPixels),
+2
View File
@@ -59,6 +59,7 @@ func TestLoadServerLoadsTLSAndHealthSettings(t *testing.T) {
require.Equal(t, 5, settings.LoginRateLimitAccountAttempts)
require.Equal(t, 20, settings.LoginRateLimitSourceAttempts)
require.Equal(t, time.Minute, settings.LoginRateLimitWindow)
require.Equal(t, 2, settings.PasswordMaxConcurrentOperations)
}
func TestLoadServerRejectsNonLoopbackHealthAddress(t *testing.T) {
@@ -152,6 +153,7 @@ server:
parallelism: 2
salt_length: 16
key_length: 32
max_concurrent_operations: 2
database:
min_connections: 0
max_connections: 4
+1 -1
View File
@@ -74,7 +74,7 @@ func loadSecretFile(values *viper.Viper, path string) error {
if err != nil {
return fmt.Errorf("open messenger secrets: %w", err)
}
defer file.Close()
defer func() { _ = file.Close() }()
decoder := json.NewDecoder(io.LimitReader(file, 64<<10))
var secrets map[string]string
if err := decoder.Decode(&secrets); err != nil {