diff --git a/go.mod b/go.mod index 82ded69..719a6e2 100644 --- a/go.mod +++ b/go.mod @@ -20,10 +20,10 @@ require ( github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 github.com/charmbracelet/x/exp/teatest v0.0.0-20261011004359-2acd7e345453 github.com/jackc/pgx/v5 v5.11.0 - github.com/newstack-cloud/bluelink/libs/blueprint v0.56.0 - github.com/newstack-cloud/bluelink/libs/blueprint-state v0.12.0 + github.com/newstack-cloud/bluelink/libs/blueprint v0.57.0 + github.com/newstack-cloud/bluelink/libs/blueprint-state v0.13.1 github.com/newstack-cloud/bluelink/libs/common v0.6.0 - github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.5.2 + github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.6.0 github.com/spf13/afero v1.15.0 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 diff --git a/go.sum b/go.sum index d68c3d2..fa7dd2e 100644 --- a/go.sum +++ b/go.sum @@ -264,14 +264,14 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= -github.com/newstack-cloud/bluelink/libs/blueprint v0.56.0 h1:Mb5aNDFaayXhxKW+VpicqiBYs56zzk9XieXEMopp83o= -github.com/newstack-cloud/bluelink/libs/blueprint v0.56.0/go.mod h1:IzAGdeIgsxVNhqa6fO0wmkD8xbTviEruMgHgXk33j2k= -github.com/newstack-cloud/bluelink/libs/blueprint-state v0.12.0 h1:p6WoKlDd/+btlivd89gLfOhAlg6/8z4f4W6pWoPHQQw= -github.com/newstack-cloud/bluelink/libs/blueprint-state v0.12.0/go.mod h1:Wqd5tZicpwwVOqKEJj4/oyNhEyxvf/frFIWgMEfthOM= +github.com/newstack-cloud/bluelink/libs/blueprint v0.57.0 h1:rR2uq9HFvBP9hoP2PehWPsjiYzQ6WaYmHCjAJ7TDeXw= +github.com/newstack-cloud/bluelink/libs/blueprint v0.57.0/go.mod h1:IzAGdeIgsxVNhqa6fO0wmkD8xbTviEruMgHgXk33j2k= +github.com/newstack-cloud/bluelink/libs/blueprint-state v0.13.1 h1:YQl/wRThtElL03HiqkiVbszT7VdNX424wcEZs+4Q7gs= +github.com/newstack-cloud/bluelink/libs/blueprint-state v0.13.1/go.mod h1:Wqd5tZicpwwVOqKEJj4/oyNhEyxvf/frFIWgMEfthOM= github.com/newstack-cloud/bluelink/libs/common v0.6.0 h1:sITqsLAkYUbNmwuVuJ1/M8uzloZ4k56OcVPfgiwx0G4= github.com/newstack-cloud/bluelink/libs/common v0.6.0/go.mod h1:a8xXIgLy0loEE/62oaiGyGxFH7z63xUefLnzZZRk8Gs= -github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.5.2 h1:REoQW+smduR0tzb7G8/tu4e8ouLpvcUxh2jn5dsCXCI= -github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.5.2/go.mod h1:9GboMmne4TYv9cbsenYnqCt4wIu4z1tEf0CxKzoIf8o= +github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.6.0 h1:/lHT9SnEpJ31LkMxB86pd++yeGOLsbkRl9dzViJETY8= +github.com/newstack-cloud/bluelink/libs/deploy-engine-client v0.6.0/go.mod h1:I3piCSmuwnG4DPtPoMNFkKFvXOiITy4Sg7sPpEWJ73k= github.com/pierrec/lz4/v4 v4.1.28 h1:pPEPwRJ4kybBTfGt28q7lQsRJQHhC08axprdLD5Ppio= github.com/pierrec/lz4/v4 v4.1.28/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= diff --git a/stateio/backend.go b/stateio/backend.go index 9ee4d89..e0ebfbd 100644 --- a/stateio/backend.go +++ b/stateio/backend.go @@ -11,6 +11,7 @@ import ( "github.com/newstack-cloud/bluelink/libs/blueprint-state/postgres" "github.com/newstack-cloud/bluelink/libs/blueprint/core" "github.com/newstack-cloud/bluelink/libs/blueprint/state" + "github.com/newstack-cloud/bluelink/libs/common/crypto" "github.com/spf13/afero" ) @@ -152,13 +153,22 @@ func wrapMemfileLoadError(config *StateConfig, err error) error { } } + if errors.Is(err, crypto.ErrNotEnvelope) { + return &StateAccessError{ + Code: ErrCodeStateDecryptionFailed, + Message: "some of the state is not encrypted", + Hint: "Some state files are not encrypted, usually because they were written before " + + "encryption was enabled. Encrypt them by running bluelink-deploy-engine reencrypt-state " + + "with the deploy engine stopped.", + Err: err, + } + } + return &StateAccessError{ Code: ErrCodeStateDecryptionFailed, Message: "the state could not be decrypted", Hint: "Check that the configured key is the one this state was encrypted with. " + - "If the key has been rotated, list the old key under state.encryption.previous_keys. " + - "If the state was written before encryption was enabled, encrypt it with the " + - "deploy engine's reencrypt-state command.", + "If the key has been rotated, list the old key under state.encryption.previous_keys.", Err: err, } } diff --git a/stateio/encryption_test.go b/stateio/encryption_test.go index 12dcde6..5f5875d 100644 --- a/stateio/encryption_test.go +++ b/stateio/encryption_test.go @@ -19,9 +19,10 @@ const ( encryptionConfigHint = "Check state.encryption in the deploy engine config, and any " + "BLUELINK_DEPLOY_ENGINE_STATE_ENCRYPTION_* environment variables." stateDecryptionHint = "Check that the configured key is the one this state was encrypted with. " + - "If the key has been rotated, list the old key under state.encryption.previous_keys. " + - "If the state was written before encryption was enabled, encrypt it with the " + - "deploy engine's reencrypt-state command." + "If the key has been rotated, list the old key under state.encryption.previous_keys." + notEncryptedStateHint = "Some state files are not encrypted, usually because they were written " + + "before encryption was enabled. Encrypt them by running bluelink-deploy-engine " + + "reencrypt-state with the deploy engine stopped." plaintextExportWarning = "State is encrypted at rest but the export file is not; it can contain " + "resolved secrets, so encrypt the export or store it securely and remove it once it is no " + "longer needed" @@ -198,12 +199,8 @@ func (s *StateEncryptionTestSuite) Test_suggests_reencrypting_state_written_befo s.assertStateAccessError(err, ErrCodeStateDecryptionFailed) explanation := ExplainError(err) - s.Equal( - `"/test/state/instance_index.json" is not encrypted, so this state was written before `+ - "encryption was enabled; re-encrypt the state directory or start from an empty one", - explanation.Cause, - ) - s.Equal(stateDecryptionHint, explanation.Hint) + s.Equal("some of the state is not encrypted", explanation.Summary) + s.Equal(notEncryptedStateHint, explanation.Hint) } func (s *StateEncryptionTestSuite) Test_a_refused_import_leaves_an_empty_encrypted_store_without_a_salt() {