question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mysql - fallback to memory db allows admin:admin login!

See original GitHub issue

So I want to set up with mysql and docker compose, but the app server starts up too quick for the database server, causing it to revert to memory db, where username and password admin:admin work. This is a major security vulnerability.

Error during initializing SQL falling back temporally to memory DB
"Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'pigallery2'@'192.168.112.3' (using password: YES)"

If I log in with admin:admin and resubmit the database information, this is a temporary fix, but every time I restart the server, this issue persists. This error is inherant to the nature of MYSQL’s slower start up time.

A solution would be to not start the app until a connection can be made to the database, once the MYSQL database has been chosen. Additionally displaying an error message on the home screen like “cannot log in, because database has not yet been connected”.

Using docker-compose on Linux. FInd below my docker-compose.yml:

version: '3'
services:

  db:
    image: mariadb
    volumes:
      - ./db-data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=_________________
      - MYSQL_USER=pigallery2
      - MYSQL_PASSWORD=pigallery2_pass
      - MYSQL_DATABASE=pigallery2

  app:
    image: bpatrik/pigallery2:latest
    command: --Server-Database-mysql-host=db --Server-Database-mysql-username=pigallery2 --Server-Database-mysql-password=pigallery2_pass--Server-Database-mysql-database=pigallery2
    environment:
      - NODE_ENV=production
    volumes:
      - "./config:/app/data/config"
      - "./db-data:/app/data/db"
      - "/my/images:/app/data/images/"
      - "/tmp/pigallery/:/app/data/tmp" 
    ports:
      - 8008:80
    restart: always
    depends_on:
      - db

Find below my docker-compose logs:

