mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(database): add encryption support EE-1983 (#6316)
* bootstrap encryption key * secret key message change in cli and secret key file content trimmed * Migrate encryption code to latest version * pull in newer code * tidying up * working data encryption layer * fix tests * remove stray comment * fix a few minor issues and improve the comments * split out databasefilename with param to two methods to be more obvious * DB encryption integration (#6374) * json methods moved under DBConnection * store encryption fixed * cleaned * review comments addressed * newstore value fixed * backup test updated * logrus format config updated * Fix for newStore Co-authored-by: Matt Hook <hookenz@gmail.com> * Minor improvements * Improve the export code. Add missing webhook for import * rename HelmUserRepositorys to HelmUserRepositories * fix logging messages * when starting portainer with a key (first use) http is disabled by default. But when starting fresh without a key, http is enabled? * Fix bug for default settings on new installs Co-authored-by: Prabhat Khera <prabhat.khera@portainer.io> Co-authored-by: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com>
This commit is contained in:
parent
59ec22f706
commit
34cc8ea96a
22 changed files with 548 additions and 147 deletions
|
@ -363,118 +363,184 @@ func (store *Store) Export(filename string) (err error) {
|
|||
backup := storeExport{}
|
||||
|
||||
if c, err := store.CustomTemplate().CustomTemplates(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Custom Templates")
|
||||
}
|
||||
} else {
|
||||
backup.CustomTemplate = c
|
||||
}
|
||||
|
||||
if e, err := store.EdgeGroup().EdgeGroups(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Edge Groups")
|
||||
}
|
||||
} else {
|
||||
backup.EdgeGroup = e
|
||||
}
|
||||
|
||||
if e, err := store.EdgeJob().EdgeJobs(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Edge Jobs")
|
||||
}
|
||||
} else {
|
||||
backup.EdgeJob = e
|
||||
}
|
||||
|
||||
if e, err := store.EdgeStack().EdgeStacks(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Edge Stacks")
|
||||
}
|
||||
} else {
|
||||
backup.EdgeStack = e
|
||||
}
|
||||
|
||||
if e, err := store.Endpoint().Endpoints(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Endpoints")
|
||||
}
|
||||
} else {
|
||||
backup.Endpoint = e
|
||||
}
|
||||
|
||||
if e, err := store.EndpointGroup().EndpointGroups(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Endpoint Groups")
|
||||
}
|
||||
} else {
|
||||
backup.EndpointGroup = e
|
||||
}
|
||||
|
||||
if r, err := store.EndpointRelation().EndpointRelations(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Endpoint Relations")
|
||||
}
|
||||
} else {
|
||||
backup.EndpointRelation = r
|
||||
}
|
||||
|
||||
if r, err := store.ExtensionService.Extensions(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Extensions")
|
||||
}
|
||||
} else {
|
||||
backup.Extensions = r
|
||||
}
|
||||
if r, err := store.HelmUserRepository().HelmUserRepositorys(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
|
||||
if r, err := store.HelmUserRepository().HelmUserRepositories(); err != nil {
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Helm User Repositories")
|
||||
}
|
||||
} else {
|
||||
backup.HelmUserRepository = r
|
||||
}
|
||||
|
||||
if r, err := store.Registry().Registries(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Registries")
|
||||
}
|
||||
} else {
|
||||
backup.Registry = r
|
||||
}
|
||||
|
||||
if c, err := store.ResourceControl().ResourceControls(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Resource Controls")
|
||||
}
|
||||
} else {
|
||||
backup.ResourceControl = c
|
||||
}
|
||||
|
||||
if role, err := store.Role().Roles(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Roles")
|
||||
}
|
||||
} else {
|
||||
backup.Role = role
|
||||
}
|
||||
|
||||
if r, err := store.ScheduleService.Schedules(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Schedules")
|
||||
}
|
||||
} else {
|
||||
backup.Schedules = r
|
||||
}
|
||||
|
||||
if settings, err := store.Settings().Settings(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Settings")
|
||||
}
|
||||
} else {
|
||||
backup.Settings = *settings
|
||||
}
|
||||
|
||||
if settings, err := store.SSLSettings().Settings(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting SSL Settings")
|
||||
}
|
||||
} else {
|
||||
backup.SSLSettings = *settings
|
||||
}
|
||||
|
||||
if t, err := store.Stack().Stacks(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Stacks")
|
||||
}
|
||||
} else {
|
||||
backup.Stack = t
|
||||
}
|
||||
|
||||
if t, err := store.Tag().Tags(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Tags")
|
||||
}
|
||||
} else {
|
||||
backup.Tag = t
|
||||
}
|
||||
|
||||
if t, err := store.TeamMembership().TeamMemberships(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Team Memberships")
|
||||
}
|
||||
} else {
|
||||
backup.TeamMembership = t
|
||||
}
|
||||
|
||||
if t, err := store.Team().Teams(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Teams")
|
||||
}
|
||||
} else {
|
||||
backup.Team = t
|
||||
}
|
||||
|
||||
if info, err := store.TunnelServer().Info(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Tunnel Server")
|
||||
}
|
||||
} else {
|
||||
backup.TunnelServer = *info
|
||||
}
|
||||
|
||||
if users, err := store.User().Users(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Users")
|
||||
}
|
||||
} else {
|
||||
backup.User = users
|
||||
}
|
||||
|
||||
if webhooks, err := store.Webhook().Webhooks(); err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting Webhooks")
|
||||
}
|
||||
} else {
|
||||
backup.Webhook = webhooks
|
||||
}
|
||||
|
||||
v, err := store.Version().DBVersion()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Debugf("Export boom")
|
||||
if err != nil && !store.IsErrObjectNotFound(err) {
|
||||
logrus.WithError(err).Errorf("Exporting DB version")
|
||||
}
|
||||
instance, _ := store.Version().InstanceID()
|
||||
backup.Version = map[string]string{
|
||||
|
@ -518,50 +584,66 @@ func (store *Store) Import(filename string) (err error) {
|
|||
for _, v := range backup.CustomTemplate {
|
||||
store.CustomTemplate().UpdateCustomTemplate(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.EdgeGroup {
|
||||
store.EdgeGroup().UpdateEdgeGroup(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.EdgeJob {
|
||||
store.EdgeJob().UpdateEdgeJob(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.EdgeStack {
|
||||
store.EdgeStack().UpdateEdgeStack(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.Endpoint {
|
||||
store.Endpoint().UpdateEndpoint(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.EndpointGroup {
|
||||
store.EndpointGroup().UpdateEndpointGroup(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.EndpointRelation {
|
||||
store.EndpointRelation().UpdateEndpointRelation(v.EndpointID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.HelmUserRepository {
|
||||
store.HelmUserRepository().UpdateHelmUserRepository(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.Registry {
|
||||
store.Registry().UpdateRegistry(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.ResourceControl {
|
||||
store.ResourceControl().UpdateResourceControl(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.Role {
|
||||
store.Role().UpdateRole(v.ID, &v)
|
||||
}
|
||||
|
||||
store.Settings().UpdateSettings(&backup.Settings)
|
||||
store.SSLSettings().UpdateSettings(&backup.SSLSettings)
|
||||
|
||||
for _, v := range backup.Stack {
|
||||
store.Stack().UpdateStack(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.Tag {
|
||||
store.Tag().UpdateTag(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.TeamMembership {
|
||||
store.TeamMembership().UpdateTeamMembership(v.ID, &v)
|
||||
}
|
||||
|
||||
for _, v := range backup.Team {
|
||||
store.Team().UpdateTeam(v.ID, &v)
|
||||
}
|
||||
|
||||
store.TunnelServer().UpdateInfo(&backup.TunnelServer)
|
||||
|
||||
for _, user := range backup.User {
|
||||
|
@ -570,10 +652,9 @@ func (store *Store) Import(filename string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// backup[store.Webhook().BucketName()], err = store.Webhook().Webhooks()
|
||||
// if err != nil {
|
||||
// logrus.WithError(err).Debugf("Export boom")
|
||||
// }
|
||||
for _, v := range backup.Webhook {
|
||||
store.Webhook().UpdateWebhook(v.ID, &v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue