Skip to content

Commit 50bd33b

Browse files
authored
Update user in tables to use hashed password (#1667)
Fixes OPS-3123.
1 parent 869655c commit 50bd33b

14 files changed

Lines changed: 88 additions & 17 deletions

File tree

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: openopsdev
22
services:
33
tables:
44
container_name: tables
5-
image: public.ecr.aws/openops/openops-tables:0.2.10
5+
image: public.ecr.aws/openops/openops-tables:0.2.12
66
environment:
77
BASEROW_PUBLIC_URL: ${OPS_OPENOPS_TABLES_PUBLIC_URL}
88
BASEROW_PRIVATE_URL: http://localhost:3001

deploy/docker-compose/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
environment:
2222
OPS_COMPONENT: app
2323
OPS_VERSION: ${OPS_VERSION:-latest}
24-
OPS_OPENOPS_TABLES_VERSION: 0.2.10
24+
OPS_OPENOPS_TABLES_VERSION: 0.2.12
2525
OPS_ANALYTICS_VERSION: 0.14.1
2626
depends_on:
2727
openops-tables:
@@ -47,7 +47,7 @@ services:
4747
- ${HOST_AZURE_CONFIG_DIR:-openops_azure_cli_data}:/tmp/azure
4848
- ${HOST_CLOUDSDK_CONFIG:-openops_gcloud_cli_data}:/tmp/gcloud
4949
openops-tables:
50-
image: public.ecr.aws/openops/openops-tables:0.2.10
50+
image: public.ecr.aws/openops/openops-tables:0.2.12
5151
restart: unless-stopped
5252
environment:
5353
BASEROW_PUBLIC_URL: ${OPS_OPENOPS_TABLES_PUBLIC_URL}

deploy/helm/openops/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ engine:
9090
tables:
9191
name: openops-tables
9292
image: openops-tables
93-
tag: "0.2.10"
93+
tag: "0.2.12"
9494
replicas: 1
9595
env:
9696
BASEROW_PUBLIC_URL: "{{ .Values.openopsEnv.OPS_OPENOPS_TABLES_PUBLIC_URL }}"

packages/server/api/src/app/authentication/basic/authentication-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const authenticationService = {
3838

3939
const { refresh_token } = await authenticateUserInOpenOpsTables(
4040
request.email,
41-
request.password,
41+
user.password,
4242
);
4343

4444
return this.authResponse(user, refresh_token);

packages/server/api/src/app/authentication/new-user/create-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function createUser(
122122
const tablesRefreshToken = await createTablesUser(
123123
name,
124124
params.email,
125-
params.password,
125+
user.password,
126126
);
127127

128128
return {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
authenticateUserInOpenOpsTables,
3+
resetUserPassword,
4+
} from '@openops/common';
5+
import { AppSystemProp, system } from '@openops/server-shared';
6+
import { MigrationInterface, QueryRunner } from 'typeorm';
7+
8+
export class MigrateTablesUserPassword1763755045436
9+
implements MigrationInterface
10+
{
11+
name = 'MigrateTablesUserPassword1763755045436';
12+
13+
public async up(queryRunner: QueryRunner): Promise<void> {
14+
const users = await queryRunner.query(
15+
'SELECT "email", "password" FROM "user"',
16+
);
17+
18+
if (users.length === 0) {
19+
return;
20+
}
21+
22+
const adminEmail = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_EMAIL);
23+
const password = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_PASSWORD);
24+
const { token } = await authenticateUserInOpenOpsTables(
25+
adminEmail,
26+
password,
27+
);
28+
29+
for (const record of users) {
30+
if (record.email === adminEmail) {
31+
continue;
32+
}
33+
34+
await resetUserPassword(record.email, record.password, token);
35+
}
36+
}
37+
38+
public async down(_: QueryRunner): Promise<void> {
39+
throw new Error('Rollback not implemented');
40+
}
41+
}

packages/server/api/src/app/database/postgres-connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { MigrateAiConfigToAppConnection1759242268873 } from './migrations/175924
3838
import { AddTestRunActionLimitsToFlowVersion1760429290001 } from './migrations/1760429290001-AddTestRunActionLimitsToFlowVersion';
3939
import { MoveTablesWorkspaceIdFromOrganizationToProject1760500000000 } from './migrations/1760500000000-MoveTablesWorkspaceIdFromOrganizationToProject';
4040
import { AddTablesDatabaseTokenToProject1763394159990 } from './migrations/1763394159990-AddTablesTokenToProject';
41+
import { MigrateTablesUserPassword1763755045436 } from './migrations/1763755045436-MigrateTablesUserPassword';
4142

4243
const getSslConfig = (): boolean | TlsOptions => {
4344
const useSsl = system.get(AppSystemProp.POSTGRES_USE_SSL);
@@ -84,6 +85,7 @@ const getMigrations = (): (new () => MigrationInterface)[] => {
8485
AddTestRunActionLimitsToFlowVersion1760429290001,
8586
MoveTablesWorkspaceIdFromOrganizationToProject1760500000000,
8687
AddTablesDatabaseTokenToProject1763394159990,
88+
MigrateTablesUserPassword1763755045436,
8789
];
8890
};
8991

packages/server/api/src/app/database/seeds/seed-admin.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
authenticateUserInOpenOpsTables,
3+
resetUserPassword,
4+
} from '@openops/common';
15
import { AppSystemProp, logger, system } from '@openops/server-shared';
26
import { OrganizationRole, Provider, User } from '@openops/shared';
37
import { authenticationService } from '../../authentication/basic/authentication-service';
@@ -53,6 +57,7 @@ async function ensureUserExists(
5357
`Admin user already exists [${email}], updating their password`,
5458
email,
5559
);
60+
5661
await upsertAdminPassword(user, password);
5762
return user;
5863
}
@@ -73,7 +78,11 @@ async function ensureUserExists(
7378
email,
7479
);
7580

