Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sms authentication in local dev #1274

Merged
merged 7 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
93 changes: 63 additions & 30 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,7 @@ EOF
// Start Kong.
p.Send(utils.StatusMsg("Starting containers..."))
if !isContainerExcluded(utils.KongImage, excluded) {
env := []string{
"KONG_DATABASE=off",
"KONG_DECLARATIVE_CONFIG=/home/kong/kong.yml",
"KONG_DNS_ORDER=LAST,A,CNAME", // https://github.com/supabase/cli/issues/14
"KONG_PLUGINS=request-transformer,cors",
// Need to increase the nginx buffers in kong to avoid it rejecting the rather
// sizeable response headers azure can generate
// Ref: https://github.com/Kong/kong/issues/3974#issuecomment-482105126
"KONG_NGINX_PROXY_PROXY_BUFFER_SIZE=160k",
"KONG_NGINX_PROXY_PROXY_BUFFERS=64 160k",
}

if utils.Config.Kong.NginxWorkerProcesses != 0 {
env = append(env, fmt.Sprintf("KONG_NGINX_WORKER_PROCESSES=%d", utils.Config.Kong.NginxWorkerProcesses))
}

var kongConfigBuf bytes.Buffer

if err := kongConfigTemplate.Execute(&kongConfigBuf, kongConfig{
GotrueId: utils.GotrueId,
RestId: utils.RestId,
Expand All @@ -299,7 +282,18 @@ EOF
ctx,
container.Config{
Image: utils.KongImage,
Env: env,
Env: []string{
"KONG_DATABASE=off",
"KONG_DECLARATIVE_CONFIG=/home/kong/kong.yml",
"KONG_DNS_ORDER=LAST,A,CNAME", // https://github.com/supabase/cli/issues/14
"KONG_PLUGINS=request-transformer,cors",
// Need to increase the nginx buffers in kong to avoid it rejecting the rather
// sizeable response headers azure can generate
// Ref: https://github.com/Kong/kong/issues/3974#issuecomment-482105126
"KONG_NGINX_PROXY_PROXY_BUFFER_SIZE=160k",
"KONG_NGINX_PROXY_PROXY_BUFFERS=64 160k",
"KONG_NGINX_WORKER_PROCESSES=1",
},
Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /home/kong/kong.yml && ./docker-entrypoint.sh kong docker-start
` + kongConfigBuf.String() + `
EOF
Expand Down Expand Up @@ -329,17 +323,17 @@ EOF

"GOTRUE_SITE_URL=" + utils.Config.Auth.SiteUrl,
"GOTRUE_URI_ALLOW_LIST=" + strings.Join(utils.Config.Auth.AdditionalRedirectUrls, ","),
fmt.Sprintf("GOTRUE_DISABLE_SIGNUP=%v", !*utils.Config.Auth.EnableSignup),
fmt.Sprintf("GOTRUE_DISABLE_SIGNUP=%v", !utils.Config.Auth.EnableSignup),

"GOTRUE_JWT_ADMIN_ROLES=service_role",
"GOTRUE_JWT_AUD=authenticated",
"GOTRUE_JWT_DEFAULT_GROUP_NAME=authenticated",
fmt.Sprintf("GOTRUE_JWT_EXP=%v", utils.Config.Auth.JwtExpiry),
"GOTRUE_JWT_SECRET=" + utils.Config.Auth.JwtSecret,

fmt.Sprintf("GOTRUE_EXTERNAL_EMAIL_ENABLED=%v", *utils.Config.Auth.Email.EnableSignup),
fmt.Sprintf("GOTRUE_MAILER_SECURE_EMAIL_CHANGE_ENABLED=%v", *utils.Config.Auth.Email.DoubleConfirmChanges),
fmt.Sprintf("GOTRUE_MAILER_AUTOCONFIRM=%v", !*utils.Config.Auth.Email.EnableConfirmations),
fmt.Sprintf("GOTRUE_EXTERNAL_EMAIL_ENABLED=%v", utils.Config.Auth.Email.EnableSignup),
fmt.Sprintf("GOTRUE_MAILER_SECURE_EMAIL_CHANGE_ENABLED=%v", utils.Config.Auth.Email.DoubleConfirmChanges),
fmt.Sprintf("GOTRUE_MAILER_AUTOCONFIRM=%v", !utils.Config.Auth.Email.EnableConfirmations),

"GOTRUE_SMTP_HOST=" + utils.InbucketId,
"GOTRUE_SMTP_PORT=2500",
Expand All @@ -351,13 +345,52 @@ EOF
"GOTRUE_MAILER_URLPATHS_EMAIL_CHANGE=/auth/v1/verify",
"GOTRUE_RATE_LIMIT_EMAIL_SENT=360000",

"GOTRUE_EXTERNAL_PHONE_ENABLED=true",
"GOTRUE_SMS_AUTOCONFIRM=true",
fmt.Sprintf("GOTRUE_EXTERNAL_PHONE_ENABLED=%v", utils.Config.Auth.Sms.EnableSignup),
fmt.Sprintf("GOTRUE_SMS_AUTOCONFIRM=%v", !utils.Config.Auth.Sms.EnableConfirmations),
"GOTRUE_SMS_MAX_FREQUENCY=5s",
"GOTRUE_SMS_OTP_EXP=6000",
"GOTRUE_SMS_OTP_LENGTH=6",
"GOTRUE_SMS_TEMPLATE=Your code is {{ .Code }}",

fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_ROTATION_ENABLED=%v", *utils.Config.Auth.EnableRefreshTokenRotation),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_ROTATION_ENABLED=%v", utils.Config.Auth.EnableRefreshTokenRotation),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL=%v", utils.Config.Auth.RefreshTokenReuseInterval),
}

if utils.Config.Auth.Sms.Twilio.Enabled {
env = append(
env,
"GOTRUE_SMS_PROVIDER=twilio",
"GOTRUE_SMS_TWILIO_ACCOUNT_SID="+utils.Config.Auth.Sms.Twilio.AccountSid,
"GOTRUE_SMS_TWILIO_AUTH_TOKEN="+utils.Config.Auth.Sms.Twilio.AuthToken,
"GOTRUE_SMS_TWILIO_MESSAGE_SERVICE_SID="+utils.Config.Auth.Sms.Twilio.MessageServiceSid,
)
}
if utils.Config.Auth.Sms.Messagebird.Enabled {
env = append(
env,
"GOTRUE_SMS_PROVIDER=messagebird",
"GOTRUE_SMS_MESSAGEBIRD_ACCESS_KEY="+utils.Config.Auth.Sms.Messagebird.AccessKey,
"GOTRUE_SMS_MESSAGEBIRD_ORIGINATOR="+utils.Config.Auth.Sms.Messagebird.Originator,
)
}
if utils.Config.Auth.Sms.Textlocal.Enabled {
env = append(
env,
"GOTRUE_SMS_PROVIDER=textlocal",
"GOTRUE_SMS_TEXTLOCAL_API_KEY="+utils.Config.Auth.Sms.Textlocal.ApiKey,
"GOTRUE_SMS_TEXTLOCAL_SENDER="+utils.Config.Auth.Sms.Textlocal.Sender,
)
}
if utils.Config.Auth.Sms.Vonage.Enabled {
env = append(
env,
"GOTRUE_SMS_PROVIDER=vonage",
"GOTRUE_SMS_VONAGE_API_KEY="+utils.Config.Auth.Sms.Vonage.ApiKey,
"GOTRUE_SMS_VONAGE_API_SECRET="+utils.Config.Auth.Sms.Vonage.ApiSecret,
"GOTRUE_SMS_VONAGE_FROM="+utils.Config.Auth.Sms.Vonage.From,
)
}

for name, config := range utils.Config.Auth.External {
env = append(
env,
Expand Down Expand Up @@ -407,7 +440,7 @@ EOF
}

// Start Inbucket.
if !isContainerExcluded(utils.InbucketImage, excluded) {
if utils.Config.Inbucket.Enabled && !isContainerExcluded(utils.InbucketImage, excluded) {
inbucketPortBindings := nat.PortMap{"9000/tcp": []nat.PortBinding{{HostPort: strconv.FormatUint(uint64(utils.Config.Inbucket.Port), 10)}}}
if utils.Config.Inbucket.SmtpPort != 0 {
inbucketPortBindings["2500/tcp"] = []nat.PortBinding{{HostPort: strconv.FormatUint(uint64(utils.Config.Inbucket.SmtpPort), 10)}}
Expand Down Expand Up @@ -582,7 +615,7 @@ EOF
}

// Start pg-meta.
if !isContainerExcluded(utils.PgmetaImage, excluded) {
if utils.Config.Studio.Enabled && !isContainerExcluded(utils.PgmetaImage, excluded) {
if _, err := utils.DockerStart(
ctx,
container.Config{
Expand Down Expand Up @@ -613,7 +646,7 @@ EOF
}

// Start Studio.
if !isContainerExcluded(utils.StudioImage, excluded) {
if utils.Config.Studio.Enabled && !isContainerExcluded(utils.StudioImage, excluded) {
if _, err := utils.DockerStart(
ctx,
container.Config{
Expand All @@ -622,8 +655,8 @@ EOF
"STUDIO_PG_META_URL=http://" + utils.PgmetaId + ":8080",
"POSTGRES_PASSWORD=" + dbConfig.Password,
"SUPABASE_URL=http://" + utils.KongId + ":8000",
fmt.Sprintf("SUPABASE_REST_URL=http://localhost:%v/rest/v1/", utils.Config.Api.Port),
fmt.Sprintf("SUPABASE_PUBLIC_URL=http://localhost:%v/", utils.Config.Api.Port),
fmt.Sprintf("SUPABASE_REST_URL=%s:%v/rest/v1/", utils.Config.Studio.ApiUrl, utils.Config.Api.Port),
fmt.Sprintf("SUPABASE_PUBLIC_URL=%s:%v/", utils.Config.Studio.ApiUrl, utils.Config.Api.Port),
"SUPABASE_ANON_KEY=" + utils.Config.Auth.AnonKey,
"SUPABASE_SERVICE_KEY=" + utils.Config.Auth.ServiceRoleKey,
"LOGFLARE_API_KEY=" + utils.Config.Analytics.ApiKey,
Expand Down
9 changes: 4 additions & 5 deletions internal/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ func TestDatabaseStart(t *testing.T) {
utils.KongId = "test-kong"
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.KongImage), utils.KongId)
utils.GotrueId = "test-gotrue"
flag := true
utils.Config.Auth.EnableSignup = &flag
utils.Config.Auth.Email.EnableSignup = &flag
utils.Config.Auth.Email.DoubleConfirmChanges = &flag
utils.Config.Auth.Email.EnableConfirmations = &flag
utils.Config.Auth.EnableSignup = true
utils.Config.Auth.Email.EnableSignup = true
utils.Config.Auth.Email.DoubleConfirmChanges = true
utils.Config.Auth.Email.EnableConfirmations = true
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.GotrueImage), utils.GotrueId)
utils.InbucketId = "test-inbucket"
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.InbucketImage), utils.InbucketId)
Expand Down
Loading