Skip to content

Commit

Permalink
Move machine-auth-api-key to shared.Commons
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Apr 26, 2022
1 parent acf75af commit 4a13035
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion extensions/notifications/pkg/channels/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m Mail) getReceiverAddresses(receivers []string) ([]string, error) {
res, err := m.gatewayClient.Authenticate(context.Background(), &gateway.AuthenticateRequest{
Type: "machine",
ClientId: "userid:" + id,
ClientSecret: m.conf.Notifications.MachineAuthSecret,
ClientSecret: m.conf.Notifications.MachineAuthAPIKey,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion extensions/notifications/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type SutureService struct {

// NewSutureService creates a new notifications.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.Settings.Commons = cfg.Commons
cfg.Notifications.Commons = cfg.Commons
return SutureService{
cfg: cfg.Notifications,
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/notifications/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type Config struct {

// Notifications definces the config options for the notifications service.
type Notifications struct {
*shared.Commons `yaml:"-"`
SMTP SMTP `yaml:"SMTP,omitempty"`
Events Events `yaml:"events,omitempty"`
RevaGateway string `yaml:"reva_gateway,omitempty" env:"REVA_GATEWAY;NOTIFICATIONS_REVA_GATEWAY"`
MachineAuthSecret string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;NOTIFICATIONS_MACHINE_AUTH_API_KEY"`
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;NOTIFICATIONS_MACHINE_AUTH_API_KEY"`
}

// SMTP combines the smtp configuration options.
Expand Down
15 changes: 12 additions & 3 deletions extensions/notifications/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package defaults

import "github.com/owncloud/ocis/extensions/notifications/pkg/config"
import (
"log"

"github.com/owncloud/ocis/extensions/notifications/pkg/config"
)

func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
Expand Down Expand Up @@ -31,8 +35,7 @@ func DefaultConfig() *config.Config {
Cluster: "ocis-cluster",
ConsumerGroup: "notifications",
},
RevaGateway: "127.0.0.1:9142",
MachineAuthSecret: "change-me-please",
RevaGateway: "127.0.0.1:9142",
},
}
}
Expand All @@ -49,6 +52,12 @@ func EnsureDefaults(cfg *config.Config) {
} else if cfg.Log == nil {
cfg.Log = &config.Log{}
}

if cfg.Notifications.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
cfg.Notifications.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
} else {
log.Fatalf("machine auth api key is not set up properly, bailing out (%s)", cfg.Service.Name)
}
}

func Sanitize(cfg *config.Config) {
Expand Down
8 changes: 7 additions & 1 deletion extensions/ocs/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package defaults

import (
"log"
"strings"

"github.com/owncloud/ocis/extensions/ocs/pkg/config"
Expand Down Expand Up @@ -44,7 +45,6 @@ func DefaultConfig() *config.Config {
Address: "127.0.0.1:9142",
},
StorageUsersDriver: "ocis",
MachineAuthAPIKey: "change-me-please",
IdentityManagement: config.IdentityManagement{
Address: "https://localhost:9200",
},
Expand Down Expand Up @@ -82,6 +82,12 @@ func EnsureDefaults(cfg *config.Config) {
} else {
cfg.TokenManager = &shared.TokenManager{}
}

if cfg.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
} else {
log.Fatalf("machine auth api key is not set up properly, bailing out (%s)", cfg.Service.Name)
}
}

func Sanitize(cfg *config.Config) {
Expand Down
8 changes: 7 additions & 1 deletion extensions/proxy/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package defaults

import (
"log"
"path"
"strings"

Expand Down Expand Up @@ -45,7 +46,6 @@ func DefaultConfig() *config.Config {
AccountBackend: "accounts",
UserOIDCClaim: "email",
UserCS3Claim: "mail",
MachineAuthAPIKey: "change-me-please",
AutoprovisionAccounts: false,
EnableBasicAuth: false,
InsecureBackends: false,
Expand Down Expand Up @@ -185,6 +185,12 @@ func EnsureDefaults(cfg *config.Config) {
} else {
cfg.TokenManager = &config.TokenManager{}
}

if cfg.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
} else {
log.Fatalf("machine auth api key is not set up properly, bailing out (%s)", cfg.Service.Name)
}
}

func Sanitize(cfg *config.Config) {
Expand Down
16 changes: 11 additions & 5 deletions extensions/settings/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package defaults

import (
"log"
"path"
"strings"

Expand Down Expand Up @@ -53,11 +54,10 @@ func DefaultConfig() *config.Config {
},

Metadata: config.Metadata{
GatewayAddress: "127.0.0.1:9142",
StorageAddress: "127.0.0.1:9215",
ServiceUserID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad",
ServiceUserIDP: "https://localhost:9200",
MachineAuthAPIKey: "change-me-please",
GatewayAddress: "127.0.0.1:9142",
StorageAddress: "127.0.0.1:9215",
ServiceUserID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad",
ServiceUserIDP: "https://localhost:9200",
},
}
}
Expand Down Expand Up @@ -93,6 +93,12 @@ func EnsureDefaults(cfg *config.Config) {
} else {
cfg.TokenManager = &shared.TokenManager{}
}

if cfg.Metadata.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
} else {
log.Fatalf("machine auth api key is not set up properly, bailing out (%s)", cfg.Service.Name)
}
}

