Skip to content

Commit fbf9357

Browse files
MarceloRGoncmaor-rozenfeld
authored andcommitted
Add fixed salt for admin password (#1739)
Part of OPS-3201
1 parent b634cdf commit fbf9357

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

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.12
5+
image: public.ecr.aws/openops/openops-tables:0.2.13
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.12
24+
OPS_OPENOPS_TABLES_VERSION: 0.2.13
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.12
50+
image: public.ecr.aws/openops/openops-tables:0.2.13
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
@@ -88,7 +88,7 @@ engine:
8888
tables:
8989
name: openops-tables
9090
image: openops-tables
91-
tag: "0.2.12"
91+
tag: "0.2.13"
9292
replicas: 1
9393
env:
9494
BASEROW_PUBLIC_URL: "{{ .Values.openopsEnv.OPS_OPENOPS_TABLES_PUBLIC_URL }}"

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
authenticateUserInOpenOpsTables,
3-
resetUserPassword,
4-
} from '@openops/common';
51
import { AppSystemProp, logger, system } from '@openops/server-shared';
62
import {
73
Organization,
@@ -95,9 +91,6 @@ async function ensureUserExists(
9591
);
9692

9793
user = await createAdminUser(email, password);
98-
const { token } = await authenticateUserInOpenOpsTables(email, password);
99-
await resetUserPassword(email, user.password, token);
100-
10194
return user;
10295
}
10396

@@ -188,13 +181,10 @@ async function upsertAdminPassword(
188181
const email = user.email;
189182
logger.info(`Updating password for admin [${email}]`, email);
190183

191-
const updatedUser = await userService.updatePassword({
184+
await userService.updateAdminPassword({
192185
id: user.id,
193186
newPassword,
194187
});
195-
196-
const { token } = await authenticateUserInOpenOpsTables(email, newPassword);
197-
await resetUserPassword(email, updatedUser.password, token);
198188
}
199189

200190
async function upsertAdminEmail(user: User, email: string): Promise<void> {
@@ -204,7 +194,7 @@ async function upsertAdminEmail(user: User, email: string): Promise<void> {
204194
}
205195

206196
function createAdminUser(email: string, password: string): Promise<User> {
207-
return userService.create({
197+
return userService.createAdminUser({
208198
email,
209199
password,
210200
organizationRole: OrganizationRole.ADMIN,

packages/server/api/src/app/user/user-service.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cacheWrapper } from '@openops/server-shared';
1+
import { AppSystemProp, cacheWrapper, system } from '@openops/server-shared';
22
import {
33
ApplicationError,
44
assertValidEmail,
@@ -17,6 +17,7 @@ import {
1717
UserStatus,
1818
UserWithOrganization,
1919
} from '@openops/shared';
20+
import bcrypt from 'bcrypt';
2021
import dayjs from 'dayjs';
2122
import { passwordHasher } from '../authentication/basic/password-hasher';
2223
import { repoFactory } from '../core/db/repo-factory';
@@ -29,17 +30,24 @@ export const userService = {
2930
async create(params: CreateParams): Promise<User> {
3031
const hashedPassword = await passwordHasher.hash(params.password);
3132

32-
const user: NewUser = {
33+
return saveUser({
3334
id: openOpsId(),
3435
...params,
3536
organizationRole: params.organizationRole,
3637
status: UserStatus.ACTIVE,
3738
password: hashedPassword,
38-
};
39-
40-
sendUserCreatedEvent(user.id, user.organizationId);
39+
});
40+
},
41+
async createAdminUser(params: CreateParams): Promise<User> {
42+
const hashedPassword = await bcrypt.hash(params.password, getStaticSalt());
4143

42-
return userRepo().save(user);
44+
return saveUser({
45+
id: openOpsId(),
46+
...params,
47+
organizationRole: params.organizationRole,
48+
status: UserStatus.ACTIVE,
49+
password: hashedPassword,
50+
});
4351
},
4452
async update({
4553
id,
@@ -209,13 +217,13 @@ export const userService = {
209217
});
210218
},
211219

212-
async updatePassword({
220+
async updateAdminPassword({
213221
id,
214222
newPassword,
215223
}: UpdatePasswordParams): Promise<User> {
216224
assertValidPassword(newPassword);
217225

218-
const hashedPassword = await passwordHasher.hash(newPassword);
226+
const hashedPassword = await bcrypt.hash(newPassword, getStaticSalt());
219227

220228
await userRepo().update(id, {
221229
updated: dayjs().toISOString(),
@@ -307,6 +315,16 @@ export const userService = {
307315
},
308316
};
309317

318+
function saveUser(user: NewUser): Promise<User> {
319+
sendUserCreatedEvent(user.id, user.organizationId);
320+
321+
return userRepo().save(user);
322+
}
323+
324+
function getStaticSalt(): string {
325+
return system.getOrThrow<string>(AppSystemProp.OPENOPS_ADMIN_PASSWORD_SALT);
326+
}
327+
310328
type DeleteParams = {
311329
id: UserId;
312330
organizationId: OrganizationId | null;

packages/server/shared/src/lib/system/system-prop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export enum AppSystemProp {
6767

6868
OPENOPS_ADMIN_EMAIL = 'OPENOPS_ADMIN_EMAIL',
6969
OPENOPS_ADMIN_PASSWORD = 'OPENOPS_ADMIN_PASSWORD',
70+
OPENOPS_ADMIN_PASSWORD_SALT = 'OPENOPS_ADMIN_PASSWORD_SALT',
7071

7172
OPENOPS_TABLES_DATABASE_NAME = 'OPENOPS_TABLES_DATABASE_NAME',
7273
OPENOPS_TABLES_PUBLIC_URL = 'OPENOPS_TABLES_PUBLIC_URL',

packages/server/shared/src/lib/system/system.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const systemPropDefaultValues: Partial<Record<SystemProp, string>> = {
108108
[AppSystemProp.TELEMETRY_MODE]: 'COLLECTOR',
109109
[AppSystemProp.TELEMETRY_COLLECTOR_URL]: 'https://telemetry.openops.com/save',
110110
[SharedSystemProp.ENABLE_HOST_VALIDATION]: 'true',
111+
[AppSystemProp.OPENOPS_ADMIN_PASSWORD_SALT]: '$2b$10$6zuoB5d8Dz9bzV91gpuynO',
111112
};
112113

113114
export const system = {

0 commit comments

Comments
 (0)