app_1  | using config path:/app/data/config/config.json
app_1  | 6/23/2020, 6:30:38 PM[INFO] [server] running diagnostics...
app_1  | 6/23/2020, 6:30:38 PM[WARN] [ConfigDiagnostics] [SQL error] Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'pigallery2'@'192.168.112.3' (using password: YES)
app_1  | 6/23/2020, 6:30:38 PM[WARN] [ConfigDiagnostics] Error during initializing SQL falling back temporally to memory DB
app_1  | 6/23/2020, 6:30:38 PM[WARN] [ConfigDiagnostics] Faces are not supported with these settings, switching off.. Error: Memory Database do not support faces
app_1  | 6/23/2020, 6:30:38 PM[INFO] [JobManager] Running job schedules
app_1  | 6/23/2020, 6:30:38 PM[INFO] [server] Listening on port 80
app_1  | using config path:/app/data/config/config.json
app_1  | 6/23/2020, 6:31:13 PM[INFO] [SettingsMWs] new config:
app_1  | 6/23/2020, 6:31:13 PM[INFO] [SettingsMWs] {
app_1  | 	"Client": {
app_1  | 		"applicationTitle": "PiGallery 2",
app_1  | 		"appVersion": "1.8.0",
app_1  | 		"buildCommitHash": "8b5785679dd278c824e92e5017a5d74541fc108e",
app_1  | 		"buildTime": "2019-12-30T20:50:44.075Z",
app_1  | 		"upTime": "2020-06-23T18:30:38.678Z",
app_1  | 		"Media": {
app_1  | 			"Video": {
app_1  | 				"enabled": true
app_1  | 			},
app_1  | 			"Photo": {
app_1  | 				"Converting": {
db_1   | 2020-06-23 18:30:34+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.13+maria~bionic started.
db_1   | 2020-06-23 18:30:35+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1   | 2020-06-23 18:30:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.13+maria~bionic started.
db_1   | 2020-06-23 18:30:35 0 [Note] mysqld (mysqld 10.4.13-MariaDB-1:10.4.13+maria~bionic) starting as process 1 ...
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Uses event mutexes
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Number of pools: 1
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Using SSE2 crc32 instructions
db_1   | 2020-06-23 18:30:35 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2020-06-23 18:30:35 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: 10.4.13 started; log sequence number 486613; transaction id 452
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2020-06-23 18:30:36 0 [Note] Plugin 'FEEDBACK' is disabled.
db_1   | 2020-06-23 18:30:36 0 [Note] Server socket created on IP: '::'.
db_1   | 2020-06-23 18:30:36 0 [Warning] 'proxies_priv' entry '@% root@d0fc72c5040e' ignored in --skip-name-resolve mode.
db_1   | 2020-06-23 18:30:36 0 [Note] Reading of all Master_info entries succeeded
db_1   | 2020-06-23 18:30:36 0 [Note] Added new Master_info '' to hash table
db_1   | 2020-06-23 18:30:36 0 [Note] mysqld: ready for connections.
db_1   | Version: '10.4.13-MariaDB-1:10.4.13+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
db_1   | 2020-06-23 18:30:36 0 [Note] InnoDB: Buffer pool(s) load completed at 200623 18:30:36
db_1   | 2020-06-23 18:30:38 8 [Warning] Access denied for user 'pigallery2'@'192.168.112.3' (using password: YES)
db_1   | 2020-06-23 18:43:08 12 [Warning] Aborted connection 12 to db: 'pigallery2' user: 'pigallery2' host: '192.168.112.3' (Got timeout reading communication packets)
db_1   | 2020-06-23 18:43:08 11 [Warning] Aborted connection 11 to db: 'pigallery2' user: 'pigallery2' host: '192.168.112.3' (Got timeout reading communication packets)
app_1  | 					"enabled": true
app_1  | 				}
app_1  | 			},
app_1  | 			"Thumbnail": {
app_1  | 				"concurrentThumbnailGenerations": 7,
app_1  | 				"thumbnailSizes": [
app_1  | 					240,
app_1  | 					480
app_1  | 				],
app_1  | 				"iconSize": 45,
app_1  | 				"personThumbnailSize": 200
app_1  | 			}
app_1  | 		},
app_1  | 		"Search": {
app_1  | 			"enabled": false,
app_1  | 			"instantSearchEnabled": true,
app_1  | 			"InstantSearchTimeout": 3000,
app_1  | 			"searchCacheTimeout": 3600000,
app_1  | 			"instantSearchCacheTimeout": 3600000,
app_1  | 			"AutoComplete": {
app_1  | 				"enabled": true,
app_1  | 				"cacheTimeout": 3600000,
app_1  | 				"maxItemsPerCategory": 5
app_1  | 			}
app_1  | 		},
app_1  | 		"Sharing": {
app_1  | 			"enabled": false,
app_1  | 			"passwordProtected": true
app_1  | 		},
app_1  | 		"Map": {
app_1  | 			"enabled": true,
app_1  | 			"useImageMarkers": true,
app_1  | 			"mapProvider": 0,
app_1  | 			"mapboxAccessToken": "",
app_1  | 			"customLayers": [
app_1  | 				{
app_1  | 					"name": "street",
app_1  | 					"url": ""
app_1  | 				}
app_1  | 			]
app_1  | 		},
app_1  | 		"RandomPhoto": {
app_1  | 			"enabled": true
app_1  | 		},
app_1  | 		"MetaFile": {
app_1  | 			"enabled": true
app_1  | 		},
app_1  | 		"Other": {
app_1  | 			"captionFirstNaming": false,
app_1  | 			"enableCache": true,
app_1  | 			"enableOnScrollRendering": true,
app_1  | 			"enableOnScrollThumbnailPrioritising": true,
app_1  | 			"defaultPhotoSortingMethod": 3,
app_1  | 			"NavBar": {
app_1  | 				"showItemCount": true
app_1  | 			}
app_1  | 		},
app_1  | 		"Faces": {
app_1  | 			"enabled": false,
app_1  | 			"keywordsToPersons": true,
app_1  | 			"writeAccessMinRole": 4
app_1  | 		},
app_1  | 		"authenticationRequired": true,
app_1  | 		"unAuthenticatedUserRole": 4,
app_1  | 		"publicUrl": "",
app_1  | 		"urlBase": "",
app_1  | 		"languages": [
app_1  | 			"fr",
app_1  | 			"hu",
app_1  | 			"ro",
app_1  | 			"ru",
app_1  | 			"en"
app_1  | 		]
app_1  | 	},
app_1  | 	"Server": {
app_1  | 		"port": 80,
app_1  | 		"host": "0.0.0.0",
app_1  | 		"Media": {
app_1  | 			"folder": "/app/data/images",
app_1  | 			"tempFolder": "/app/data/tmp",
app_1  | 			"photoProcessingLibrary": 3,
app_1  | 			"Thumbnail": {
app_1  | 				"qualityPriority": true,
app_1  | 				"personFaceMargin": 0.6
app_1  | 			},
app_1  | 			"Photo": {
app_1  | 				"Converting": {
app_1  | 					"onTheFly": true,
app_1  | 					"resolution": 720
app_1  | 				}
app_1  | 			},
app_1  | 			"Video": {
app_1  | 				"transcoding": {
app_1  | 					"bitRate": 2621440,
app_1  | 					"codec": "libx264",
app_1  | 					"format": "mp4",
app_1  | 					"fps": 25,
app_1  | 					"resolution": 480
app_1  | 				}
app_1  | 			}
app_1  | 		},
app_1  | 		"Log": {
app_1  | 			"level": 3,
app_1  | 			"sqlLevel": 2
app_1  | 		},
app_1  | 		"sessionTimeout": 604800000,
app_1  | 		"photoMetadataSize": 524288,
app_1  | 		"Database": {
app_1  | 			"type": 2,
app_1  | 			"dbFolder": "/app/data/db",
app_1  | 			"mysql": {
app_1  | 				"host": "db",
app_1  | 				"username": "pigallery2",
app_1  | 				"password": "pigallery2_pass",
app_1  | 				"database": "pigallery2"
app_1  | 			}
app_1  | 		},
app_1  | 		"Sharing": {
app_1  | 			"updateTimeout": 300000
app_1  | 		},
app_1  | 		"Threading": {
app_1  | 			"enabled": true,
app_1  | 			"thumbnailThreads": 0
app_1  | 		},
app_1  | 		"Indexing": {
app_1  | 			"folderPreviewSize": 2,
app_1  | 			"cachedFolderTimeout": 3600000,
app_1  | 			"reIndexingSensitivity": 1,
app_1  | 			"excludeFolderList": [],
app_1  | 			"excludeFileList": []
app_1  | 		},
app_1  | 		"Duplicates": {
app_1  | 			"listingLimit": 1000
app_1  | 		},
app_1  | 		"Jobs": {
app_1  | 			"maxSavedProgress": 10,
app_1  | 			"scheduled": [
app_1  | 				{
app_1  | 					"name": "Indexing",
app_1  | 					"jobName": "Indexing",
app_1  | 					"config": {},
app_1  | 					"trigger": {
app_1  | 						"type": 1
app_1  | 					}
app_1  | 				},
app_1  | 				{
app_1  | 					"name": "Thumbnail Generation",
app_1  | 					"jobName": "Thumbnail Generation",
app_1  | 					"config": {
app_1  | 						"sizes": [
app_1  | 							240
app_1  | 						]
app_1  | 					},
app_1  | 					"trigger": {
app_1  | 						"type": 4,
app_1  | 						"afterScheduleName": "Indexing"
app_1  | 					}
app_1  | 				},
app_1  | 				{
app_1  | 					"name": "Video Converting",
app_1  | 					"jobName": "Video Converting",
app_1  | 					"config": {},
app_1  | 					"trigger": {
app_1  | 						"type": 4,
app_1  | 						"afterScheduleName": "Thumbnail Generation"
app_1  | 					}
app_1  | 				},
app_1  | 				{
app_1  | 					"name": "Temp Folder Cleaning",
app_1  | 					"jobName": "Temp Folder Cleaning",
app_1  | 					"config": {},
app_1  | 					"trigger": {
app_1  | 						"type": 4,
app_1  | 						"afterScheduleName": "Video Converting"
app_1  | 					}
app_1  | 				}
app_1  | 			]
app_1  | 		}
app_1  | 	}
app_1  | }
app_1  | 6/23/2020, 6:31:13 PM[INFO] [JobManager] Running job schedules

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
twatzlcommented, Aug 9, 2020

