fix(docker): add docker desktop extension flag in settings and add migration EE-5277 (#8948)

pull/8956/head
Prabhat Khera 2023-05-17 14:31:46 +12:00 committed by GitHub
parent e156243e43
commit 83551201fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package datastore package datastore
import ( import (
"os"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
) )
@ -20,6 +22,12 @@ func (store *Store) Init() error {
} }
func (store *Store) checkOrCreateDefaultSettings() error { func (store *Store) checkOrCreateDefaultSettings() error {
isDDExtention := false
if _, ok := os.LookupEnv("DOCKER_EXTENSION"); ok {
isDDExtention = true
}
// TODO: these need to also be applied when importing // TODO: these need to also be applied when importing
settings, err := store.SettingsService.Settings() settings, err := store.SettingsService.Settings()
if store.IsErrObjectNotFound(err) { if store.IsErrObjectNotFound(err) {
@ -51,6 +59,8 @@ func (store *Store) checkOrCreateDefaultSettings() error {
UserSessionTimeout: portainer.DefaultUserSessionTimeout, UserSessionTimeout: portainer.DefaultUserSessionTimeout,
KubeconfigExpiry: portainer.DefaultKubeconfigExpiry, KubeconfigExpiry: portainer.DefaultKubeconfigExpiry,
KubectlShellImage: portainer.DefaultKubectlShellImage, KubectlShellImage: portainer.DefaultKubectlShellImage,
IsDockerDesktopExtention: isDDExtention,
} }
return store.SettingsService.UpdateSettings(defaultSettings) return store.SettingsService.UpdateSettings(defaultSettings)

View File

@ -0,0 +1,29 @@
package migrator
import (
"os"
"github.com/rs/zerolog/log"
)
func (m *Migrator) migrateDockerDesktopExtentionSetting() error {
log.Info().Msg("updating docker desktop extention flag in settings")
isDDExtention := false
if _, ok := os.LookupEnv("DOCKER_EXTENSION"); ok {
isDDExtention = true
}
settings, err := m.settingsService.Settings()
if err != nil {
return err
}
settings.IsDockerDesktopExtention = isDDExtention
err = m.settingsService.UpdateSettings(settings)
if err != nil {
return err
}
return nil
}

View File

@ -211,6 +211,8 @@ func (m *Migrator) initMigrations() {
m.addMigrations("2.17", m.migrateDBVersionToDB80) m.addMigrations("2.17", m.migrateDBVersionToDB80)
m.addMigrations("2.18", m.migrateDBVersionToDB90) m.addMigrations("2.18", m.migrateDBVersionToDB90)
m.addMigrations("2.19", m.migrateDockerDesktopExtentionSetting)
// Add new migrations below... // Add new migrations below...
// One function per migration, each versions migration funcs in the same file. // One function per migration, each versions migration funcs in the same file.
} }

View File

@ -606,6 +606,7 @@
"InternalAuthSettings": { "InternalAuthSettings": {
"RequiredPasswordLength": 12 "RequiredPasswordLength": 12
}, },
"IsDockerDesktopExtention": false,
"KubeconfigExpiry": "0", "KubeconfigExpiry": "0",
"KubectlShellImage": "portainer/kubectl-shell", "KubectlShellImage": "portainer/kubectl-shell",
"LDAPSettings": { "LDAPSettings": {
@ -945,6 +946,6 @@
} }
], ],
"version": { "version": {
"VERSION": "{\"SchemaVersion\":\"2.19.0\",\"MigratorCount\":0,\"Edition\":1,\"InstanceID\":\"463d5c47-0ea5-4aca-85b1-405ceefee254\"}" "VERSION": "{\"SchemaVersion\":\"2.19.0\",\"MigratorCount\":1,\"Edition\":1,\"InstanceID\":\"463d5c47-0ea5-4aca-85b1-405ceefee254\"}"
} }
} }

View File

@ -49,6 +49,8 @@ type publicSettingsResponse struct {
// The check in interval for edge agent (in seconds) - used in non async mode [seconds] // The check in interval for edge agent (in seconds) - used in non async mode [seconds]
CheckinInterval int `example:"60"` CheckinInterval int `example:"60"`
} }
IsDockerDesktopExtention bool `json:"IsDockerDesktopExtention" example:"false"`
} }
// @id SettingsPublic // @id SettingsPublic
@ -89,6 +91,8 @@ func generatePublicSettings(appSettings *portainer.Settings) *publicSettingsResp
publicSettings.Edge.CommandInterval = appSettings.Edge.CommandInterval publicSettings.Edge.CommandInterval = appSettings.Edge.CommandInterval
publicSettings.Edge.CheckinInterval = appSettings.EdgeAgentCheckinInterval publicSettings.Edge.CheckinInterval = appSettings.EdgeAgentCheckinInterval
publicSettings.IsDockerDesktopExtention = appSettings.IsDockerDesktopExtention
//if OAuth authentication is on, compose the related fields from application settings //if OAuth authentication is on, compose the related fields from application settings
if publicSettings.AuthenticationMethod == portainer.AuthenticationOAuth { if publicSettings.AuthenticationMethod == portainer.AuthenticationOAuth {
publicSettings.OAuthLogoutURI = appSettings.OAuthSettings.LogoutURI publicSettings.OAuthLogoutURI = appSettings.OAuthSettings.LogoutURI

View File

@ -3,7 +3,6 @@ package jwt
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"time" "time"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
@ -169,7 +168,12 @@ func (service *Service) generateSignedToken(data *portainer.TokenData, expiresAt
return "", fmt.Errorf("invalid scope: %v", scope) return "", fmt.Errorf("invalid scope: %v", scope)
} }
if _, ok := os.LookupEnv("DOCKER_EXTENSION"); ok { settings, err := service.dataStore.Settings().Settings()
if err != nil {
return "", fmt.Errorf("failed fetching settings from db: %w", err)
}
if settings.IsDockerDesktopExtention {
// Set expiration to 99 years for docker desktop extension. // Set expiration to 99 years for docker desktop extension.
log.Info().Msg("detected docker desktop extension mode") log.Info().Msg("detected docker desktop extension mode")
expiresAt = time.Now().Add(time.Hour * 8760 * 99).Unix() expiresAt = time.Now().Add(time.Hour * 8760 * 99).Unix()

View File

@ -967,6 +967,8 @@ type (
AllowStackManagementForRegularUsers bool `json:"AllowStackManagementForRegularUsers"` AllowStackManagementForRegularUsers bool `json:"AllowStackManagementForRegularUsers"`
AllowDeviceMappingForRegularUsers bool `json:"AllowDeviceMappingForRegularUsers"` AllowDeviceMappingForRegularUsers bool `json:"AllowDeviceMappingForRegularUsers"`
AllowContainerCapabilitiesForRegularUsers bool `json:"AllowContainerCapabilitiesForRegularUsers"` AllowContainerCapabilitiesForRegularUsers bool `json:"AllowContainerCapabilitiesForRegularUsers"`
IsDockerDesktopExtention bool `json:"IsDockerDesktopExtention"`
} }
// SnapshotJob represents a scheduled job that can create environment(endpoint) snapshots // SnapshotJob represents a scheduled job that can create environment(endpoint) snapshots