Skip to content

Commit 343f11c

Browse files
fix: address P0/P1 security and reliability issues in restic session backups
Security (P0): - Remove password from structured logs to prevent credential leakage to centralized log systems (Splunk, Datadog, etc.) Reliability (P1): - Add dependency checks for jq and flock before installing backup scripts - Add flock to prune script using same lock file as backup script to prevent concurrent runs and restic lock contention - Add ValidateResticDuration() to validate --keep-within input before script generation, preventing runtime prune failures - Deprecate --use-restic flag (restic is now mandatory) with clear warning message when user explicitly sets --use-restic=false Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 60c182e commit 343f11c

4 files changed

Lines changed: 1114 additions & 161 deletions

File tree

cmd/create/code.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ func init() {
8989
CreateCodeCmd.Flags().Bool("skip-session-backups", false, "Skip setting up automatic session backups")
9090
CreateCodeCmd.Flags().String("backup-interval", "hourly", "Session backup frequency: 30min, hourly, 6hours, daily")
9191

92+
// Restic backup flags
93+
CreateCodeCmd.Flags().Bool("use-restic", true, "[DEPRECATED] Restic is now mandatory; this flag is ignored")
94+
CreateCodeCmd.Flags().String("keep-within", "48h", "Keep all snapshots within this duration")
95+
CreateCodeCmd.Flags().Int("keep-hourly", 24, "Number of hourly snapshots to keep after keep-within")
96+
CreateCodeCmd.Flags().Int("keep-daily", 7, "Number of daily snapshots to keep")
97+
CreateCodeCmd.Flags().Int("keep-weekly", 4, "Number of weekly snapshots to keep")
98+
CreateCodeCmd.Flags().Int("keep-monthly", 12, "Number of monthly snapshots to keep")
99+
92100
// Network flags
93101
CreateCodeCmd.Flags().StringSlice("allowed-networks", []string{},
94102
"Additional CIDR ranges to allow SSH from (e.g., 203.0.113.0/24)")
@@ -171,6 +179,31 @@ func runCreateCode(rc *eos_io.RuntimeContext, cmd *cobra.Command, args []string)
171179
config.SessionBackupInterval = parseBackupInterval(backupInterval)
172180
}
173181

182+
// Restic backup flags
183+
if useRestic, err := cmd.Flags().GetBool("use-restic"); err == nil {
184+
config.UseRestic = useRestic
185+
}
186+
187+
if keepWithin, err := cmd.Flags().GetString("keep-within"); err == nil {
188+
config.ResticKeepWithin = keepWithin
189+
}
190+
191+
if keepHourly, err := cmd.Flags().GetInt("keep-hourly"); err == nil {
192+
config.ResticKeepHourly = keepHourly
193+
}
194+
195+
if keepDaily, err := cmd.Flags().GetInt("keep-daily"); err == nil {
196+
config.ResticKeepDaily = keepDaily
197+
}
198+
199+
if keepWeekly, err := cmd.Flags().GetInt("keep-weekly"); err == nil {
200+
config.ResticKeepWeekly = keepWeekly
201+
}
202+
203+
if keepMonthly, err := cmd.Flags().GetInt("keep-monthly"); err == nil {
204+
config.ResticKeepMonthly = keepMonthly
205+
}
206+
174207
// Windsurf-specific flags
175208
if skipConnCheck, err := cmd.Flags().GetBool("skip-connectivity-check"); err == nil {
176209
config.SkipConnectivityCheck = skipConnCheck

pkg/remotecode/install.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,21 @@ func Install(rc *eos_io.RuntimeContext, config *Config) (*InstallResult, error)
8989
}
9090
}
9191

92-
// INTERVENE - Set up session backups
92+
// INTERVENE - Set up session backups (restic-based with deduplication)
9393
if config.SetupSessionBackups && !config.SkipSessionBackups {
94-
logger.Info("Setting up coding session backups")
94+
logger.Info("Setting up coding session backups (restic)")
9595
backupConfig := &SessionBackupConfig{
9696
User: config.User,
9797
CronInterval: config.SessionBackupInterval,
9898
DryRun: config.DryRun,
99+
UseRestic: config.UseRestic,
100+
RetentionPolicy: &ResticRetentionPolicy{
101+
KeepWithin: config.ResticKeepWithin,
102+
KeepHourly: config.ResticKeepHourly,
103+
KeepDaily: config.ResticKeepDaily,
104+
KeepWeekly: config.ResticKeepWeekly,
105+
KeepMonthly: config.ResticKeepMonthly,
106+
},
99107
}
100108
backupResult, err := SetupSessionBackups(rc, backupConfig)
101109
if err != nil {

0 commit comments

Comments
 (0)