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"
|
2019-07-24 18:26:43 +01:00
|
|
|
"storj.io/storj/satellite/gc"
|
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"
|
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-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"
|
2020-12-31 18:43:13 +00:00
|
|
|
"storj.io/storj/satellite/overlay/straynodes"
|
2019-11-05 20:26:19 +00:00
|
|
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
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
|
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
|
|
|
|
// 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
|
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
|
2021-01-14 16:41:36 +00:00
|
|
|
// SnoPayout returns database for payouts.
|
2021-01-15 16:23:19 +00:00
|
|
|
SNOPayouts() snopayouts.DB
|
2020-03-10 20:42:11 +00:00
|
|
|
// Compoensation tracks storage node compensation
|
|
|
|
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
|
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
|
|
|
|
|
2020-12-31 18:43:13 +00:00
|
|
|
Contact contact.Config
|
|
|
|
Overlay overlay.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
|
|
|
|
|
2019-07-24 18:26:43 +01:00
|
|
|
GarbageCollection gc.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,
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
sender = simulate.NewDefaultLinkClicker(log.Named("mail:linkclicker"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return mailservice.New(
|
|
|
|
log.Named("mail:service"),
|
|
|
|
sender,
|
|
|
|
mailConfig.TemplatePath,
|
|
|
|
)
|
|
|
|
}
|