Skip to content

Commit

Permalink
fix(docker): change default password for postgres (#1250)
Browse files Browse the repository at this point in the history
## What ❔

Use the same password for zk stack and zk init 

## Why ❔

Using 2 different auth models in postgres leads to some
unpredictability, because we have 2 differnt containers with 2 different
auth models. but the same volumes folder, as a result we constantly have
authentification error

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Feb 26, 2024
1 parent 7d53618 commit f6bff74
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions core/lib/env_config/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod tests {
fn postgres_from_env() {
let mut lock = MUTEX.lock();
let config = r#"
DATABASE_URL=postgres://postgres@localhost/zksync_local
DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local
DATABASE_POOL_SIZE=50
DATABASE_ACQUIRE_TIMEOUT_SEC=15
DATABASE_STATEMENT_TIMEOUT_SEC=300
Expand All @@ -151,7 +151,7 @@ mod tests {
let postgres_config = PostgresConfig::from_env().unwrap();
assert_eq!(
postgres_config.master_url().unwrap(),
"postgres://postgres@localhost/zksync_local"
"postgres://postgres:notsecurepassword@localhost/zksync_local"
);
assert_eq!(postgres_config.max_connections().unwrap(), 50);
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion docker-compose-cpu-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ services:
ports:
- 127.0.0.1:5432:5432
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
# We bind only to 127.0.0.1, so setting insecure password is acceptable here
- POSTGRES_PASSWORD=notsecurepassword
3 changes: 2 additions & 1 deletion docker-compose-gpu-runner-cuda-12-0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ services:
ports:
- 127.0.0.1:5432:5432
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
# We bind only to 127.0.0.1, so setting insecure password is acceptable here
- POSTGRES_PASSWORD=notsecurepassword
3 changes: 2 additions & 1 deletion docker-compose-gpu-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ services:
ports:
- 127.0.0.1:5432:5432
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
# We bind only to 127.0.0.1, so setting insecure password is acceptable here
- POSTGRES_PASSWORD=notsecurepassword
3 changes: 2 additions & 1 deletion docker-compose-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ services:
ports:
- "5433:5432"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
# We bind only to 127.0.0.1, so setting insecure password is acceptable here
- POSTGRES_PASSWORD=notsecurepassword
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ services:
source: ./volumes/postgres
target: /var/lib/postgresql/data
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
# We bind only to 127.0.0.1, so setting insecure password is acceptable here
- POSTGRES_PASSWORD=notsecurepassword

# This is specific to runner
zk:
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/advanced/01_initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ And now we're ready to start setting up the system.
First - postgres database: you'll be able to see something like

```
DATABASE_URL = postgres://postgres@localhost/zksync_local
DATABASE_URL = postgres://postgres:notsecurepassword@localhost/zksync_local
```

After which we setup the schema (lots of lines with `Applied XX`).

You can try connecting to postgres now, to see what's inside:

```shell
psql postgres://postgres@localhost/zksync_local
psql postgres://postgres:notsecurepassword@localhost/zksync_local
```

(and then commands like `\dt` to see the tables, `\d TABLE_NAME` to see the schema, and `select * from XX` to see the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------

# URL of the Postgres DB.
DATABASE_URL=postgres://postgres@localhost/zksync_local_ext_node
DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local_ext_node
# PostgreSQL connection pool size
DATABASE_POOL_SIZE=50

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------

# URL of the Postgres DB.
DATABASE_URL=postgres://postgres@localhost/zksync_local_ext_node
DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local_ext_node
# PostgreSQL connection pool size
DATABASE_POOL_SIZE=50

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------

# URL of the Postgres DB.
DATABASE_URL=postgres://postgres@localhost/zksync_local_ext_node
DATABASE_URL=postgres://postgres:notsecurepassword@localhost/zksync_local_ext_node
# PostgreSQL connection pool size
DATABASE_POOL_SIZE=50

Expand Down
8 changes: 4 additions & 4 deletions etc/env/base/private.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Sensitive values which MUST be different for production
# Values provided here are valid for the development infrastructure only.

database_url="postgres://postgres@localhost/zksync_local"
database_prover_url="postgres://postgres@localhost/prover_local"
test_database_url="postgres://postgres@localhost:5433/zksync_local_test"
test_database_prover_url="postgres://postgres@localhost:5433/prover_local_test"
database_url="postgres://postgres:notsecurepassword@localhost/zksync_local"
database_prover_url="postgres://postgres:notsecurepassword@localhost/prover_local"
test_database_url="postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test"
test_database_prover_url="postgres://postgres:notsecurepassword@localhost:5433/prover_local_test"

[eth_sender.sender]
# Set in env file for development, production, staging and testnet.
Expand Down
8 changes: 4 additions & 4 deletions etc/env/docker.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
database_url = "postgres://postgres@postgres/zksync_local"
database_prover_url = "postgres://postgres@postgres/prover_local"
test_database_url = "postgres://postgres@host:5433/zksync_local_test"
test_database_prover_url="postgres://postgres@host:5433/prover_local_test"
database_url = "postgres://postgres:notsecurepassword@postgres/zksync_local"
database_prover_url = "postgres://postgres:notsecurepassword@postgres/prover_local"
test_database_url = "postgres://postgres:notsecurepassword@host:5433/zksync_local_test"
test_database_prover_url="postgres://postgres:notsecurepassword@host:5433/prover_local_test"

# for loadtest
l1_rpc_address = "http://geth:8545"
Expand Down
6 changes: 3 additions & 3 deletions etc/env/ext-node-docker.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
database_url = "postgres://postgres@postgres/zksync_local_ext_node"
template_database_url = "postgres://postgres@postgres/zksync_local"
test_database_url = "postgres://postgres@host:5433/zksync_local_test_ext_node"
database_url = "postgres://postgres:notsecurepassword@postgres/_ext_node"
template_database_url = "postgres://postgres:notsecurepassword@postgres/zksync_local"
test_database_url = "postgres://postgres:notsecurepassword@host:5433/zksync_local_test_ext_node"

[en]
eth_client_url = "http://geth:8545"
Expand Down
6 changes: 3 additions & 3 deletions etc/env/ext-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# All the variables must be provided explicitly.
# This is on purpose: if EN will accidentally depend on the main node env, it may cause problems.

database_url = "postgres://postgres@localhost/zksync_local_ext_node"
database_url = "postgres://postgres:notsecurepassword@localhost/zksync_local_ext_node"
# Optional variable. If set, "zk db setup" will recreate "database_url" db by
# cloning "template_database_url" db instead of creating an empty db.
# "template_database_url" is not used by EN itself.
template_database_url="postgres://postgres@localhost/zksync_local"
test_database_url = "postgres://postgres@localhost:5433/zksync_local_test_ext_node"
template_database_url="postgres://postgres:notsecurepassword@localhost/zksync_local"
test_database_url = "postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test_ext_node"
database_pool_size = 50
zksync_action="dont_ask"

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function generateMigration(dbType: DbType, name: string) {

export async function setupForDal(dalPath: DalPath, dbUrl: string) {
process.chdir(dalPath);
const localDbUrl = 'postgres://postgres@localhost';
const localDbUrl = 'postgres://postgres:notsecurepassword@localhost';
if (dbUrl.startsWith(localDbUrl)) {
console.log(`Using localhost database -- ${dbUrl}`);
} else {
Expand Down
1 change: 0 additions & 1 deletion infrastructure/zk/src/hyperchain_wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async function initHyperchain() {
const governorPrivateKey = process.env.GOVERNOR_PRIVATE_KEY;
const deployL2Weth = Boolean(process.env.DEPLOY_L2_WETH || false);
const deployTestTokens = Boolean(process.env.DEPLOY_TEST_TOKENS || false);

const governorAdrress = ethers.utils.computeAddress(governorPrivateKey!);
const initArgs: InitArgs = {
skipSubmodulesCheckout: false,
Expand Down

0 comments on commit f6bff74

Please sign in to comment.