Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
43cba36
SAAS-175 Update saas dependency
artemgavrilov Jul 14, 2020
b4cdde3
SAAS-175 Update pmm dependency
artemgavrilov Jul 14, 2020
8039800
SAAS-175 Implement authentication methods
artemgavrilov Jul 14, 2020
78ca1d9
Merge branch 'PMM-2.0' into SAAS-175-auth-api
artemgavrilov Jul 14, 2020
f4b9d69
SAAS-175 Update pmm dependency, remove RefreshSession API method
artemgavrilov Jul 15, 2020
8e3f006
SAAS-175 Add auth tests
artemgavrilov Jul 15, 2020
a2880e3
SAAS-175 Refactoring
artemgavrilov Jul 16, 2020
26f00ba
SAAS-175 Fix tests
artemgavrilov Jul 16, 2020
e7b1afc
SAAS-175 Mute linter
artemgavrilov Jul 16, 2020
acc8fe8
SAAS-175 Refactoring
artemgavrilov Jul 16, 2020
24600bd
SAAS-175 Update pmm dependency, fix build
artemgavrilov Jul 20, 2020
3116158
SAAS-175 Refactoring
artemgavrilov Jul 20, 2020
553234e
SAAS-175 Refactoring
artemgavrilov Jul 20, 2020
aa12e04
SAAS-175 Extract auth type to const
artemgavrilov Jul 20, 2020
de6d131
SAAS-175 Generate passwords in tests
artemgavrilov Jul 20, 2020
5ed63c1
SAAS-175 Refresh session every day
artemgavrilov Jul 20, 2020
11f8a74
SAAS-175 Save users email
artemgavrilov Jul 20, 2020
f07a387
SAAS-175 Fix permissions
artemgavrilov Jul 20, 2020
cb2b125
SAAS-175 Fix tests
artemgavrilov Jul 20, 2020
daeb46d
SAAS-175 Refactoring
artemgavrilov Jul 21, 2020
6df28e6
SAAS-175 Add comment
artemgavrilov Jul 21, 2020
9d667ed
SAAS-175 Remove redundant error check
artemgavrilov Jul 21, 2020
4708281
SAAS-175 Improove env variable name
artemgavrilov Jul 21, 2020
1980900
SAAS-175 Fix comments
artemgavrilov Jul 21, 2020
978bc92
SAAS-175 Refactoring
artemgavrilov Jul 21, 2020
0dd42b9
SAAS-175 Add LogOut option to settings update
artemgavrilov Jul 21, 2020
b49c033
SAAS-175 Fix linters
artemgavrilov Jul 21, 2020
ab66b50
SAAS-175 Install gofumpt
AlekSi Jul 23, 2020
b68fbf4
SAAS-175 Use cleanup
AlekSi Jul 23, 2020
37d6ead
SAAS-175 Gofumpt
AlekSi Jul 23, 2020
37baf56
SAAS-175 Use mock for testing
AlekSi Jul 23, 2020
708ea4e
SAAS-175 Add timeout to refresh session request
artemgavrilov Jul 23, 2020
ee0a7a3
SAAS-175 Set Platrotm API request timeouts
artemgavrilov Jul 23, 2020
2d7d514
SAAS-175 Hit CI
artemgavrilov Jul 23, 2020
87e8ed7
SAAS-175 Refactoring
artemgavrilov Jul 23, 2020
fb0178c
SAAS-175 Refactoring
artemgavrilov Jul 23, 2020
dcf7635
SAAS-174 Update pmm dependency
artemgavrilov Jul 22, 2020
adb50cf
SAAS-174 Update saas dependency
artemgavrilov Jul 23, 2020
77e2a51
SAAS-174 Add password reset method
artemgavrilov Jul 23, 2020
cfdb709
SAAS-175 Hit CI
artemgavrilov Jul 24, 2020
507629a
SAAS-174 Update pmm dependecny
artemgavrilov Jul 27, 2020
643f999
Merge branch 'SAAS-174-password-reset' into SAAS-175-auth-api
artemgavrilov Jul 27, 2020
938e034
SAAS-175 SAAS-174 Do not wrap gRPC errors
artemgavrilov Jul 27, 2020
8101c9f
SAAS-175 Update saas and pmm dependencies
artemgavrilov Jul 28, 2020
e0d358f
SAAS-174 Remove password reset API method
artemgavrilov Jul 28, 2020
1c119e7
SAAS-175 Hit CI
artemgavrilov Jul 28, 2020
72980a6
SAAS-175 Update pmm dependency
artemgavrilov Jul 28, 2020
e0e3605
SAAS-175 Regenerate mocks
artemgavrilov Jul 28, 2020
9a2cc8c
Merge branch 'PMM-2.0' into SAAS-175-auth-api
artemgavrilov Jul 28, 2020
3c323a6
Merge branch 'PMM-2.0' into SAAS-175-auth-api
AlekSi Jul 28, 2020
e7a26b9
SAAS-175 Update API branch
AlekSi Jul 28, 2020
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
4 changes: 3 additions & 1 deletion .devcontainer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def install_tools():
go mod init tools && \
env GOPROXY=https://proxy.golang.org go get -v \
github.com/go-delve/delve/cmd/dlv@latest \
golang.org/x/tools/gopls@latest"
golang.org/x/tools/gopls@latest \
mvdan.cc/gofumpt@latest \
mvdan.cc/gofumpt/gofumports"
])


Expand Down
20 changes: 17 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ required = [
name = "github.com/percona/pmm"
branch = "PMM-2.0"

[[constraint]]
name = "github.com/percona-platform/saas"
branch = "main"

# to prevent unexpected downgrades; see https://github.com/percona/exporter_shared/releases/tag/v0.6.0
[[constraint]]
name = "github.com/percona/exporter_shared"
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import (
inventorygrpc "github.com/percona/pmm-managed/services/inventory/grpc"
"github.com/percona/pmm-managed/services/management"
managementgrpc "github.com/percona/pmm-managed/services/management/grpc"
"github.com/percona/pmm-managed/services/platform"
"github.com/percona/pmm-managed/services/prometheus"
"github.com/percona/pmm-managed/services/qan"
"github.com/percona/pmm-managed/services/server"
Expand Down Expand Up @@ -538,12 +539,15 @@ func main() {
checksService := checks.New(agentsRegistry, alertsRegistry, db)
prom.MustRegister(checksService)

platformService := platform.New(db)

serverParams := &server.Params{
DB: db,
Prometheus: prometheus,
Alertmanager: alertmanager,
Supervisord: supervisord,
TelemetryService: telemetry,
PlatformService: platformService,
AwsInstanceChecker: awsInstanceChecker,
GrafanaClient: grafanaClient,
PrometheusAlertingRules: alertingRules,
Expand Down Expand Up @@ -607,6 +611,12 @@ func main() {
checksService.Run(ctx)
}()

wg.Add(1)
go func() {
defer wg.Done()
platformService.Run(ctx)
}()

wg.Add(1)
go func() {
defer wg.Done()
Expand Down
4 changes: 4 additions & 0 deletions models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type Settings struct {

// Saas config options
SaaS struct {
// Percona Platform user email
Email string `json:"email"`
// Percona Platform session Id
SessionID string `json:"session_id"`
// Security Threat Tool enabled
STTEnabled bool `json:"stt_enabled"`
} `json:"sass"`
Comment thread
artemgavrilov marked this conversation as resolved.
Expand Down
43 changes: 33 additions & 10 deletions models/settings_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ type ChangeSettingsParams struct {
EnableSTT bool
// Disable Security Threat Tool
DisableSTT bool

// Percona Platform user email
Email string
// Percona Platform session Id
SessionID string
// LogOut user from Percona Platform, i.e. remove user email and session id
LogOut bool
}

// UpdateSettings updates only non-zero, non-empty values.
Expand Down Expand Up @@ -128,6 +135,18 @@ func UpdateSettings(q reform.DBTX, params *ChangeSettingsParams) (*Settings, err
if params.EnableSTT {
settings.SaaS.STTEnabled = true
}
if params.LogOut {
settings.SaaS.SessionID = ""
settings.SaaS.Email = ""
}

if params.SessionID != "" {
settings.SaaS.SessionID = params.SessionID
}

if params.Email != "" {
settings.SaaS.Email = params.Email
}
Comment thread
artemgavrilov marked this conversation as resolved.

err = SaveSettings(q, settings)
if err != nil {
Expand All @@ -139,10 +158,10 @@ func UpdateSettings(q reform.DBTX, params *ChangeSettingsParams) (*Settings, err
// ValidateSettings validates settings changes.
func ValidateSettings(params *ChangeSettingsParams) error {
if params.EnableTelemetry && params.DisableTelemetry {
return fmt.Errorf("Both enable_telemetry and disable_telemetry are present.")
return fmt.Errorf("Both enable_telemetry and disable_telemetry are present.") //nolint:golint,stylecheck
}
if params.EnableSTT && params.DisableSTT {
return fmt.Errorf("Both enable_stt and disable_stt are present.")
return fmt.Errorf("Both enable_stt and disable_stt are present.") //nolint:golint,stylecheck
}

checkCases := []struct {
Expand Down Expand Up @@ -190,22 +209,22 @@ func ValidateSettings(params *ChangeSettingsParams) error {

if params.AlertManagerURL != "" {
if params.RemoveAlertManagerURL {
return fmt.Errorf("Both alert_manager_url and remove_alert_manager_url are present.")
return fmt.Errorf("Both alert_manager_url and remove_alert_manager_url are present.") //nolint:golint,stylecheck
}

// custom validation for typical error that is not handled well by url.Parse
if !strings.Contains(params.AlertManagerURL, "//") {
return fmt.Errorf("Invalid alert_manager_url: %s - missing protocol scheme.", params.AlertManagerURL)
return fmt.Errorf("Invalid alert_manager_url: %s - missing protocol scheme.", params.AlertManagerURL) //nolint:golint,stylecheck
}
u, err := url.Parse(params.AlertManagerURL)
if err != nil {
return fmt.Errorf("Invalid alert_manager_url: %s.", err)
return fmt.Errorf("Invalid alert_manager_url: %s.", err) //nolint:golint,stylecheck
}
if u.Scheme == "" {
return fmt.Errorf("Invalid alert_manager_url: %s - missing protocol scheme.", params.AlertManagerURL)
return fmt.Errorf("Invalid alert_manager_url: %s - missing protocol scheme.", params.AlertManagerURL) //nolint:golint,stylecheck
}
if u.Host == "" {
return fmt.Errorf("Invalid alert_manager_url: %s - missing host.", params.AlertManagerURL)
return fmt.Errorf("Invalid alert_manager_url: %s - missing host.", params.AlertManagerURL) //nolint:golint,stylecheck
}
}

Expand All @@ -214,13 +233,17 @@ func ValidateSettings(params *ChangeSettingsParams) error {

func validateSettingsConflicts(params *ChangeSettingsParams, settings *Settings) error {
if params.EnableSTT && !params.EnableTelemetry && settings.Telemetry.Disabled {
return fmt.Errorf("Cannot enable STT while telemetry is disabled.")
return fmt.Errorf("Cannot enable STT while telemetry is disabled.") //nolint:golint,stylecheck
}
if params.EnableSTT && params.DisableTelemetry {
return fmt.Errorf("Cannot enable STT while disabling telemetry.")
return fmt.Errorf("Cannot enable STT while disabling telemetry.") //nolint:golint,stylecheck
}
if params.DisableTelemetry && !params.DisableSTT && settings.SaaS.STTEnabled {
return fmt.Errorf("Cannot disable telemetry while STT is enabled.")
return fmt.Errorf("Cannot disable telemetry while STT is enabled.") //nolint:golint,stylecheck
}

if params.LogOut && (params.Email != "" || params.SessionID != "") {
return fmt.Errorf("Cannot loguot while updating Percona Platform user data.") //nolint:golint,stylecheck
}

return nil
Expand Down
45 changes: 45 additions & 0 deletions models/settings_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/brianvoe/gofakeit"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -240,5 +241,49 @@ func TestSettings(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, ns.Telemetry.UUID)
})

t.Run("Percona Platform auth ", func(t *testing.T) {
email := gofakeit.Email()
sessionID := gofakeit.UUID()

// User logged in
ns, err := models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
Email: email,
SessionID: sessionID,
})
require.NoError(t, err)
assert.Equal(t, email, ns.SaaS.Email)
assert.Equal(t, sessionID, ns.SaaS.SessionID)

// Logout with email update
_, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
LogOut: true,
Email: gofakeit.Email(),
})
assert.Error(t, err, "Cannot logout while updating Percona Platform user data.")

// Logout with session ID update
_, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
LogOut: true,
SessionID: gofakeit.UUID(),
})
assert.Error(t, err, "Cannot logout while updating Percona Platform user data.")

// Logout with email and session ID update
_, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
LogOut: true,
Email: gofakeit.Email(),
SessionID: gofakeit.UUID(),
})
assert.Error(t, err, "Cannot logout while updating Percona Platform user data.")

// Normal logout
ns, err = models.UpdateSettings(sqlDB, &models.ChangeSettingsParams{
LogOut: true,
})
require.NoError(t, err)
assert.Empty(t, ns.SaaS.Email)
assert.Empty(t, ns.SaaS.SessionID)
})
})
}
1 change: 1 addition & 0 deletions packages.dot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ digraph packages {
"/" -> "/services/inventory/grpc";
"/" -> "/services/management";
"/" -> "/services/management/grpc";
"/" -> "/services/platform";
"/" -> "/services/prometheus";
"/" -> "/services/qan";
"/" -> "/services/server";
Expand Down
1 change: 1 addition & 0 deletions services/grafana/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var rules = map[string]role{
"/v1/AWSInstanceCheck": none, // special case - used before Grafana can be accessed
"/v1/Updates/": admin,
"/v1/Settings/": admin,
"/v1/Platform/": admin,

// must be available without authentication for health checking
"/v1/readyz": none,
Expand Down
2 changes: 2 additions & 0 deletions services/grafana/auth_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func TestAuthServerAuthenticate(t *testing.T) {
"/v1/Updates/Status": none,
"/v1/Settings/Get": admin,
"/v1/AWSInstanceCheck": none,
"/v1/Platform/SignUp": admin,
"/v1/Platform/SingIn": admin,

"/v1/readyz": none,
"/ping": none,
Expand Down
Loading