diff --git a/hosting/kubernetes/envoy/envoy.yaml b/hosting/kubernetes/envoy/envoy.yaml index 0e7859d887..1041287f5e 100644 --- a/hosting/kubernetes/envoy/envoy.yaml +++ b/hosting/kubernetes/envoy/envoy.yaml @@ -33,11 +33,19 @@ static_resources: route: cluster: app-service - # special case for worker admin API + # special cases for worker admin (deprecated), global and system API + - match: { prefix: "/api/global/" } + route: + cluster: worker-service + - match: { prefix: "/api/admin/" } route: cluster: worker-service + - match: { prefix: "/api/system/" } + route: + cluster: worker-service + - match: { path: "/" } route: cluster: app-service diff --git a/lerna.json b/lerna.json index d98092c638..68d6b0ed22 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/auth/package.json b/packages/auth/package.json index 5842d7f30c..f6c393d3ef 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/auth", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "description": "Authentication middlewares for budibase builder and apps", "main": "src/index.js", "author": "Budibase", diff --git a/packages/auth/src/cache/user.js b/packages/auth/src/cache/user.js index 4a19da489f..e0936182a7 100644 --- a/packages/auth/src/cache/user.js +++ b/packages/auth/src/cache/user.js @@ -18,6 +18,10 @@ exports.getUser = async (userId, tenantId = null) => { user = await getGlobalDB(tenantId).get(userId) client.store(userId, user, EXPIRY_SECONDS) } + if (user && !user.tenantId && tenantId) { + // make sure the tenant ID is always correct/set + user.tenantId = tenantId + } return user } diff --git a/packages/auth/src/middleware/tenancy.js b/packages/auth/src/middleware/tenancy.js index b80b9a6763..19cce82273 100644 --- a/packages/auth/src/middleware/tenancy.js +++ b/packages/auth/src/middleware/tenancy.js @@ -2,12 +2,13 @@ const { setTenantId } = require("../tenancy") const ContextFactory = require("../tenancy/FunctionContext") const { buildMatcherRegex, matches } = require("./matchers") -module.exports = (allowQueryStringPatterns, noTenancyPatterns) => { +module.exports = (allowQueryStringPatterns, noTenancyPatterns, opts = {}) => { const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns) const noTenancyOptions = buildMatcherRegex(noTenancyPatterns) return ContextFactory.getMiddleware(ctx => { - const allowNoTenant = !!matches(ctx, noTenancyOptions) + const allowNoTenant = + opts.noTenancyRequired || !!matches(ctx, noTenancyOptions) const allowQs = !!matches(ctx, allowQsOptions) setTenantId(ctx, { allowQs, allowNoTenant }) }) diff --git a/packages/bbui/package.json b/packages/bbui/package.json index bb2b4d367a..7d1f3793f5 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "license": "AGPL-3.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", diff --git a/packages/builder/package.json b/packages/builder/package.json index c829605ed8..8128361a61 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "license": "AGPL-3.0", "private": true, "scripts": { @@ -65,10 +65,10 @@ } }, "dependencies": { - "@budibase/bbui": "^0.9.120-alpha.3", - "@budibase/client": "^0.9.120-alpha.3", + "@budibase/bbui": "^0.9.123-alpha.0", + "@budibase/client": "^0.9.123-alpha.0", "@budibase/colorpicker": "1.1.2", - "@budibase/string-templates": "^0.9.120-alpha.3", + "@budibase/string-templates": "^0.9.123-alpha.0", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index 3b2848f16b..42f986c445 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "description": "Budibase CLI, for developers, self hosting and migrations.", "main": "src/index.js", "bin": { diff --git a/packages/client/package.json b/packages/client/package.json index 60b8d74884..07449e22f3 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "license": "MPL-2.0", "module": "dist/budibase-client.js", "main": "dist/budibase-client.js", @@ -18,9 +18,9 @@ "dev:builder": "rollup -cw" }, "dependencies": { - "@budibase/bbui": "^0.9.120-alpha.3", - "@budibase/standard-components": "^0.9.120-alpha.3", - "@budibase/string-templates": "^0.9.120-alpha.3", + "@budibase/bbui": "^0.9.123-alpha.0", + "@budibase/standard-components": "^0.9.123-alpha.0", + "@budibase/string-templates": "^0.9.123-alpha.0", "regexparam": "^1.3.0", "shortid": "^2.2.15", "svelte-spa-router": "^3.0.5" diff --git a/packages/server/package.json b/packages/server/package.json index eec510944f..da08ba8ca3 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/server", "email": "hi@budibase.com", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "description": "Budibase Web Server", "main": "src/index.js", "repository": { @@ -62,9 +62,9 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.120-alpha.3", - "@budibase/client": "^0.9.120-alpha.3", - "@budibase/string-templates": "^0.9.120-alpha.3", + "@budibase/auth": "^0.9.123-alpha.0", + "@budibase/client": "^0.9.123-alpha.0", + "@budibase/string-templates": "^0.9.123-alpha.0", "@elastic/elasticsearch": "7.10.0", "@koa/router": "8.0.0", "@sendgrid/mail": "7.1.1", @@ -117,7 +117,7 @@ "devDependencies": { "@babel/core": "^7.14.3", "@babel/preset-env": "^7.14.4", - "@budibase/standard-components": "^0.9.120-alpha.3", + "@budibase/standard-components": "^0.9.123-alpha.0", "@jest/test-sequencer": "^24.8.0", "@types/bull": "^3.15.1", "@types/jest": "^26.0.23", diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index c473bf619b..24567b54a6 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -10,13 +10,6 @@ const env = require("../environment") const router = new Router() -const NO_TENANCY_ENDPOINTS = [ - { - route: "/api/analytics", - method: "GET", - }, -] - router .use( compress({ @@ -39,13 +32,21 @@ router }) .use("/health", ctx => (ctx.status = 200)) .use("/version", ctx => (ctx.body = pkg.version)) + // re-direct before any middlewares occur + .redirect("/", "/builder") .use( buildAuthMiddleware(null, { publicAllowed: true, }) ) // nothing in the server should allow query string tenants - .use(buildTenancyMiddleware(null, NO_TENANCY_ENDPOINTS)) + // the server can be public anywhere, so nowhere should throw errors + // if the tenancy has not been set, it'll have to be discovered at application layer + .use( + buildTenancyMiddleware(null, null, { + noTenancyRequired: true, + }) + ) .use(currentApp) .use(auditLog) @@ -79,7 +80,4 @@ for (let route of mainRoutes) { router.use(staticRoutes.routes()) router.use(staticRoutes.allowedMethods()) -// add a redirect for when hitting server directly -router.redirect("/", "/builder") - module.exports = router diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index e48090a478..8b43a42110 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -29,11 +29,11 @@ "keywords": [ "svelte" ], - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "license": "MIT", "gitHead": "d1836a898cab3f8ab80ee6d8f42be1a9eed7dcdc", "dependencies": { - "@budibase/bbui": "^0.9.120-alpha.3", + "@budibase/bbui": "^0.9.123-alpha.0", "@spectrum-css/button": "^3.0.3", "@spectrum-css/card": "^3.0.3", "@spectrum-css/divider": "^1.0.3", diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index 782b5cf4d9..0ebe24c1ef 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "description": "Handlebars wrapper for Budibase templating.", "main": "src/index.cjs", "module": "dist/bundle.mjs", diff --git a/packages/worker/package.json b/packages/worker/package.json index 2278a60b1f..7b7675d9b7 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/worker", "email": "hi@budibase.com", - "version": "0.9.120-alpha.3", + "version": "0.9.123-alpha.0", "description": "Budibase background service", "main": "src/index.js", "repository": { @@ -23,8 +23,8 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.120-alpha.3", - "@budibase/string-templates": "^0.9.120-alpha.3", + "@budibase/auth": "^0.9.123-alpha.0", + "@budibase/string-templates": "^0.9.123-alpha.0", "@koa/router": "^8.0.0", "@techpass/passport-openidconnect": "^0.3.0", "aws-sdk": "^2.811.0",