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

Disable index creation external auth prefix #638

Open
wants to merge 5 commits into
base: disable-index-creation
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ RUN ["make", "service-build"]
CMD ["make", "service-start"]

# Production
FROM mongo:4.2.14 AS production
ENV ENV="/home/tidepool/.bashrc" DEBIAN_FRONTEND="noninteractive"
FROM mongo:6.0.5 AS production
# this statically set $HOME is non-ideal, but is to combat it being hardcoded to /data/db upstream
ENV HOME="/home/tidepool/" DEBIAN_FRONTEND="noninteractive"
RUN apt -y update && \
apt -y install ca-certificates tzdata && \
adduser --disabled-password tidepool
Expand Down
2 changes: 2 additions & 0 deletions auth/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var _ = Describe("Client", func() {
Expect(config).ToNot(BeNil())
Expect(config.Config).ToNot(BeNil())
config.Config.Address = testHttp.NewAddress()
config.ExternalConfig.PathPrefix = "auth"
config.Config.UserAgent = testHttp.NewUserAgent()
config.Config.ServiceSecret = authTest.NewServiceSecret()
config.ExternalConfig.Address = testHttp.NewAddress()
Expand Down Expand Up @@ -112,6 +113,7 @@ var _ = Describe("Client", func() {
Expect(config).ToNot(BeNil())
Expect(config.Config).ToNot(BeNil())
config.Config.Address = server.URL()
config.ExternalConfig.PathPrefix = "auth"
config.Config.UserAgent = testHttp.NewUserAgent()
config.Config.ServiceSecret = authTest.NewServiceSecret()
config.ExternalConfig.Address = server.URL()
Expand Down
9 changes: 7 additions & 2 deletions auth/client/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type ExternalConfig struct {
*platform.Config
ServerSessionTokenSecret string
ServerSessionTokenTimeout time.Duration
// PathPrefix is the prefix to include in all calls to the external service, if any.
PathPrefix string
}

func NewExternalConfig() *ExternalConfig {
Expand All @@ -83,6 +85,7 @@ func (e *ExternalConfig) Load(configReporter config.Reporter) error {
}
e.ServerSessionTokenTimeout = time.Duration(serverSessionTokenTimeoutInteger) * time.Second
}
e.PathPrefix = configReporter.GetWithDefault("path_prefix", "auth")

return nil
}
Expand Down Expand Up @@ -110,6 +113,7 @@ type External struct {
serverSessionTokenTimeout time.Duration
serverSessionTokenMutex sync.Mutex
serverSessionTokenSafe string
pathPrefix string
closingChannel chan chan bool
}

Expand Down Expand Up @@ -139,6 +143,7 @@ func NewExternal(cfg *ExternalConfig, authorizeAs platform.AuthorizeAs, name str
name: name,
serverSessionTokenSecret: cfg.ServerSessionTokenSecret,
serverSessionTokenTimeout: cfg.ServerSessionTokenTimeout,
pathPrefix: cfg.PathPrefix,
}, nil
}

Expand Down Expand Up @@ -204,7 +209,7 @@ func (e *External) ValidateSessionToken(ctx context.Context, token string) (requ
IsServer bool
UserID string
}
if err := e.client.RequestData(ctx, "GET", e.client.ConstructURL("auth", "token", token), nil, nil, &result); err != nil {
if err := e.client.RequestData(ctx, "GET", e.client.ConstructURL(e.pathPrefix, "token", token), nil, nil, &result); err != nil {
return nil, err
}

Expand Down Expand Up @@ -305,7 +310,7 @@ func (e *External) refreshServerSessionToken() error {
e.logger.Debug("Refreshing server session token")

requestMethod := "POST"
requestURL := e.client.ConstructURL("auth", "serverlogin")
requestURL := e.client.ConstructURL(e.pathPrefix, "serverlogin")
request, err := http.NewRequest(requestMethod, requestURL, nil)
if err != nil {
return errors.Wrapf(err, "unable to create new request for %s %s", requestMethod, requestURL)
Expand Down
6 changes: 5 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ func New(cfg *Config) (*Client, error) {
func (c *Client) ConstructURL(paths ...string) string {
segments := []string{}
for _, path := range paths {
segments = append(segments, url.PathEscape(strings.Trim(path, "/")))
escapedPath := url.PathEscape(strings.Trim(path, "/"))
if escapedPath == "" {
continue
}
segments = append(segments, escapedPath)
}
return fmt.Sprintf("%s/%s", strings.TrimRight(c.address, "/"), strings.Join(segments, "/"))
}
Expand Down
1 change: 1 addition & 0 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export TIDEPOOL_PERMISSION_CLIENT_ADDRESS="http://localhost:8009"
export TIDEPOOL_TASK_CLIENT_ADDRESS="http://localhost:8009"
export TIDEPOOL_USER_CLIENT_ADDRESS="http://localhost:8009"

export TIDEPOOL_AUTH_CLIENT_EXTERNAL_PATH_PREFIX="auth"
export TIDEPOOL_AUTH_CLIENT_EXTERNAL_ADDRESS="http://localhost:8009"
export TIDEPOOL_AUTH_CLIENT_EXTERNAL_SERVER_SESSION_TOKEN_SECRET="This needs to be the same secret everywhere. YaHut75NsK1f9UKUXuWqxNN0RUwHFBCy"

Expand Down
6 changes: 3 additions & 3 deletions tools/ashrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NOTE: admin and readonly usernames are assembled by attaching mongo-*-readonly and mongo-*-admin around the last dashed term in the service TIDEPOOL_STORE_USERNAME

alias mongo=$'/usr/bin/mongo "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "mongo-${TIDEPOOL_STORE_USERNAME##*-}-readonly" ${TIDEPOOL_STORE_PASSWORD:+-p "$TIDEPOOL_STORE_PASSWORD"}'
alias mongo=$'/usr/bin/mongosh "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "mongo-${TIDEPOOL_STORE_USERNAME##*-}-readonly" ${TIDEPOOL_STORE_PASSWORD:+-p "$TIDEPOOL_STORE_PASSWORD"}'

alias mongow=$'/usr/bin/mongo "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "$TIDEPOOL_STORE_USERNAME -p'
alias mongow=$'/usr/bin/mongosh "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "$TIDEPOOL_STORE_USERNAME -p'

alias mongoa=$'/usr/bin/mongo "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "mongo-${TIDEPOOL_STORE_USERNAME##*-}-admin" -p'
alias mongoa=$'/usr/bin/mongosh "${TIDEPOOL_STORE_SCHEME}://${TIDEPOOL_STORE_ADDRESSES}/${TIDEPOOL_STORE_DATABASE}?${TIDEPOOL_STORE_OPT_PARAMS}" $( [ "$TIDEPOOL_STORE_TLS" == "true" ] && echo "--tls" ) --username "mongo-${TIDEPOOL_STORE_USERNAME##*-}-admin" -p'