Hi. I think I am just running into the same issue. pigallery uses the in memory db as a fallback, so I am having issues getting it connected to the database. In my opinion this should not be the case at all. The start should just fail if there is no database available. Otherwise this is some unexpected behavior which might lead to loss of data for users when they think everything is running fine, but actually the in memory database is used.

If the server just shuts down again then restart: always should try to start the container again and once the db is available pigallery should get a connection just fine.

So my point is: This fallback should be removed alltogether as it serves no good purpose and just brings the danger of running a misconfigured instance.

0reactions
bpatrikcommented, Oct 31, 2020

Alright I have removed the fallback to memory DB entirely. (including the flag)

Read more comments on GitHub >

github_iconTop Results From Across the Web

6.3.1 Configuring MySQL to Use Encrypted Connections
On the server side, the --ssl option specifies that the server permits but does not require encrypted connections. This option is enabled by...
Read more >
How to fallback to a different value in 'WHERE' clause sql?
I believe the answer lies somewhere in using CASE WHEN clause. Also the above queries should work for oracle, postgres as well as...
Read more >
Config Cheat Sheet - Docs
Configuration Cheat Sheet. This is a cheat sheet for the Gitea configuration file. It contains most of the settings that can be configured...
Read more >
Cloud SQL for MySQL disaster recovery: A complete failover ...
Phase 1: Setting up an HA database instance for DR. The following phases (1-3) guide you through a complete failover and fallback process....
Read more >
Frequently-Seen Support Issues - iThemes Help Center
See 'Fallback to Compatibility Mode' above. Warning: mysql_query() [function.mysql-query]: Unable to save result set in /www/wp-content/plugins/backupbuddy/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found