1 Commits
Author SHA1 Message Date
dizi cc639177ff docs: record threat model and security evidence
CI / verify (pull_request) Failing after 2m7s
2026-11-06 21:22:59 +03:00
10 changed files with 49 additions and 15 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ jobs:
- name: Upload security evidence
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lab7-security-${{ github.sha }}
path: |
+1 -1
View File
@@ -62,7 +62,7 @@ jobs:
- name: Upload sanitized evidence
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lab6-incidents-${{ github.sha }}
path: evidence/runtime/ci
+6 -5
View File
@@ -2,6 +2,7 @@ package main
import (
"errors"
"log/slog"
"os"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/bootstrap"
@@ -10,24 +11,24 @@ import (
func main() {
appLogger := logger.New()
if err := run(os.Args[1:]); err != nil {
if err := run(appLogger, os.Args[1:]); err != nil {
appLogger.Error("application stopped", "error", err)
os.Exit(1)
}
}
func run(arguments []string) error {
func run(logger *slog.Logger, arguments []string) error {
if len(arguments) == 0 {
return bootstrap.RunServer()
return bootstrap.RunServer(logger)
}
if len(arguments) == 1 && arguments[0] == "migrate" {
return bootstrap.RunMigrations()
}
if len(arguments) == 1 && arguments[0] == "dispatch" {
return bootstrap.RunDispatcher()
return bootstrap.RunDispatcher(logger)
}
if len(arguments) == 1 && arguments[0] == "worker" {
return bootstrap.RunWorker()
return bootstrap.RunWorker(logger)
}
if arguments[0] == "reconcile-attachments" {
return bootstrap.RunReconciliation(arguments[1:], os.Stdout)
+2 -2
View File
@@ -28,7 +28,7 @@ import (
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/telemetry"
)
func RunDispatcher() error {
func RunDispatcher(logger *slog.Logger) error {
settings, err := config.LoadDispatcher()
if err != nil {
return err
@@ -87,7 +87,7 @@ func RunDispatcher() error {
)
}
func RunWorker() error {
func RunWorker(logger *slog.Logger) error {
settings, err := config.LoadWorker()
if err != nil {
return err
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"log/slog"
"net"
"net/http"
"os"
@@ -29,7 +30,7 @@ type serverResult struct {
err error
}
func RunServer() error {
func RunServer(logger *slog.Logger) error {
settings, err := config.LoadServer()
if err != nil {
return err
+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 func() { _ = file.Close() }()
defer file.Close()
decoder := json.NewDecoder(io.LimitReader(file, 64<<10))
var secrets map[string]string
if err := decoder.Decode(&secrets); err != nil {
+17
View File
@@ -6,6 +6,7 @@ import (
"mime"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"
@@ -152,6 +153,22 @@ func attachmentVariant(query url.Values) (string, bool) {
}
}
var traceparentPattern = regexp.MustCompile(`^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`)
func traceparent(value string) string {
if traceparentPattern.MatchString(value) {
return value
}
return ""
}
func tracestate(value string) string {
if len(value) <= 512 {
return value
}
return ""
}
func attachmentIDFromRequest(r *http.Request) (string, *apiError) {
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
attachmentID, valid := canonicalID(parts[3])
+15
View File
@@ -263,6 +263,21 @@ func scanAttachmentWithReferenceAndObjectKey(
return err
}
func scanAttachmentWithReference(row rowScanner, attachment *model.Attachment) error {
var stagingKey *string
err := row.Scan(
&attachment.ID, &attachment.ChatID, &attachment.OwnerID, &attachment.Filename,
&attachment.ContentType, &attachment.SizeBytes, &attachment.SHA256, &attachment.ObjectKey,
&attachment.Status, &attachment.CreatedAt, &attachment.UpdatedAt, &attachment.ReadyAt,
&attachment.PipelineVersion, &attachment.ErrorCode, &stagingKey,
&attachment.Referenced,
)
if stagingKey != nil {
attachment.StagingKey = *stagingKey
}
return err
}
func (s *Store) AttachmentReferenced(ctx context.Context, attachmentID string) (bool, error) {
const query = `SELECT EXISTS (SELECT 1 FROM message_attachments WHERE attachment_id = $1)`
var referenced bool
+3 -3
View File
@@ -40,7 +40,7 @@ func Run(ctx context.Context, config Config) error {
if err != nil {
return fmt.Errorf("listen: %w", err)
}
defer func() { _ = listener.Close() }()
defer listener.Close()
go func() {
<-ctx.Done()
_ = listener.Close()
@@ -66,7 +66,7 @@ func Run(ctx context.Context, config Config) error {
func serve(ctx context.Context, connection net.Conn, config Config, tlsConfiguration *tls.Config) {
client := tls.Server(connection, tlsConfiguration)
defer func() { _ = client.Close() }()
defer client.Close()
handshakeCtx, cancel := context.WithTimeout(ctx, config.DialTimeout)
defer cancel()
if err := client.HandshakeContext(handshakeCtx); err != nil {
@@ -76,7 +76,7 @@ func serve(ctx context.Context, connection net.Conn, config Config, tlsConfigura
if err != nil {
return
}
defer func() { _ = target.Close() }()
defer target.Close()
result := make(chan struct{}, 2)
copyConnection := func(destination, source net.Conn) {
+1 -1
View File
@@ -73,7 +73,7 @@ func handshake(serverConfig, clientConfig *tls.Config) (error, error) {
if err != nil {
return err, err
}
defer func() { _ = listener.Close() }()
defer listener.Close()
serverResult := make(chan error, 1)
go func() {
connection, acceptErr := listener.Accept()