func Sanitize(cfg *config.Config) {
Expand Down
4 changes: 1 addition & 3 deletions extensions/storage/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ func DefaultConfig() *config.Config {
Services: []string{"authprovider"},
Endpoint: "localhost:9166",
},
AuthMachineConfig: config.AuthMachineConfig{
MachineAuthAPIKey: "change-me-please",
},
AuthMachineConfig: config.AuthMachineConfig{},
Sharing: config.Sharing{
Port: config.Port{
Endpoint: "localhost:9150",
Expand Down
7 changes: 4 additions & 3 deletions ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ type Config struct {
File string `yaml:",omitempty"`
OcisURL string `yaml:"ocis_url,omitempty"`

Registry string `yaml:"registry,omitempty"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`
Runtime Runtime `yaml:"runtime,omitempty"`
Registry string `yaml:"registry,omitempty"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`
MachineAuthAPIKey string
Runtime Runtime `yaml:"runtime,omitempty"`

Audit *audit.Config `yaml:"audit,omitempty"`
Accounts *accounts.Config `yaml:"accounts,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions ocis-pkg/config/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package parser

import (
"errors"
"log"

"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
Expand Down Expand Up @@ -50,6 +51,12 @@ func ParseConfig(cfg *config.Config) error {
cfg.TokenManager = cfg.Commons.TokenManager
}

if cfg.MachineAuthAPIKey != "" {
cfg.Commons.MachineAuthAPIKey = cfg.MachineAuthAPIKey
} else {
log.Fatalf("machine auth api key is not set up properly, bailing out (ocis)")
}

// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
Expand Down
9 changes: 5 additions & 4 deletions ocis-pkg/shared/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type TokenManager struct {
// Commons holds configuration that are common to all extensions. Each extension can then decide whether
// to overwrite its values.
type Commons struct {
Log *Log `yaml:"log"`
Tracing *Tracing `yaml:"tracing"`
OcisURL string `yaml:"ocis_url" env:"OCIS_URL"`
TokenManager *TokenManager `yaml:"token_manager"`
Log *Log `yaml:"log"`
Tracing *Tracing `yaml:"tracing"`
OcisURL string `yaml:"ocis_url" env:"OCIS_URL"`
TokenManager *TokenManager `yaml:"token_manager"`
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY"`
}
19 changes: 8 additions & 11 deletions ocis/pkg/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"gopkg.in/yaml.v3"

idm "github.com/owncloud/ocis/extensions/idm/pkg/config"
notifications "github.com/owncloud/ocis/extensions/notifications/pkg/config"
ocs "github.com/owncloud/ocis/extensions/ocs/pkg/config"
proxy "github.com/owncloud/ocis/extensions/proxy/pkg/config"
settings "github.com/owncloud/ocis/extensions/settings/pkg/config"
storage "github.com/owncloud/ocis/extensions/storage/pkg/config"
Expand Down Expand Up @@ -109,9 +107,9 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
IDM: &idm.Config{},
//IDP: &idp.Config{},
//Nats: &nats.Config{},
Notifications: &notifications.Config{},
//Notifications: &notifications.Config{},
//Proxy: &proxy.Config{},
OCS: &ocs.Config{},
//OCS: &ocs.Config{},
Settings: &settings.Config{},
Storage: &storage.Config{},
Thumbnails: &thumbnails.Config{},
Expand Down Expand Up @@ -144,7 +142,7 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
if err != nil {
return fmt.Errorf("Could not generate random password for tokenmanager: %s", err)
}
machineAuthSecret, err := generators.GenerateRandomPassword(passwordLength)
machineAuthApiKey, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for machineauthsecret: %s", err)
}
Expand All @@ -158,10 +156,9 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
// TODO: graph needs IDM password configured
// TODO: add missing insecure occurences
// TODO: search for missing transfer secrets
// TODO: move TokenManager for all extensions to shared
// TODO: move machineauthsecret for all extensions to shared
// TODO: move transfersecret for all extensions to shared

cfg.MachineAuthAPIKey = machineAuthApiKey
cfg.TokenManager.JWTSecret = tokenManagerJwtSecret
//cfg.Commons.TokenManager.JWTSecret = tokenManagerJwtSecret
//cfg.Accounts.TokenManager.JWTSecret = tokenManagerJwtSecret
Expand All @@ -171,12 +168,12 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
cfg.IDM.ServiceUserPasswords.Idp = idpServicePassword
cfg.IDM.ServiceUserPasswords.OcisAdmin = ocisAdminServicePassword
cfg.IDM.ServiceUserPasswords.Reva = revaServicePassword
cfg.Notifications.Notifications.MachineAuthSecret = machineAuthSecret
cfg.OCS.MachineAuthAPIKey = machineAuthSecret
//cfg.Notifications.Notifications.MachineAuthAPIKey = machineAuthSecret
//cfg.OCS.MachineAuthAPIKey = machineAuthSecret
//cfg.Proxy.TokenManager.JWTSecret = tokenManagerJwtSecret
//fmt.Printf("%v\n", cfg.Proxy.TokenManager)
cfg.Proxy.MachineAuthAPIKey = machineAuthSecret
cfg.Settings.Metadata.MachineAuthAPIKey = machineAuthSecret
//cfg.Proxy.MachineAuthAPIKey = machineAuthSecret
//cfg.Settings.Metadata.MachineAuthAPIKey = machineAuthSecret
//cfg.Settings.TokenManager.JWTSecret = tokenManagerJwtSecret
cfg.Storage.Reva.JWTSecret = tokenManagerJwtSecret
cfg.Storage.OCDav.JWTSecret = tokenManagerJwtSecret
Expand Down
7 changes: 0 additions & 7 deletions ocis/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/ocis/pkg/runtime"
"github.com/urfave/cli/v2"
Expand All @@ -20,12 +19,6 @@ func Server(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {

cfg.Commons = &shared.Commons{
Log: cfg.Log,
Tracing: cfg.Tracing,
TokenManager: cfg.TokenManager,
}

r := runtime.New(cfg)
return r.Start()
},
Expand Down

0 comments on commit 4a13035

Please sign in to comment.