76-
return createAdminUser(email, password);
81+
user = await createAdminUser(email, password);
82+
const { token } = await authenticateUserInOpenOpsTables(email, password);
83+
await resetUserPassword(email, user.password, token);
84+
85+
return user;
7786
}
7887

7988
async function ensureOpenOpsTablesWorkspaceAndDatabaseExist(): Promise<{
@@ -160,7 +169,14 @@ async function upsertAdminPassword(
160169
): Promise<void> {
161170
const email = user.email;
162171
logger.info(`Updating password for admin [${email}]`, email);
163-
await userService.updatePassword({ id: user.id, newPassword });
172+
173+
const updatedUser = await userService.updatePassword({
174+
id: user.id,
175+
newPassword,
176+
});
177+
178+
const { token } = await authenticateUserInOpenOpsTables(email, newPassword);
179+
await resetUserPassword(email, updatedUser.password, token);
164180
}
165181

166182
async function upsertAdminEmail(user: User, email: string): Promise<void> {

packages/server/api/src/app/openops-tables/auth-admin-tables.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { authenticateUserInOpenOpsTables } from '@openops/common';
22
import { AppSystemProp, cacheWrapper, system } from '@openops/server-shared';
33
import { IAxiosRetryConfig } from 'axios-retry';
4+
import { userService } from '../user/user-service';
45

56
export type AuthTokens = {
67
token: string;
@@ -22,11 +23,11 @@ export async function authenticateAdminUserInOpenOpsTables(
2223

2324
if (!tokens) {
2425
const email = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_EMAIL);
25-
const password = system.getOrThrow(AppSystemProp.OPENOPS_ADMIN_PASSWORD);
26+
const user = await userService.getUserByEmailOrFail({ email });
2627

2728
tokens = await authenticateUserInOpenOpsTables(
2829
email,
29-
password,
30+
user.password,
3031
axiosRetryConfig,
3132
);
3233
await cacheWrapper.setSerializedObject(

packages/server/api/src/app/openops-tables/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { addUserToWorkspace } from './add-user-workspace';
2-
import { authenticateAdminUserInOpenOpsTables } from './auth-admin-tables';
32
import { createDatabase } from './create-database';
43
import { createDatabaseToken } from './create-database-token';
54
import { createMcpEndpoint } from './create-mcp-endpoint';
@@ -29,5 +28,4 @@ export const openopsTables = {
2928
getMcpEndpointList,
3029
createMcpEndpoint,
3130
getWorkspaceByName,
32-
authenticateAdminUserInOpenOpsTables,
3331
};

0 commit comments

Comments
 (0)