gregtwallace / certwarden

Cert Warden is a centralized ACME Client. It provides an API for certificate consumers to fetch their individual keys and certs with API keys.
https://www.certwarden.com/
Other
176 stars 6 forks source link

Backup Before Config File Upgrade Triggers nil-deref #41

Closed mp3-10 closed 6 months ago

mp3-10 commented 6 months ago

Hello, After upgrade, I have this error. Do you have maybe any idea what cause it?

panic: runtime error: invalid memory address or nil pointer dereference                                                                                                              [0/452][signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9be929]                                                                                                                                                                                                                                                                                                                  goroutine 1 [running]:                                                                                                                                                                      legocerthub-backend/pkg/domain/app/backup.(*Service).CreateBackupOnDisk(0xc0000625c0)                                                                                                               /src/pkg/domain/app/backup/fileops_backup.go:150 +0x1e9                                                                                                                             legocerthub-backend/pkg/domain/app.(*Application).CreateBackupOnDisk(...)                                                                                                                           /src/pkg/domain/app/app.go:108                                                                                                                                                      legocerthub-backend/pkg/domain/app.(*Application).loadConfigFile(0xc0000000c0)                                                                                                                      /src/pkg/domain/app/configure.go:165 +0x6a5                                                                                                                                         legocerthub-backend/pkg/domain/app.create()                                                                                                                                                         /src/pkg/domain/app/app_create.go:67 +0x311                                                                                                                                         legocerthub-backend/pkg/domain/app.run()                                                                                                                                                            /src/pkg/domain/app/run.go:62 +0x5e                                                                                                                                                 legocerthub-backend/pkg/domain/app.RunLeGoAPI()                                                                                                                                                     /src/pkg/domain/app/run.go:23 +0x17                                                                                                                                                 main.main()                                                                                                                                                                                         /src/cmd/api-server/main.go:8 +0xf                                                                                                                                                  2024-01-02T10:09:24.309Z        info    app/logger.go:138       init logging started (log level: debug)                                                                                     2024-01-02T10:09:24.311Z        info    app/app_create.go:39    starting LeGo CertHub v0.17.2                                                                                               2024-01-02T10:09:24.333Z        info    backup/fileops_backup.go:148    backup saved to disk (lego_certhub_backup.2024-01-02T10--09--24Z.zip)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9be929]

goroutine 1 [running]:
legocerthub-backend/pkg/domain/app/backup.(*Service).CreateBackupOnDisk(0xc00006a5c0)
        /src/pkg/domain/app/backup/fileops_backup.go:150 +0x1e9
legocerthub-backend/pkg/domain/app.(*Application).CreateBackupOnDisk(...)
        /src/pkg/domain/app/app.go:108
legocerthub-backend/pkg/domain/app.(*Application).loadConfigFile(0xc0000000c0)
        /src/pkg/domain/app/configure.go:165 +0x6a5
legocerthub-backend/pkg/domain/app.create()
        /src/pkg/domain/app/app_create.go:67 +0x311
legocerthub-backend/pkg/domain/app.run()
        /src/pkg/domain/app/run.go:62 +0x5e
legocerthub-backend/pkg/domain/app.RunLeGoAPI()
        /src/pkg/domain/app/run.go:23 +0x17
main.main()
        /src/cmd/api-server/main.go:8 +0xf

IN lego-certhub.log nothing special:

{"level":"info","ts":"2024-01-02T10:07:23.199Z","caller":"app/logger.go:138","msg":"init logging started (log level: debug)"},                                                              {"level":"info","ts":"2024-01-02T10:07:23.199Z","caller":"app/app_create.go:39","msg":"starting LeGo CertHub v0.17.2"},                                                                     {"level":"info","ts":"2024-01-02T10:07:23.219Z","caller":"backup/fileops_backup.go:148","msg":"backup saved to disk (lego_certhub_backup.2024-01-02T10--07--23Z.zip)"},                     {"level":"info","ts":"2024-01-02T10:08:23.767Z","caller":"app/logger.go:138","msg":"init logging started (log level: debug)"},                                                              {"level":"info","ts":"2024-01-02T10:08:23.767Z","caller":"app/app_create.go:39","msg":"starting LeGo CertHub v0.17.2"},                                                                     {"level":"info","ts":"2024-01-02T10:08:23.787Z","caller":"backup/fileops_backup.go:148","msg":"backup saved to disk (lego_certhub_backup.2024-01-02T10--08--23Z.zip)"},                     {"level":"info","ts":"2024-01-02T10:09:24.309Z","caller":"app/logger.go:138","msg":"init logging started (log level: debug)"},                                                              {"level":"info","ts":"2024-01-02T10:09:24.311Z","caller":"app/app_create.go:39","msg":"starting LeGo CertHub v0.17.2"},                                                                     {"level":"info","ts":"2024-01-02T10:09:24.333Z","caller":"backup/fileops_backup.go:148","msg":"backup saved to disk (lego_certhub_backup.2024-01-02T10--09--24Z.zip)"},                     {"level":"info","ts":"2024-01-02T10:10:24.923Z","caller":"app/logger.go:138","msg":"init logging started (log level: debug)"},                                                              {"level":"info","ts":"2024-01-02T10:10:24.924Z","caller":"app/app_create.go:39","msg":"starting LeGo CertHub v0.17.2"},                                                                     {"level":"info","ts":"2024-01-02T10:10:24.953Z","caller":"backup/fileops_backup.go:148","msg":"backup saved to disk (lego_certhub_backup.2024-01-02T10--10--24Z.zip)"},                     {"level":"info","ts":"2024-01-02T10:11:25.505Z","caller":"app/logger.go:138","msg":"init logging started (log level: debug)"},                                                              {"level":"info","ts":"2024-01-02T10:11:25.506Z","caller":"app/app_create.go:39","msg":"starting LeGo CertHub v0.17.2"},                                                                     {"level":"info","ts":"2024-01-02T10:11:25.533Z","caller":"backup/fileops_backup.go:148","msg":"backup saved to disk (lego_certhub_backup.2024-01-02T10--11--25Z.zip)"}, 
mp3-10 commented 6 months ago

Solved by me :)

But for next affected person, small description how to solve.

In before versions of the great tool like LegoCertHub, config file parameters was without ' So you have to modify your old config file.

Example: Before:

http_port: 4050
https_port: 4055
log_level: debug

After:

'http_port': 4050
'https_port': 4055
'log_level': 'debug'
gregtwallace commented 6 months ago

I looked at this because there should never be a nil deref (in good code, anyway). This actually is a bug. I'm going to guess when you edited the config file you also updated the file version number which would have bypassed the bug.

Appreciate the report. I'll get a fix out soon.

edit to add: quoting in YAML is strongly encouraged, so you made a good change regardless :)