Repository navigation
bug: drop hardcoded MySQL root credentials and unpublish DB ports (sfind-b433244b) - #1111
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
typeorm-db.js reads MYSQL_HOST/PORT/USER/PASSWORD/DATABASE from the environment and defaults to the non-root goof user with no password. docker-compose gives MySQL a random root password, creates the goof app user from MYSQL_PASSWORD (required), passes the same settings to the goof service, and no longer publishes 3306 or 27017 on the host. Fixes sfind-b433244bbb4c4f79a5bb8074745ca428
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
| database: "acme", | ||
| host: process.env.MYSQL_HOST || "localhost", | ||
| port: Number(process.env.MYSQL_PORT) || 3306, | ||
| username: process.env.MYSQL_USER || "goof", |
| host: process.env.MYSQL_HOST || "localhost", | ||
| port: Number(process.env.MYSQL_PORT) || 3306, | ||
| username: process.env.MYSQL_USER || "goof", | ||
| password: process.env.MYSQL_PASSWORD, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resumo
Corrige o finding
sfind-b433244bbb4c4f79a5bb8074745ca428(severidade média): o app se conectava ao MySQL comorootcom senha fixaroot, e odocker-compose.ymlusava a mesma senha e publicava3306(e27017do Mongo) em todas as interfaces do host. Qualquer pessoa com acesso de rede ao host conseguia entrar como root e alteraracme.users(por exemplo, promover um usuário a[REDACTED SECRET]).typeorm-db.js: a conexão agora vem do ambiente:docker-compose.yml:good-mysqlpassa a usarMYSQL_RANDOM_ROOT_PASSWORD: "yes"e cria um usuário de aplicação sem privilégios de root (MYSQL_USER, padrãogoof, comALLapenas emacme.*), usandoMYSQL_PASSWORD, que é obrigatório:${MYSQL_PASSWORD:?...}faz o compose falhar se ele não estiver definido.portsfoi removido degood-mysql(3306) e degoof-mongo(27017). Os dois bancos só ficam acessíveis pela rede do compose.goofrecebeMYSQL_HOST=goof-mysql/MYSQL_USER/MYSQL_PASSWORD/MYSQL_DATABASEe ganhalinksparagood-mysql, comdepends_on: good-mysql: condition: service_healthy. Ohealthcheckrodamysql -h 127.0.0.1 -u$MYSQL_USER ... acme, então só passa depois que o init criou o banco e o usuário. Por isso o arquivo foi paraversion: "2.1". Antes, ogooftentavalocalhostdentro do container e o seed falhava.README.md: documenta oMYSQL_PASSWORDe as variáveisMYSQL_*para rodar fora do compose..gitignore: passa a ignorar.env.Mudança de comportamento / contrato: nenhuma rota da API mudou. A mudança é operacional:
docker-compose upagora exigeMYSQL_PASSWORD, seja no ambiente ou em.env.npm startno host usando o MySQL/Mongo do compose emlocalhost:3306/27017precisa expor essas portas por conta própria (por exemplo,127.0.0.1:3306:3306em um override local) e definir as variáveisMYSQL_*.Como testar
Harness:
run.sh <checkout> <label>. Ele sobe o serviço realgood-mysqldodocker-compose.ymlde cada checkout, com a imagem trocada paramysql:5.7, que está em cache (o Docker Hub está bloqueado nesta VM), eMYSQL_PASSWORDdefinido. Depois roda otypeorm-db.jsreal e, por fim, faz o papel do atacante:mysql -h <IP externo do host> -uroot -proot.main0.0.0.0:3306,[::]:3306mysql -h 172.16.255.2 -uroot -prootroot@%,UPDATE ... role='[REDACTED SECRET]'funciona (Liran vira[REDACTED SECRET])ERROR 2003 Can't connect ... (111)root/rootdireto na rede do composeroot@%ERROR 1045 Access denied for user 'root'goofgoof@%,GRANT ALL PRIVILEGES ON acme.*typeorm-db.jsseedgoof)acme.usersno finalLiran [REDACTED SECRET],Simon [REDACTED SECRET]Liran user,Simon [REDACTED SECRET]Também validei com
MYSQL_HOST=<ip do container>:routes/users.jsmontado com a conexão real dotypeorm-db.jsrespondeuGET /users -> 200 [{"id":1,"name":"Liran",...,"role":"user"}]. Startup do zero com healthcheck: subigoof(substituído por um cliente mysql,healthcheck-override.yml) e o compose esperougoof-mysql Healthy. O MySQL ficou pronto às 21:56:24, ogoofiniciou às 21:56:29 e a primeira conexão retornougoof@% acme. Já odocker compose configsemMYSQL_PASSWORDfalha comrequired variable MYSQL_PASSWORD is missing a value.Limitações:
mongo:3enode:18.13.0não estão em cache e o Docker Hub está bloqueado, entãodocker-compose up --buildcompleto (com o containergoof) não foi executado.npm startcompleto no host também não foi validado: ele cai no seed do Mongo (mongoose-db.js:50) por causa do MongoDB local incompatível, sem relação com esta mudança.npm test(snyk test) exige autenticação no Snyk.Devin-Org: engineering
Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/e5689771fc914f30bdd73c0cc7fcdf69
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/e5689771fc914f30bdd73c0cc7fcdf69?variant=devin
Devin Review