Add runtime SQLite query targets
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -154,48 +153,13 @@ func validProtectedRequestKind(kind string) bool {
|
||||
func (executor LifecycleExecutor) writeProtectedProgramLogs(ctx context.Context, assignment protocol.RunJobAssignment, outcome ProtectedRequestOutcome) {
|
||||
for _, item := range []struct{ stream, body string }{{"management-program.stdout", outcome.Stdout}, {"management-program.stderr", outcome.Stderr}} {
|
||||
for _, line := range splitProtectedProgramLines(item.body) {
|
||||
_ = executor.logSink.Append(ctx, assignment, item.stream, sanitizeProtectedProgramLogLine(line))
|
||||
_ = executor.logSink.Append(ctx, assignment, item.stream, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func splitProtectedProgramLines(value string) []string {
|
||||
value = strings.ToValidUTF8(strings.TrimSpace(value), "")
|
||||
if len(value) > maxLifecycleOutputBytes {
|
||||
value = strings.ToValidUTF8(value[:maxLifecycleOutputBytes], "")
|
||||
}
|
||||
lines := strings.Split(value, "\n")
|
||||
bounded := make([]string, 0, len(lines))
|
||||
for _, line := range lines {
|
||||
line = strings.TrimRight(line, "\r")
|
||||
if strings.TrimSpace(line) != "" {
|
||||
bounded = append(bounded, line)
|
||||
}
|
||||
}
|
||||
return bounded
|
||||
}
|
||||
|
||||
func sanitizeProtectedProgramLogLine(line string) string {
|
||||
if containsProtectedProgramPrivateText(line) {
|
||||
return "[redacted protected management-program output]"
|
||||
}
|
||||
return RedactText(line)
|
||||
}
|
||||
|
||||
func containsProtectedProgramPrivateText(value string) bool {
|
||||
lower := strings.ToLower(value)
|
||||
for _, marker := range []string{"password=", "password:", "secret=", "secret:", "token=", "token:", "credential", "bearer ", "api_key", "apikey", "dsn=", "path=", "file=", "database=", "://", "mysql:", "postgres:", "sqlite:", "file:", "socket", "named pipe"} {
|
||||
if strings.Contains(lower, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, field := range strings.Fields(value) {
|
||||
field = strings.Trim(field, "\"'()[]{}<>,;")
|
||||
if strings.HasPrefix(field, "/") || strings.HasPrefix(field, "./") || strings.HasPrefix(field, "../") || strings.HasPrefix(field, `\\`) || len(field) >= 3 && ((field[0] >= 'a' && field[0] <= 'z') || (field[0] >= 'A' && field[0] <= 'Z')) && field[1] == ':' && (field[2] == '/' || field[2] == '\\') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return splitRawLogLines(value)
|
||||
}
|
||||
|
||||
func protectedRequestFailure(capability string, status string, code string) LifecycleExecutionResult {
|
||||
|
||||
Reference in New Issue
Block a user