Skip to content

Commit bd46fac

Browse files
authored
enhance: add option to disable bootstrap user (#1368)
Signed-off-by: Grant Linville <[email protected]>
1 parent a857327 commit bd46fac

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

chart/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ spec:
7979
name: {{ include "obot.config.secretName" . }}
8080
key: githubAuthToken
8181
{{- end }}
82+
- name: "OBOT_SERVER_ENABLE_BOOTSTRAP_USER"
83+
value: "{{ .Values.config.obotServerEnableBootstrapUser }}"
8284
{{- if .Values.config.obotServerAuthAdminEmails }}
8385
- name: "OBOT_SERVER_AUTH_ADMIN_EMAILS"
8486
valueFrom:

chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ config:
5858
awsRegion: ""
5959
awsSecretAccessKey: ""
6060
baaahThreadiness: "20"
61+
6162
githubAuthToken: ""
6263
obotServerEnableAuthentication: true
64+
obotServerEnableBootstrapUser: true
6365
obotBootstrapToken: ""
6466
obotServerAuthAdminEmails: ""
6567
obotServerDSN: ""

docs/docs/05-configuration/03-auth-providers.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ Obot currently supports the following authentication providers (using OAuth2):
4343
- Google
4444

4545
The code for these providers is available in the [Obot tools repo](https://github.com/obot-platform/tools).
46+
47+
## Disabling the Bootstrap User
48+
49+
If you do not want to be able to log in as the bootstrap user, you can set the `OBOT_SERVER_ENABLE_BOOTSTRAP_USER` environment variable to `false`.
50+
This will prevent you from logging in as the bootstrap user.
51+
When you first run Obot, do not set this environment variable, because you need to be able to use the bootstrap user to set up the first auth provider.
52+
Once that is done, you can restart the server and set this environment variable if you would like.

pkg/bootstrap/bootstrap.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bootstrap
22

33
import (
4+
"context"
45
"crypto/rand"
56
"fmt"
67
"net/http"
@@ -11,22 +12,25 @@ import (
1112
"github.com/obot-platform/obot/pkg/api"
1213
"github.com/obot-platform/obot/pkg/api/authz"
1314
"github.com/obot-platform/obot/pkg/gateway/client"
15+
"github.com/obot-platform/obot/pkg/gateway/server/dispatcher"
1416
"github.com/obot-platform/obot/pkg/gateway/types"
17+
"github.com/obot-platform/obot/pkg/system"
1518
"k8s.io/apiserver/pkg/authentication/authenticator"
1619
"k8s.io/apiserver/pkg/authentication/user"
1720
)
1821

1922
const bootstrapCookie = "obot-bootstrap"
2023

2124
type Bootstrap struct {
22-
token, serverURL string
23-
gatewayClient *client.Client
25+
enableBootstrapUser bool
26+
token, serverURL string
27+
gatewayClient *client.Client
2428
}
2529

26-
func New(serverURL string, c *client.Client) (*Bootstrap, error) {
30+
func New(ctx context.Context, enableBootstrapUser bool, serverURL string, c *client.Client, d *dispatcher.Dispatcher) (*Bootstrap, error) {
2731
token := os.Getenv("OBOT_BOOTSTRAP_TOKEN")
2832

29-
if token == "" {
33+
if token == "" && enableBootstrapUser {
3034
bytes := make([]byte, 32)
3135
_, err := rand.Read(bytes)
3236
if err != nil {
@@ -37,16 +41,26 @@ func New(serverURL string, c *client.Client) (*Bootstrap, error) {
3741

3842
// We deliberately only print the token if it was not provided by the user.
3943
fmt.Printf("Bootstrap token: %s\nUse this token to log in to the Admin UI.\n", token)
44+
} else if !enableBootstrapUser {
45+
configuredAuthProviders, err := d.ListConfiguredAuthProviders(ctx, system.DefaultNamespace)
46+
if err == nil && len(configuredAuthProviders) == 0 {
47+
fmt.Printf("WARNING: Bootstrap user is disabled, and no auth providers are configured. You will be unable to log in to Obot.\n")
48+
}
4049
}
4150

4251
return &Bootstrap{
43-
token: token,
44-
serverURL: serverURL,
45-
gatewayClient: c,
52+
enableBootstrapUser: enableBootstrapUser,
53+
token: token,
54+
serverURL: serverURL,
55+
gatewayClient: c,
4656
}, nil
4757
}
4858

4959
func (b *Bootstrap) AuthenticateRequest(req *http.Request) (*authenticator.Response, bool, error) {
60+
if !b.enableBootstrapUser {
61+
return nil, false, nil
62+
}
63+
5064
authHeader := req.Header.Get("Authorization")
5165
if authHeader == "" {
5266
// Check for the cookie.
@@ -80,6 +94,11 @@ func (b *Bootstrap) AuthenticateRequest(req *http.Request) (*authenticator.Respo
8094
}
8195

8296
func (b *Bootstrap) Login(req api.Context) error {
97+
if !b.enableBootstrapUser {
98+
http.Error(req.ResponseWriter, "invalid token", http.StatusUnauthorized)
99+
return nil
100+
}
101+
83102
auth := req.Request.Header.Get("Authorization")
84103
if auth == "" {
85104
http.Error(req.ResponseWriter, "missing Authorization header", http.StatusBadRequest)

pkg/services/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type Config struct {
6666
EnvKeys []string `usage:"The environment keys to pass through to the GPTScript server" env:"OBOT_ENV_KEYS"`
6767
KnowledgeSetIngestionLimit int `usage:"The maximum number of files to ingest into a knowledge set" default:"3000" env:"OBOT_KNOWLEDGESET_INGESTION_LIMIT" name:"knowledge-set-ingestion-limit"`
6868
EnableAuthentication bool `usage:"Enable authentication" default:"false"`
69+
EnableBootstrapUser bool `usage:"Enables the bootstrap user, regardless of configured auth providers" default:"true"`
6970
AuthAdminEmails []string `usage:"Emails of admin users"`
7071

7172
// Sendgrid webhook
@@ -305,7 +306,7 @@ func New(ctx context.Context, config Config) (*Services, error) {
305306
proxyManager *proxy.Manager
306307
)
307308

308-
bootstrapper, err := bootstrap.New(config.Hostname, gatewayClient)
309+
bootstrapper, err := bootstrap.New(ctx, config.EnableBootstrapUser, config.Hostname, gatewayClient, providerDispatcher)
309310
if err != nil {
310311
return nil, err
311312
}

0 commit comments

Comments
 (0)