Skip to content

feat: support storing, retrieving and refreshing encrypted secrets at account or asset level#2236

Open
nhoening wants to merge 4 commits into
mainfrom
feat/secrets-column
Open

feat: support storing, retrieving and refreshing encrypted secrets at account or asset level#2236
nhoening wants to merge 4 commits into
mainfrom
feat/secrets-column

Conversation

@nhoening

@nhoening nhoening commented Jun 13, 2026

Copy link
Copy Markdown
Member

Description

With this PR, secrets like refresh and access tokens can be stored on account or asset level in the db (encrypted).
This allows to stop saving them in configuration files as-is. This PR also adds supporting logic which manages token refresh cycles.

  • db migration for secrets field on account and asset level
  • Add secret utils for getting and setting encrypted secrets
  • also supprt token refresh operations
  • document this support
  • add CLI command flexmeasures edit secret
  • Added changelog item in documentation/changelog.rst

Look & Feel

None

How to test

I tested this in a plugin which connects to 3rd party platforms, by adding code which integrated with these new fields and utils. I added a login CLI command there, plus get_3rdparty_platform_access_token() helpers and explicit warnigns and errors.

Further Improvements

… account or asset level

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening added this to the 1.0.0 milestone Jun 13, 2026
@nhoening nhoening self-assigned this Jun 13, 2026
nhoening added 2 commits June 14, 2026 01:29
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
…on initialiation there

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
@nhoening nhoening requested a review from Flix6x June 14, 2026 00:48

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably some discussion points before proceeding?

Comment thread documentation/configuration.rst Outdated
Comment thread documentation/changelog.rst
Comment thread documentation/plugin/storing-platform-secrets.rst Outdated
Comment thread documentation/plugin/storing-platform-secrets.rst Outdated
Comment thread documentation/plugin/storing-platform-secrets.rst Outdated
Comment thread documentation/dev/connection-secrets.rst
Provider strategies
-------------------

Implement provider behavior behind a strategy interface. The core application

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? This came across to me as a very difficult to parse AI-written section.

(The linebreak pattern is a dead giveaway.)


Persist encrypted access tokens with an ``expires_at`` value in ``secrets`` if
they need to be reused across workers. The database then becomes the shared
coordination point. Use a refresh margin that expires before the token itself,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refresh margin?

Comment thread documentation/dev/connection-secrets.rst
Comment on lines +147 to +148
* Replace any cached access token after the durable secret update succeeds
* Keep enough error context to tell users that reconnecting may be required

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking that this PR might need CLI logic to rotate the FLEXMEASURES_SECRETS_ENCRYPTION_KEY key, updating secrets accordingly. That is, decrypting secrets that were encrypted using the old key, and encrypting them with the new key.

@nhoening

Copy link
Copy Markdown
Member Author

I was also thinking that this PR might need CLI logic to rotate the FLEXMEASURES_SECRETS_ENCRYPTION_KEY key, updating secrets accordingly. That is, decrypting secrets that were encrypted using the old key, and encrypting them with the new key.

I would suggest doing a follow-up PR for that.

…ove plugin docs section

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants