2019-01-18 13:54:08 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
2020-01-13 13:31:09 +00:00
|
|
|
"context"
|
2022-01-06 19:46:53 +00:00
|
|
|
"net"
|
|
|
|
"net/mail"
|
|
|
|
"net/smtp"
|
2020-01-13 13:31:09 +00:00
|
|
|
|
2020-07-09 18:21:25 +01:00
|
|
|
hw "github.com/jtolds/monkit-hw/v2"
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2022-01-06 19:46:53 +00:00
|
|
|
"go.uber.org/zap"
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/identity"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/private/post"
|
|
|
|
"storj.io/storj/private/post/oauth2"
|
2021-04-23 14:13:51 +01:00
|
|
|
"storj.io/storj/private/server"
|
2019-11-14 19:46:15 +00:00
|
|
|
version_checker "storj.io/storj/private/version/checker"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
|
|
|
"storj.io/storj/satellite/accounting/live"
|
2020-07-07 15:48:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/projectbwcleanup"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
2020-11-30 19:34:42 +00:00
|
|
|
"storj.io/storj/satellite/accounting/rolluparchive"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
2020-02-07 16:36:28 +00:00
|
|
|
"storj.io/storj/satellite/admin"
|
2021-03-23 15:52:34 +00:00
|
|
|
"storj.io/storj/satellite/analytics"
|
2019-06-19 13:02:37 +01:00
|
|
|
"storj.io/storj/satellite/attribution"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2021-11-12 20:47:41 +00:00
|
|
|
"storj.io/storj/satellite/buckets"
|
2020-03-10 20:42:11 +00:00
|
|
|
"storj.io/storj/satellite/compensation"
|
2019-01-18 13:54:08 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2022-04-19 21:50:15 +01:00
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleweb"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/satellite/console/emailreminders"
|
2022-04-12 17:59:07 +01:00
|
|
|
"storj.io/storj/satellite/console/restkeys"
|
2019-09-04 20:04:18 +01:00
|
|
|
"storj.io/storj/satellite/contact"
|
2022-08-30 09:51:11 +01:00
|
|
|
"storj.io/storj/satellite/gc/bloomfilter"
|
2022-08-29 10:44:54 +01:00
|
|
|
"storj.io/storj/satellite/gc/sender"
|
2019-09-25 18:12:44 +01:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
2022-01-06 19:46:53 +00:00
|
|
|
"storj.io/storj/satellite/mailservice/simulate"
|
2022-10-26 08:02:13 +01:00
|
|
|
"storj.io/storj/satellite/metabase/rangedloop"
|
2021-05-06 12:54:10 +01:00
|
|
|
"storj.io/storj/satellite/metabase/zombiedeletion"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/satellite/metainfo"
|
2020-04-15 20:20:16 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/expireddeletion"
|
2019-10-16 19:08:33 +01:00
|
|
|
"storj.io/storj/satellite/metrics"
|
2020-07-15 18:08:24 +01:00
|
|
|
"storj.io/storj/satellite/nodeapiversion"
|
2022-10-31 15:28:29 +00:00
|
|
|
"storj.io/storj/satellite/nodeevents"
|
2022-01-19 18:25:31 +00:00
|
|
|
"storj.io/storj/satellite/oidc"
|
2019-03-27 10:24:35 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2022-10-07 21:28:51 +01:00
|
|
|
"storj.io/storj/satellite/overlay/offlinenodes"
|
2020-12-31 18:43:13 +00:00
|
|
|
"storj.io/storj/satellite/overlay/straynodes"
|
2022-04-26 21:23:27 +01:00
|
|
|
"storj.io/storj/satellite/payments/billing"
|
2019-11-05 20:26:19 +00:00
|
|
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
2022-05-20 10:18:59 +01:00
|
|
|
"storj.io/storj/satellite/payments/storjscan"
|
2019-10-10 18:12:23 +01:00
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
|
|
|
"storj.io/storj/satellite/repair/queue"
|
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
2021-06-23 00:09:39 +01:00
|
|
|
"storj.io/storj/satellite/reputation"
|
2020-06-03 14:51:02 +01:00
|
|
|
"storj.io/storj/satellite/revocation"
|
2021-01-14 16:41:36 +00:00
|
|
|
"storj.io/storj/satellite/snopayouts"
|
2019-01-18 13:54:08 +00:00
|
|
|
)
|
|
|
|
|
2019-06-04 12:55:38 +01:00
|
|
|
var mon = monkit.Package()
|
|
|
|
|
2020-07-09 18:21:25 +01:00
|
|
|
func init() {
|
|
|
|
hw.Register(monkit.Default)
|
|
|
|
}
|
|
|
|
|
2020-12-05 16:01:42 +00:00
|
|
|
// DB is the master database for the satellite.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Master Database
|
2019-01-18 13:54:08 +00:00
|
|
|
type DB interface {
|
2020-04-30 07:36:59 +01:00
|
|
|
// MigrateToLatest initializes the database
|
|
|
|
MigrateToLatest(ctx context.Context) error
|
2019-11-02 20:09:07 +00:00
|
|
|
// CheckVersion checks the database is the correct version
|
2020-01-13 13:44:55 +00:00
|
|
|
CheckVersion(ctx context.Context) error
|
2019-01-18 13:54:08 +00:00
|
|
|
// Close closes the database
|
|
|
|
Close() error
|
|
|
|
|
2020-04-30 07:36:59 +01:00
|
|
|
// TestingMigrateToLatest initializes the database for testplanet.
|
|
|
|
TestingMigrateToLatest(ctx context.Context) error
|
2020-01-17 20:56:56 +00:00
|
|
|
|
2019-08-26 17:49:42 +01:00
|
|
|
// PeerIdentities returns a storage for peer identities
|
|
|
|
PeerIdentities() overlay.PeerIdentities
|
2019-01-18 13:54:08 +00:00
|
|
|
// OverlayCache returns database for caching overlay information
|
|
|
|
OverlayCache() overlay.DB
|
2022-10-31 15:28:29 +00:00
|
|
|
// NodeEvents returns a database for node event information
|
|
|
|
NodeEvents() nodeevents.DB
|
2021-06-23 00:09:39 +01:00
|
|
|
// Reputation returns database for audit reputation information
|
|
|
|
Reputation() reputation.DB
|
2019-06-19 13:02:37 +01:00
|
|
|
// Attribution returns database for partner keys information
|
|
|
|
Attribution() attribution.DB
|
2019-05-10 20:05:42 +01:00
|
|
|
// StoragenodeAccounting returns database for storing information about storagenode use
|
|
|
|
StoragenodeAccounting() accounting.StoragenodeAccounting
|
|
|
|
// ProjectAccounting returns database for storing information about project data use
|
|
|
|
ProjectAccounting() accounting.ProjectAccounting
|
2019-01-18 13:54:08 +00:00
|
|
|
// RepairQueue returns queue for segments that need repairing
|
|
|
|
RepairQueue() queue.RepairQueue
|
2022-11-01 17:45:41 +00:00
|
|
|
// VerifyQueue returns queue for segments chosen for verification
|
|
|
|
VerifyQueue() audit.VerifyQueue
|
2022-10-05 14:24:04 +01:00
|
|
|
// ReverifyQueue returns queue for pieces that need audit reverification
|
|
|
|
ReverifyQueue() audit.ReverifyQueue
|
2019-01-18 13:54:08 +00:00
|
|
|
// Console returns database for satellite console
|
|
|
|
Console() console.DB
|
2022-01-19 18:25:31 +00:00
|
|
|
// OIDC returns the database for OIDC resources.
|
|
|
|
OIDC() oidc.DB
|
2019-03-27 10:24:35 +00:00
|
|
|
// Orders returns database for orders
|
|
|
|
Orders() orders.DB
|
2019-05-22 15:50:22 +01:00
|
|
|
// Containment returns database for containment
|
2019-05-23 15:37:23 +01:00
|
|
|
Containment() audit.Containment
|
2022-11-22 16:59:04 +00:00
|
|
|
// NewContainment is temporary and will replace Containment later in the commit chain.
|
|
|
|
NewContainment() audit.NewContainment
|
2019-07-08 23:32:18 +01:00
|
|
|
// Buckets returns the database to interact with buckets
|
2021-11-12 20:47:41 +00:00
|
|
|
Buckets() buckets.DB
|
2019-09-25 18:12:44 +01:00
|
|
|
// GracefulExit returns database for graceful exit
|
|
|
|
GracefulExit() gracefulexit.DB
|
2019-11-05 13:16:02 +00:00
|
|
|
// StripeCoinPayments returns stripecoinpayments database.
|
|
|
|
StripeCoinPayments() stripecoinpayments.DB
|
2022-04-26 21:23:27 +01:00
|
|
|
// Billing returns storjscan transactions database.
|
|
|
|
Billing() billing.TransactionsDB
|
2022-05-20 10:18:59 +01:00
|
|
|
// Wallets returns storjscan wallets database.
|
|
|
|
Wallets() storjscan.WalletsDB
|
|
|
|
// SNOPayouts returns database for payouts.
|
2021-01-15 16:23:19 +00:00
|
|
|
SNOPayouts() snopayouts.DB
|
2022-05-20 10:18:59 +01:00
|
|
|
// Compensation tracks storage node compensation
|
2020-03-10 20:42:11 +00:00
|
|
|
Compensation() compensation.DB
|
2020-06-03 14:51:02 +01:00
|
|
|
// Revocation tracks revoked macaroons
|
|
|
|
Revocation() revocation.DB
|
2020-07-15 18:08:24 +01:00
|
|
|
// NodeAPIVersion tracks nodes observed api usage
|
|
|
|
NodeAPIVersion() nodeapiversion.DB
|
2022-05-10 13:18:23 +01:00
|
|
|
// StorjscanPayments stores payments retrieved from storjscan.
|
|
|
|
StorjscanPayments() storjscan.PaymentsDB
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Config is the global config satellite.
|
2019-01-18 13:54:08 +00:00
|
|
|
type Config struct {
|
|
|
|
Identity identity.Config
|
2019-06-21 11:38:40 +01:00
|
|
|
Server server.Config
|
2020-01-28 17:35:45 +00:00
|
|
|
Debug debug.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2020-02-07 16:36:28 +00:00
|
|
|
Admin admin.Config
|
|
|
|
|
2022-10-07 21:28:51 +01:00
|
|
|
Contact contact.Config
|
|
|
|
Overlay overlay.Config
|
|
|
|
OfflineNodes offlinenodes.Config
|
|
|
|
NodeEvents nodeevents.Config
|
|
|
|
StrayNodes straynodes.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-06-06 14:57:58 +01:00
|
|
|
Metainfo metainfo.Config
|
2019-06-21 11:38:40 +01:00
|
|
|
Orders orders.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2021-06-23 00:09:39 +01:00
|
|
|
Reputation reputation.Config
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
Checker checker.Config
|
|
|
|
Repairer repairer.Config
|
2019-01-23 19:58:44 +00:00
|
|
|
Audit audit.Config
|
|
|
|
|
2022-08-29 10:44:54 +01:00
|
|
|
GarbageCollection sender.Config
|
2022-08-30 09:51:11 +01:00
|
|
|
GarbageCollectionBF bloomfilter.Config
|
2019-07-24 18:26:43 +01:00
|
|
|
|
2022-10-26 08:02:13 +01:00
|
|
|
RangedLoop rangedloop.Config
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
ExpiredDeletion expireddeletion.Config
|
2021-05-06 12:54:10 +01:00
|
|
|
ZombieDeletion zombiedeletion.Config
|
2020-04-15 20:20:16 +01:00
|
|
|
|
2020-07-07 15:48:09 +01:00
|
|
|
Tally tally.Config
|
|
|
|
Rollup rollup.Config
|
2020-11-30 19:34:42 +00:00
|
|
|
RollupArchive rolluparchive.Config
|
2020-07-07 15:48:09 +01:00
|
|
|
LiveAccounting live.Config
|
|
|
|
ProjectBWCleanup projectbwcleanup.Config
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-11-05 20:26:19 +00:00
|
|
|
Mail mailservice.Config
|
|
|
|
|
|
|
|
Payments paymentsconfig.Config
|
|
|
|
|
2022-01-06 19:46:53 +00:00
|
|
|
RESTKeys restkeys.Config
|
|
|
|
Console consoleweb.Config
|
|
|
|
ConsoleAuth consoleauth.Config
|
|
|
|
EmailReminders emailreminders.Config
|
2019-04-03 20:13:39 +01:00
|
|
|
|
2019-10-20 08:56:23 +01:00
|
|
|
Version version_checker.Config
|
2019-10-07 21:38:05 +01:00
|
|
|
|
|
|
|
GracefulExit gracefulexit.Config
|
2019-10-16 19:08:33 +01:00
|
|
|
|
|
|
|
Metrics metrics.Config
|
2020-01-02 20:41:18 +00:00
|
|
|
|
2020-03-10 20:42:11 +00:00
|
|
|
Compensation compensation.Config
|
2020-09-09 20:20:44 +01:00
|
|
|
|
|
|
|
ProjectLimit accounting.ProjectLimitConfig
|
2021-03-23 15:52:34 +00:00
|
|
|
|
|
|
|
Analytics analytics.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
2022-01-06 19:46:53 +00:00
|
|
|
|
|
|
|
func setupMailService(log *zap.Logger, config Config) (*mailservice.Service, error) {
|
|
|
|
// TODO(yar): test multiple satellites using same OAUTH credentials
|
|
|
|
mailConfig := config.Mail
|
|
|
|
|
|
|
|
// validate from mail address
|
|
|
|
from, err := mail.ParseAddress(mailConfig.From)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate smtp server address
|
|
|
|
host, _, err := net.SplitHostPort(mailConfig.SMTPServerAddress)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var sender mailservice.Sender
|
|
|
|
switch mailConfig.AuthType {
|
|
|
|
case "oauth2":
|
|
|
|
creds := oauth2.Credentials{
|
|
|
|
ClientID: mailConfig.ClientID,
|
|
|
|
ClientSecret: mailConfig.ClientSecret,
|
|
|
|
TokenURI: mailConfig.TokenURI,
|
|
|
|
}
|
|
|
|
token, err := oauth2.RefreshToken(context.TODO(), creds, mailConfig.RefreshToken)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
|
|
|
Auth: &oauth2.Auth{
|
|
|
|
UserEmail: from.Address,
|
|
|
|
Storage: oauth2.NewTokenStore(creds, *token),
|
|
|
|
},
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
case "plain":
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
|
|
|
Auth: smtp.PlainAuth("", mailConfig.Login, mailConfig.Password, host),
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
case "login":
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
|
|
|
Auth: post.LoginAuth{
|
|
|
|
Username: mailConfig.Login,
|
|
|
|
Password: mailConfig.Password,
|
|
|
|
},
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
satellite/consoleweb: fix flaky TestAuth tests
We had a lot of flaky test failures from TestAuth. The error message (WHICH IS NOT VISIBLE IN JEKNINS, only in tests.json):
```
FAIL: TestAuth_Register_NameSpecialChars/Postgres (1.04s)
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
goroutine 3473 [running]:
testing.tRunner.func1.2({0x235fe40, 0xc000fe6a08})
/usr/local/go/src/testing/testing.go:1209 +0x36c
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1212 +0x3b6
panic({0x235fe40, 0xc000fe6a08})
/usr/local/go/src/runtime/panic.go:1047 +0x266
storj.io/storj/satellite/console/consoleweb/consoleapi_test.TestAuth_Register_NameSpecialChars.func1(0xc001a281a0, 0x289d650, 0xc001a30000)
/var/lib/jenkins/workspace/storj-gerrit-verify/satellite/console/consoleweb/consoleapi/auth_test.go:773 +0x785
storj.io/storj/private/testplanet.Run.func1.1({0x289c770, 0xc0001b8008})
/var/lib/jenkins/workspace/storj-gerrit-verify/private/testplanet/run.go:67 +0x732
storj.io/storj/private/testmonkit.RunWith({0x289c770, 0xc0001b8008}, {0x28d89b0, 0xc001a281a0}, {0x1, {0x0, 0x0}, {0x0, 0x0, 0x0}}, ...)
```
The root cause:
testplanet uses a simulated mail sender which clicks to all the registration links by default (async).
These tests creat links and check the unverified users, but without enough luck the mail sender may already clicks to the link which makes the user verified.
Change-Id: I17cd6bf4ae3e7adc223ec693976bb609370f0c44
2022-08-04 12:31:47 +01:00
|
|
|
case "nomail":
|
|
|
|
sender = simulate.NoMail{}
|
2022-01-06 19:46:53 +00:00
|
|
|
default:
|
|
|
|
sender = simulate.NewDefaultLinkClicker(log.Named("mail:linkclicker"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return mailservice.New(
|
|
|
|
log.Named("mail:service"),
|
|
|
|
sender,
|
|
|
|
mailConfig.TemplatePath,
|
|
|
|
)
|
|
|
|
}
|