SecretsManager: Consolidation service and ability to run via cli (#108774)

* list all encrypted values and count

* separate interfaces

* add time filter to global queries

* initial secrets consolidation

* Revert defaults

* More verbose description of the operation

* Add consolidation tests and tracing

* Fix lint

* Revert debug log
This commit is contained in:
Dana Axinte
2025-07-31 14:45:59 +01:00
committed by GitHub
parent 9907191a7b
commit a3cdfce25a
10 changed files with 467 additions and 19 deletions
+12
View File
@@ -7,6 +7,7 @@ import (
"github.com/urfave/cli/v2"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/datamigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/secretsconsolidation"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/secretsmigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
@@ -184,6 +185,17 @@ var adminCommands = []*cli.Command{
},
},
},
{
Name: "secrets-consolidation",
Usage: "Runs an operation that re-encrypts all encrypted values in your database with new data keys",
Subcommands: []*cli.Command{
{
Name: "consolidate",
Usage: "Re-encrypts all encrypted values with new data keys and deletes the old deactivated data keys. Returns ok unless there is an error. Safe to execute multiple times.",
Action: runRunnerCommand(secretsconsolidation.ConsolidateSecrets),
},
},
},
}
var Commands = []*cli.Command{
@@ -0,0 +1,13 @@
package secretsconsolidation
import (
"context"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/server"
)
func ConsolidateSecrets(_ utils.CommandLine, runner server.Runner) error {
err := runner.SecretsConsolidationService.Consolidate(context.Background())
return err
}