feat: run on a single port (#3163)

* start v2

* start

* run

* some cleanup

* remove v2 pkg again

* simplify

* webauthn

* remove unused config

* fix login path in Dockerfile

* fix asset_generator.go

* health handler

* fix grpc web

* refactor

* merge

* build new main.go

* run new main.go

* update logging pkg

* fix error msg

* update logging

* cleanup

* cleanup

* go mod tidy

* change localDevMode

* fix customEndpoints

* update logging

* comments

* change local flag to external configs

* fix location generated go code

* fix

Co-authored-by: fforootd <florian@caos.ch>
This commit is contained in:
Livio Amstutz
2022-02-14 17:22:30 +01:00
committed by GitHub
parent 2f3a482ade
commit 389eb4a27a
306 changed files with 1708 additions and 1567 deletions

View File

@@ -1,37 +0,0 @@
package config
import (
"flag"
"strings"
)
var _ flag.Value = (*ArrayFlags)(nil)
//ArrayFlags implements the flag/Value interface
//allowing to set multiple string flags with the same name
type ArrayFlags struct {
defaultValues []string
values []string
}
func NewArrayFlags(defaults ...string) *ArrayFlags {
return &ArrayFlags{
defaultValues: defaults,
}
}
func (i *ArrayFlags) Values() []string {
if len(i.values) == 0 {
return i.defaultValues
}
return i.values
}
func (i *ArrayFlags) String() string {
return strings.Join(i.Values(), ";")
}
func (i *ArrayFlags) Set(value string) error {
i.values = append(i.values, value)
return nil
}

View File

@@ -1,13 +1,14 @@
package systemdefaults
import (
"github.com/caos/zitadel/internal/notification/channels/log"
"time"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/config/types"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/notification/channels/chat"
"github.com/caos/zitadel/internal/notification/channels/fs"
"github.com/caos/zitadel/internal/notification/channels/log"
"github.com/caos/zitadel/internal/notification/channels/smtp"
"github.com/caos/zitadel/internal/notification/channels/twilio"
"github.com/caos/zitadel/internal/notification/templates"
@@ -25,7 +26,6 @@ type SystemDefaults struct {
DomainVerification DomainVerification
IamID string
Notifications Notifications
WebAuthN WebAuthN
KeyConfig KeyConfig
}
@@ -56,11 +56,11 @@ type OTPConfig struct {
}
type VerificationLifetimes struct {
PasswordCheck types.Duration
ExternalLoginCheck types.Duration
MFAInitSkip types.Duration
SecondFactorCheck types.Duration
MultiFactorCheck types.Duration
PasswordCheck time.Duration
ExternalLoginCheck time.Duration
MFAInitSkip time.Duration
SecondFactorCheck time.Duration
MultiFactorCheck time.Duration
}
type DomainVerification struct {
@@ -99,18 +99,10 @@ type TemplateData struct {
DomainClaimed templates.TemplateData
}
type WebAuthN struct {
ID string
OriginLogin string
OriginConsole string
DisplayName string
}
type KeyConfig struct {
Size int
PrivateKeyLifetime types.Duration
PublicKeyLifetime types.Duration
EncryptionConfig *crypto.KeyConfig
SigningKeyRotationCheck types.Duration
SigningKeyGracefulPeriod types.Duration
PrivateKeyLifetime time.Duration
PublicKeyLifetime time.Duration
SigningKeyRotationCheck time.Duration
SigningKeyGracefulPeriod time.Duration
}

View File

@@ -1,14 +0,0 @@
package types
import (
"time"
)
type Duration struct {
time.Duration
}
func (d *Duration) UnmarshalText(data []byte) (err error) {
d.Duration, err = time.ParseDuration(string(data))
return err
}

View File

@@ -1,46 +0,0 @@
package types
import (
"testing"
"time"
)
func TestDuration_UnmarshalText(t *testing.T) {
type args struct {
data []byte
}
tests := []struct {
name string
args args
wantErr bool
want time.Duration
}{
{
"ok",
args{
data: []byte("10s"),
},
false,
time.Duration(10 * time.Second),
},
{
"error",
args{
data: []byte("10"),
},
true,
time.Duration(0),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &Duration{}
if err := d.UnmarshalText(tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("UnmarshalText() error = %v, wantErr %v", err, tt.wantErr)
}
if d.Duration != tt.want {
t.Errorf("UnmarshalText() got = %v, want %v", d.Duration, tt.want)
}
})
}
}

View File

@@ -1,145 +0,0 @@
package types
import (
"database/sql"
"strings"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/errors"
)
const (
sslDisabledMode = "disable"
)
type SQL struct {
Host string
Port string
User string
Password string
Database string
Schema string
SSL *ssl
MaxOpenConns uint32
MaxConnLifetime Duration
MaxConnIdleTime Duration
//Additional options to be appended as options=<Options>
//The value will be taken as is. So be sure to separate multiple options by a space
Options string
}
type SQLBase struct {
Host string
Port string
Database string
Schema string
SSL sslBase
//Additional options to be appended as options=<Options>
//The value will be taken as is. So be sure to separate multiple options by a space
Options string
}
type SQLUser struct {
User string
Password string
SSL sslUser
}
type ssl struct {
sslBase
sslUser
}
type sslBase struct {
// type of connection security
Mode string
// RootCert Path to the CA certificate
RootCert string
}
type sslUser struct {
// Cert Path to the client certificate
Cert string
// Key Path to the client private key
Key string
}
func (s *SQL) connectionString() string {
fields := []string{
"host=" + s.Host,
"port=" + s.Port,
"user=" + s.User,
"dbname=" + s.Database,
"application_name=zitadel",
"sslmode=" + s.SSL.Mode,
}
if s.Options != "" {
fields = append(fields, "options="+s.Options)
}
if s.Password != "" {
fields = append(fields, "password="+s.Password)
}
s.checkSSL()
if s.SSL.Mode != sslDisabledMode {
fields = append(fields, "sslrootcert="+s.SSL.RootCert)
if s.SSL.Cert != "" {
fields = append(fields, "sslcert="+s.SSL.Cert)
}
if s.SSL.Cert != "" {
fields = append(fields, "sslkey="+s.SSL.Key)
}
}
return strings.Join(fields, " ")
}
func (s *SQL) Start() (*sql.DB, error) {
client, err := sql.Open("postgres", s.connectionString())
if err != nil {
return nil, errors.ThrowPreconditionFailed(err, "TYPES-9qBtr", "unable to open database connection")
}
// as we open many sql clients we set the max
// open cons deep. now 3(maxconn) * 8(clients) = max 24 conns per pod
client.SetMaxOpenConns(int(s.MaxOpenConns))
client.SetConnMaxLifetime(s.MaxConnLifetime.Duration)
client.SetConnMaxIdleTime(s.MaxConnIdleTime.Duration)
return client, nil
}
func (s *SQL) checkSSL() {
if s.SSL == nil || s.SSL.Mode == sslDisabledMode || s.SSL.Mode == "" {
s.SSL = &ssl{sslBase: sslBase{Mode: sslDisabledMode}}
return
}
if s.SSL.RootCert == "" {
logging.LogWithFields("TYPES-LFdzP",
"cert set", s.SSL.Cert != "",
"key set", s.SSL.Key != "",
"rootCert set", s.SSL.RootCert != "",
).Fatal("fields for secure connection missing")
}
}
func (u SQLUser) Start(base SQLBase) (*sql.DB, error) {
return (&SQL{
Host: base.Host,
Port: base.Port,
User: u.User,
Password: u.Password,
Database: base.Database,
Options: base.Options,
SSL: &ssl{
sslBase: sslBase{
Mode: base.SSL.Mode,
RootCert: base.SSL.RootCert,
},
sslUser: sslUser{
Cert: u.SSL.Cert,
Key: u.SSL.Key,
},
},
}).Start()
}