Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 13 additions & 3 deletions stateio/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
}
}
Expand Down
15 changes: 6 additions & 9 deletions stateio/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down
Loading