Cannot set defaultCertificateId using stalwart-cli plan

Issue Description

When trying to apply a plan using stalwart-cli, I get the following error message:
error: SystemSettings: update failed for id singleton: error: invalidPatch | Failed to parse Id from string | Properties: defaultCertificateId

Expected Behavior

defaultCertificateId should apply without issues.

Actual Behavior

stalwart-cli fails with error: SystemSettings: update failed for id singleton: error: invalidPatch | Failed to parse Id from string | Properties: defaultCertificateId

Reproduction Steps

  1. Use stalwart-cli v1.0.10 and stalwart v0.16.13
  2. Attempt to apply following plan while stalwart is in recovery mode:
{"@type":"upsert","matchOn":["subjectAlternativeNames"],"object":"Certificate","value":{"certificate-i2evq3oqabaa":{"certificate":{"@type":"File","filePath":"/var/lib/acme/david-w.eu/fullchain.pem"},"privateKey":{"@type":"File","filePath":"/var/lib/acme/david-w.eu/key.pem"},"subjectAlternativeNames":{"*.david-w.eu":true,"david-w.eu":true}}}}
{"@type":"reconcile","matchOn":["key"],"object":"DnsServer","value":{"dnsserver-1":{"@type":"Tsig","description":"Knot DNS","host":"::1","key":{"@type":"File","filePath":"/run/credentials/stalwart.service/tsig-key"},"keyName":"stalwart","port":53,"protocol":"udp","tsigAlgorithm":"hmac-sha512"}}}
{"@type":"reconcile","matchOn":["name"],"object":"Domain","value":{"domain-1":{"certificateManagement":{"@type":"Manual"},"description":"Default","dkimManagement":{"@type":"Automatic"},"dnsManagement":{"@type":"Automatic","dnsServerId":"#dnsserver-1"},"name":"david-w.eu"}}}
{"@type":"reconcile","matchOn":["name"],"object":"NetworkListener","value":{"listener-1":{"bind":{"[::1]:8087":true},"name":"https","protocol":"http","tlsImplicit":true,"useTls":true},"listener-2":{"bind":{"[::]:25":true},"name":"smtp","protocol":"smtp","useTls":true},"listener-3":{"bind":{"[::]:465":true},"name":"smtps","protocol":"smtp","tlsImplicit":true,"useTls":true},"listener-4":{"bind":{"[::]:993":true},"name":"imaps","protocol":"imap","tlsImplicit":true,"useTls":true},"listener-5":{"bind":{"[::]:4190":true},"name":"sieve","protocol":"manageSieve","tlsImplicit":true,"useTls":true}}}
{"@type":"reconcile","matchOn":["name"],"object":"Account","value":{"account-1":{"@type":"User","credentials":{"0":{"@type":"Password","secret":"****"}},"description":"David Wronek","domainId":"#domain-1","name":"moe","roles":{"@type":"Admin"}}}}
{"@type":"update","object":"SystemSettings","value":{"defaultCertificateId":"#certificate-i2evq3oqabaa","defaultDomainId":"#domain-1","defaultHostname":"mail.david-w.eu"}}
{"@type":"update","object":"Http","value":{"enableHsts":true,"useXForwarded":true}}                                                                                

Relevant Log Output

Plan: 0 destroy, 2 update, 0 create, 1 upsert, 4 reconcile (9 objects)
✓ upserted Certificate (1)
✓ reconciled DnsServer (1)
✓ reconciled Domain (1)
✓ reconciled NetworkListener (5)
✓ reconciled Account (1)
✗ update SystemSettings: SystemSettings: update failed for id singleton: error: invalidPatch |   Failed to parse Id from string |   Properties: defaultCertificateId
Done: 0 destroyed, 8 updated, 1 created (1 failed)
error: SystemSettings: update failed for id singleton: error: invalidPatch |   Failed to parse Id from string |   Properties: defaultCertificateId

Stalwart Version

v0.16.x

Installation Method

NixOS

Database Backend

PostgreSQL

Blob Storage

PostgreSQL

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Please add information whether or not --rawfield is being used.

Reason for that request: Cannot update certificate via stalwart-cli - #4 by jeremiahcfoster

Hi stappers,

thanks for your reply.

I don’t use `–rawfile`. The command I use is the following:
`stalwart-cli apply --file stalwart-plan.ndjson`

Best regards
David

Acknowledge.

I zoomed in on the last two lines of stalwart-plan.ndjson

stappers@messer:/dev/shm/temp
$ cat the_update_lines 
{"@type":"update","object":"SystemSettings","value":{"defaultCertificateId":"#certificate-i2evq3oqabaa","defaultDomainId":"#domain-1","defaultHostname":"mail.david-w.eu"}}
{"@type":"update","object":"Http","value":{"enableHsts":true,"useXForwarded":true}}#                                                                                       
stappers@messer:/dev/shm/temp
$ 
stappers@messer:/dev/shm/temp
$ cat the_update_lines | jq
{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultCertificateId": "#certificate-i2evq3oqabaa",
    "defaultDomainId": "#domain-1",
    "defaultHostname": "mail.david-w.eu"
  }
}
{
  "@type": "update",
  "object": "Http",
  "value": {
    "enableHsts": true,
    "useXForwarded": true
  }
}
jq: parse error: Invalid numeric literal at line 2, column 85
$ $EDITOR the_update_lines 
stappers@messer:/dev/shm/temp
$ cat the_update_lines 
{"@type":"update","object":"SystemSettings","value":{"defaultCertificateId":"#certificate-i2evq3oqabaa","defaultDomainId":"#domain-1","defaultHostname":"mail.david-w.eu"}}
{"@type":"update","object":"Http","value":{"enableHsts":true,"useXForwarded":true}}
stappers@messer:/dev/shm/temp
$ cat the_update_lines | jq
{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultCertificateId": "#certificate-i2evq3oqabaa",
    "defaultDomainId": "#domain-1",
    "defaultHostname": "mail.david-w.eu"
  }
}
{
  "@type": "update",
  "object": "Http",
  "value": {
    "enableHsts": true,
    "useXForwarded": true
  }
}
stappers@messer:/dev/shm/temp
$

My prime suspect is the # in "defaultDomainId": "#domain-1",

My bad, there has been an issue while I pasted in the NDJSON plan.
I have fixed it now.

Regardless if I use the # character to reference to domain ID/certificate ID or not, I’m still getting the Failed to parse Id from string error message.

I did read that as further ideas are welcome.

Do apply with just this as file content:

{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultHostname": "mail.david-w.eu"
  }
}

Once again to understand update

{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultHostname": "mail.david-w.eu"
  }
}

Extend

{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultDomainId": "#domain-1",
    "defaultHostname": "mail.david-w.eu"
  }
}

And the original request:

{
  "@type": "update",
  "object": "SystemSettings",
  "value": {
    "defaultCertificateId": "#certificate-i2evq3oqabaa",
    "defaultDomainId": "#domain-1",
    "defaultHostname": "mail.david-w.eu"
  }
}

Try with --rawfile , that helped me.